Definition inttype2init_data (sz: intsize) : (int -> init_data) :=
match sz with
| IBool  =>  Init_int8
| I8  =>  Init_int8
| I16 =>  Init_int16
| I32 =>  Init_int32
end.
Definition notboolsize (sz: intsize) : Prop :=
match sz with IBool => False | _ => True end.

(* Specifications: *)
Lemma id2pred_star_ZnthV_Tint  {cs: compspecs} :
forall Delta gz sh n (v: val) (data: list int) sz sign mdata
(NBS: notboolsize sz),
n = Zlength mdata ->
mdata = map (inttype2init_data sz) data ->
!! isptr v && !! align_compatible (Tint sz sign noattr) v &&
!! (offset_strict_in_range (sizeof (Tint sz sign noattr) * n)) v &&
id2pred_star Delta gz sh v mdata |--
`(data_at sh (tarray (Tint sz sign noattr) n)
(map (Basics.compose Vint (Cop.cast_int_int sz sign)) data) v).
Lemma id2pred_star_ZnthV_tint  {cs: compspecs}:
forall Delta gz sh n (v: val) (data: list int) mdata,
n = Zlength mdata ->
mdata = map Init_int32 data ->
!! isptr v && !! align_compatible tint v &&
!! offset_strict_in_range (sizeof tint * n) v &&
id2pred_star Delta gz sh v mdata |--
`(data_at sh (tarray tint n) (map Vint data) v).
Lemma offset_zero_globals_of_env: forall rho i,
offset_val 0 (globals_of_env rho i) = globals_of_env rho i.
Lemma unpack_globvar_array  {cs: compspecs}:
forall t sz sign (data: list int)  n Delta gz i gv,
(var_types Delta) ! i = None ->
(glob_types Delta) ! i = Some (gvar_info gv) ->
gvar_info gv = tarray t n ->
gvar_volatile gv = false ->
globvar_all_aligned gv = true ->
t = Tint sz sign noattr ->
forall    (NBS: notboolsize sz),
n = Zlength (gvar_init gv) ->
gvar_init gv = map (inttype2init_data sz) data ->
init_data_list_size (gvar_init gv) <= sizeof (gvar_info gv) <= Ptrofs.max_unsigned ->
local (`and (tc_environ Delta) (fun rho =>gz = globals_of_env rho)) && globvar2pred gz(i, gv) |--
`(data_at (readonly2share (gvar_readonly gv))
(tarray (Tint sz sign noattr) n)
(map (Basics.compose Vint (Cop.cast_int_int sz sign)) data)
(gz i)).
Lemma process_globvar':
forall {cs: compspecs} {Espec: OracleKind} Delta P Q R (i: ident)
gz gv gvs SF c Post (idata : init_data) t,
(var_types Delta) ! i = None ->
(glob_types Delta) ! i = Some t ->
(complete_legal_cosu_type (gvar_info gv) && is_aligned cenv_cs ha_env_cs la_env_cs (gvar_info gv) 0)%bool = true ->
gvar_volatile gv = false ->
gvar_info gv = t ->
gvar_init gv = (idata::nil) ->
init_data_size idata <= sizeof t ->
sizeof t <= Ptrofs.max_unsigned ->
semax Delta (PROPx P (LOCALx (gvars gz::Q) (SEPx R))
* id2pred_star Delta gz
(readonly2share (gvar_readonly gv))
(gz i) (idata ::nil) * globvars2pred gz gvs * SF)
c Post ->
semax Delta (PROPx P (LOCALx (gvars gz::Q) (SEPx R))
* globvars2pred gz ((i,gv)::gvs) * SF)
c Post.
Lemma process_globvar_array:
forall {cs: compspecs} {Espec: OracleKind} Delta gz P Q R (i: ident)
gv gvs SF c Post (n: Z) (t: type)  (sz : intsize) (sign : signedness) (data : list int),
(var_types Delta) ! i = None ->
(glob_types Delta) ! i = Some (gvar_info gv) ->
gvar_info gv = tarray t n ->
gvar_volatile gv = false ->
globvar_all_aligned gv = true ->
t = Tint sz sign noattr ->
notboolsize sz ->
n = Zlength (gvar_init gv) ->
gvar_init gv = map (inttype2init_data sz) data ->
init_data_list_size (gvar_init gv) <= sizeof (gvar_info gv) <=
Ptrofs.max_unsigned ->
semax Delta (PROPx P (LOCALx (gvars gz :: Q)
(SEPx ((data_at
(readonly2share (gvar_readonly gv))
(tarray (Tint sz sign noattr) n)
(map (Vint oo Cop.cast_int_int sz sign) data) (gz i))
:: R)))
* globvars2pred gz gvs * SF)
c Post ->
semax Delta (PROPx P (LOCALx (gvars gz :: Q) (SEPx R))
* globvars2pred gz ((i,gv)::gvs) * SF)
c Post.
Lemma process_globvar_star':
forall {cs: compspecs} {Espec: OracleKind} Delta gz P Q R (i: ident)
gv gvs SF c Post,
(var_types Delta) ! i = None ->
(glob_types Delta) ! i = Some (gvar_info gv) ->
(complete_legal_cosu_type (gvar_info gv) && is_aligned cenv_cs ha_env_cs la_env_cs (gvar_info gv) 0)%bool = true ->
gvar_volatile gv = false ->
globvar_all_aligned gv = true ->
init_data_list_size (gvar_init gv) <= sizeof (gvar_info gv) <=
Ptrofs.max_unsigned ->
semax Delta (PROPx P (LOCALx (gvars gz :: Q)
(SEPx R))
* (id2pred_star Delta gz (readonly2share (gvar_readonly gv))
(gz i) (gvar_init gv))
* globvars2pred gz gvs * SF)
c Post ->
semax Delta (PROPx P (LOCALx (gvars gz :: Q) (SEPx R))
* globvars2pred gz ((i,gv)::gvs) * SF)
c Post.