Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Local Open Scope assert.
Parameter mem_mgr: globals -> mpred.
Parameter malloc_token': share -> Z -> val -> mpred.
Parameter malloc_token'_valid_pointer: forall sh sz p, malloc_token' sh sz p |-- valid_pointer p.
Definition malloc_token {cs: compspecs} sh t v :=
!! field_compatible t [] v &&
malloc_token' sh (sizeof t) v.
Hint Resolve malloc_token'_local_facts : saturate_local.
Hint Resolve malloc_token_local_facts : saturate_local.
Definition malloc_spec' :=
DECLARE _malloc
WITH n:Z, gv: globals
PRE [ 1%positive OF size_t ]
PROP (0 <= n <= Ptrofs.max_unsigned)
LOCAL (temp 1%positive (Vptrofs (Ptrofs.repr n)); gvars gv)
SEP (mem_mgr gv)
POST [ tptr tvoid ] EX p:_,
PROP ()
LOCAL (temp ret_temp p)
SEP (mem_mgr gv;
if eq_dec p nullval then emp
else (malloc_token' Ews n p * memory_block Ews n p)).
Definition free_spec' :=
DECLARE _free
WITH n:Z, p:val, gv: globals
PRE [ 1%positive OF tptr tvoid ]
PROP ()
LOCAL (temp 1%positive p; gvars gv)
SEP (mem_mgr gv;
if eq_dec p nullval then emp
else (malloc_token' Ews n p * memory_block Ews n p))
POST [ Tvoid ]
PROP ()
LOCAL ()
SEP (mem_mgr gv).
Definition exit_spec :=
DECLARE _exit
WITH u: unit
PRE [1%positive OF tint]
PROP () LOCAL() SEP()
POST [ tvoid ]
PROP(False) LOCAL() SEP().
Definition placeholder_spec :=
DECLARE _placeholder
WITH u: unit
PRE [ ]
PROP (False) LOCAL() SEP()
POST [ tint ]
PROP() LOCAL() SEP().
Definition ispecs := [placeholder_spec].
Definition specs := [malloc_spec'; free_spec'; exit_spec].
Definition malloc_spec  {cs: compspecs} (t: type) :=
DECLARE _malloc
WITH gv: globals
PRE [ 1%positive OF size_t ]
PROP (0 <= sizeof t <= Ptrofs.max_unsigned;
complete_legal_cosu_type t = true;
natural_aligned natural_alignment t = true)
LOCAL (temp 1%positive (Vptrofs (Ptrofs.repr (sizeof t))); gvars gv)
SEP (mem_mgr gv)
POST [ tptr tvoid ] EX p:_,
PROP ()
LOCAL (temp ret_temp p)
SEP (mem_mgr gv;
if eq_dec p nullval then emp
else (malloc_token Ews t p * data_at_ Ews t p)).
Definition free_spec  {cs: compspecs} (t: type) :=
DECLARE _free
WITH p: val, gv: globals
PRE [ 1%positive OF tptr tvoid ]
PROP ()
LOCAL (temp 1%positive p; gvars gv)
SEP (mem_mgr gv;
if eq_dec p nullval then emp
else (malloc_token Ews t p * data_at_ Ews t p))
POST [ Tvoid ]
PROP ()
LOCAL ()
SEP (mem_mgr gv).

Lemma free_spec_sub:
forall {cs: compspecs} (t: type),
funspec_sub (snd free_spec') (snd (free_spec t)).