let frama_c_memset state actuals =
  if Value_parameters.ValShowProgress.get () then
    Value_parameters.feedback "Call to builtin memset(%a)%t"
      pretty_actuals actuals Value_util.pp_callstack;
  try
    match actuals with
    | [(exp_dst, dst, _); (_exp_v, v, _); (exp_size, size, _)] ->
        let with_alarms = warn_all_quiet_mode () in
        let size_min, size_max =
          try
            let size = Cvalue.V.project_ival size in
            let min,max = Ival.min_and_max size in
            let min = match min with
              | None -> Int.zero
              | Some m -> Int.mul Int.eight (Int.max m Int.zero)
            and max = match max with
              | None -> Bit_utils.max_bit_address ()
              | Some m -> Int.mul Int.eight m
            in min, max
          with V.Not_based_on_null -> Int.zero, Bit_utils.max_bit_address ()
        in
        let term_size = Logic_utils.expr_to_term ~cast:true exp_size in
        let array_dst = Logic_utils.array_with_range exp_dst term_size in
        CilE.set_syntactic_context (CilE.SyMemLogic array_dst);
        let left = loc_bytes_to_loc_bits dst
        and offsm_repeat =
          V_Offsetmap.create_initial
            ~v:(V_Or_Uninitialized.initialized v)
            ~modu:Int.eight
        in
        (* Write "maybe bytes" *)
        let new_state =
          Cvalue.Model.paste_offsetmap with_alarms
            offsm_repeat left Int.zero size_max false state
        in
        (* Write "sure" bytes: they exist only if there is only one base,
           and within it, size_min+leftmost_loc > rightmost_loc *)

        let new_state' =
          try
            let base, offset = Location_Bits.find_lonely_key left in
            let minb, maxb = Ival.min_and_max offset in
            let maxb = Extlib.the maxb and minb = Extlib.the minb in
            let sure = Int.sub (Int.add minb size_min) maxb in
            if Int.gt sure Int.zero then
              let left' = Location_Bits.inject base
                (Ival.inject_singleton maxb)
              in
              Cvalue.Model.paste_offsetmap with_alarms
                offsm_repeat left' Int.zero sure true new_state
            else
              new_state
          with Not_found -> new_state
        in
        wrap_ptr dst, new_state', Location_Bits.Top_Param.bottom
    | _ ->
        raise Db.Value.Outside_builtin_possibilities
  with Lmap.Cannot_copy -> raise Db.Value.Outside_builtin_possibilities