Definition zero_of_type (t: type) : val :=
match t with
| Tfloat _ _ => Vfloat Float.zero
| _ => Vint Int.zero
end.
Definition eval_sgvar (id: ident) (ty: type) (rho: environ) :=
match Map.get (ge_of rho) id with
| Some b => Vptr b Ptrofs.zero
| None => Vundef
end.
(* Lemma eval_sgvar_lemma1: forall (F: val -> mpred) ofs id t, F Vundef |-- FF -> `F (`(offset_val ofs) (eval_sgvar id t)) = (EX v:val, local (locald_denote (sgvar id v)) && `(F (offset_val ofs v))). *)
Definition init_data2pred' {cs: compspecs}
(Delta: tycontext) (gv: globals) (d: init_data)  (sh: share) (v: val) : mpred :=
match d with
| Init_int8 i => mapsto sh tuchar v (Vint (Int.zero_ext 8 i))
| Init_int16 i => mapsto sh tushort v (Vint (Int.zero_ext 16 i))
| Init_int32 i => mapsto sh tuint v (Vint i)
| Init_int64 i => mapsto sh tulong v (Vlong i)
| Init_float32 r =>  mapsto sh tfloat v (Vsingle r)
| Init_float64 r =>  mapsto sh tdouble v (Vfloat r)
| Init_space n =>  memory_block sh n v
| Init_addrof symb ofs =>
match (var_types Delta) ! symb, (glob_types Delta) ! symb with
| None, Some (Tarray t n' att) =>
mapsto sh (Tpointer t noattr) v (offset_val (Ptrofs.unsigned ofs) (gv symb))
| None, Some t => mapsto sh (Tpointer t noattr) v (offset_val (Ptrofs.unsigned ofs) (gv symb))
| Some _, Some _ => mapsto_ sh (Tpointer Tvoid noattr) v
| _, _ => TT
end
end.

(* Specifications: *)
Lemma unsigned_repr_le: forall i, 0 <= i -> Int.unsigned (Int.repr i) <= i.
Lemma mapsto_aligned:
forall t ch, access_mode t = By_value ch ->
forall  sh b z p,
mapsto sh t (Vptr b z) p
|-- !! (Memdata.align_chunk ch | Ptrofs.unsigned z).
Lemma sizeof_Tpointer {cs: compspecs} : forall t,
sizeof (Tpointer t noattr) = if Archi.ptr64 then 8 else 4.
Lemma init_data_size_space {cs: compspecs}:
forall t, init_data_size (Init_space (sizeof t)) = sizeof t.
Lemma init_data2pred_rejigger {cs: compspecs}:
forall (Delta : tycontext)  (idata : init_data) (rho : environ)
(sh : Share.t) (b : block) ofs v,
tc_environ Delta rho ->
v = Vptr b (Ptrofs.repr 0) ->
readable_share sh ->
init_data2pred idata sh (offset_val ofs v) rho
|-- init_data2pred' Delta (globals_of_env rho) idata sh (offset_val ofs v).
Lemma readable_readonly2share: forall ro, readable_share (readonly2share ro).
Lemma unpack_globvar  {cs: compspecs}:
forall Delta gz i t gv idata,
(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 = true)%bool ->
gvar_volatile gv = false ->
gvar_info gv = t ->
gvar_init gv = idata :: nil ->
init_data_size idata <= sizeof t ->
sizeof t <= Ptrofs.max_unsigned ->
local (`and (tc_environ Delta) (fun rho =>gz = globals_of_env rho)) && globvar2pred gz (i, gv) |--
`(init_data2pred' Delta gz idata (readonly2share (gvar_readonly gv)) (gz i)).