Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Definition acquire_spec := DECLARE _acquire acquire_spec.
Definition release_spec := DECLARE _release release_spec.
Definition makelock_spec := DECLARE _makelock (makelock_spec _).
Definition freelock_spec := DECLARE _freelock (freelock_spec _).
Definition spawn_spec := DECLARE _spawn spawn_spec.
Definition freelock2_spec := DECLARE _freelock2 (freelock2_spec _).
Definition release2_spec := DECLARE _release2 release2_spec.
Definition cptr_lock_inv ctr := EX z : Z, data_at Ews tuint (Vint (Int.repr z)) ctr.
Definition incr_spec :=
DECLARE _incr
WITH gv : globals, sh : share
PRE [ ]
PROP  (readable_share sh)
LOCAL (gvars gv)
SEP   (lock_inv sh (gv _ctr_lock) (cptr_lock_inv (gv _ctr)))
POST [ tvoid ]
PROP ()
LOCAL ()
SEP (lock_inv sh (gv _ctr_lock) (cptr_lock_inv (gv _ctr))).
Definition read_spec :=
DECLARE _read
WITH gv : globals, sh : share
PRE [ ]
PROP  (readable_share sh)
LOCAL (gvars gv)
SEP   (lock_inv sh (gv _ctr_lock) (cptr_lock_inv (gv _ctr)))
POST [ tuint ]
EX z : Z,
PROP ()
LOCAL (temp ret_temp (Vint (Int.repr z)))
SEP (lock_inv sh (gv _ctr_lock) (cptr_lock_inv (gv _ctr))).
Definition thread_lock_R sh ctr lockc :=
lock_inv sh lockc (cptr_lock_inv ctr).
Definition thread_lock_inv sh ctr lockc lockt :=
selflock (thread_lock_R sh ctr lockc) sh lockt.
Definition thread_func_spec :=
DECLARE _thread_func
WITH y : val, x : share * globals
PRE [ _args OF (tptr tvoid) ]
let '(sh, gv) := x in
PROP  (readable_share sh)
LOCAL (temp _args y; gvars gv)
SEP   (lock_inv sh (gv _ctr_lock) (cptr_lock_inv (gv _ctr));
lock_inv sh (gv _thread_lock) (thread_lock_inv sh (gv _ctr) (gv _ctr_lock) (gv _thread_lock)))
POST [ tptr tvoid ]
PROP ()
LOCAL ()
SEP ().
Definition main_spec :=
DECLARE _main
WITH gv : globals
PRE  [] main_pre prog tt nil gv
POST [ tint ] main_post prog nil gv.
Definition Gprog : funspecs :=   ltac:(with_library prog [acquire_spec; release_spec; release2_spec; makelock_spec;
freelock_spec; freelock2_spec; spawn_spec; incr_spec; read_spec; thread_func_spec; main_spec]).
Hint Resolve ctr_inv_exclusive.

Lemma thread_inv_exclusive : forall sh ctr lock lockt,
exclusive_mpred (thread_lock_inv sh ctr lock lockt).