Section SyncCallsDiagrams.
Context (hb: nat).
(*Instantiate definitions in Concur with the current hybridbound*)
Notation concur_match:= (concur_match hb).
Notation match_thread:= (match_thread hb).
Notation match_thread_source:= (match_thread_source hb).
Notation match_thread_target:= (match_thread_target hb).
Notation memcompat2:= (memcompat2 hb).
Notation memcompat1:= (memcompat1 hb).
Notation contains12:= (contains12 hb).
Notation mtch_target:= (mtch_target hb).
Notation mtch_compiled:= (mtch_compiled hb).
Notation mtch_source:= (mtch_source hb).
Notation thread_perms st i cnt:= (fst (@getThreadR _ _ st i cnt)).
Notation lock_perms st i cnt:= (snd (@getThreadR  _ _ st i cnt)).
(* Thread states *)
(* angel,lock permissions and new thread permissions *)
(*Hangel_bound: sub_map_virtue angel (getMaxPerm m1)*)
(* Thread states *)
(* angel, lock permissions and new thread permissions *)
(* Thread states *)
(* The following two things are not needed *)
(* angel, lock permissions and new thread permissions *)

Lemma free_step_diagram_self Sem:
let CoreSem:= sem_coresem Sem in
forall (SelfSim: (self_simulation (@semC Sem) CoreSem))
(st1 : mach_state hb) (st2 : mach_state (S hb))
(m1 m2 : mem) (mu : meminj) tid i b1 b2 ofs delt
lock_data pdata
(Hinj_b : mu b1 = Some (b2, delt))
cnt1 cnt2 (* Threads are contained *)
(CMatch: concur_match i mu st1 m1 st2 m2)
(th_state1: @semC Sem) th_state2 sum_state1 sum_state2
(HState1: coerce_state_type _ sum_state1 th_state1
(CSem, Clight.state) (AsmSem,Asm.state) (Sem,@semC Sem))
(HState2: coerce_state_type _ sum_state2 th_state2
(CSem, Clight.state) (AsmSem,Asm.state) (Sem,@semC Sem))
(Hget_th_state1: @getThreadC _ _ tid st1 cnt1 = Kblocked sum_state1)
(Hget_th_state2: @getThreadC _ _ tid st2 cnt2 = Kblocked sum_state2)
(Hnone_beyond : bounded_nat_func' pdata LKSIZE_nat)
(Hthread_mem1: access_map_equiv (thread_perms tid st1 cnt1) (getCurPerm m1))
(Hthread_mem2: access_map_equiv (thread_perms tid st2 cnt2) (getCurPerm m2))
(Hlock_map: lockRes st1 (b1, Integers.Ptrofs.unsigned ofs) = Some lock_data)
(Hempty_lock: forall b ofs, pair1 (fun map => map !! b ofs) lock_data = pair0 None)
(HlocksLt: permMapLt (lock_perms _ _ cnt1) (getMaxPerm m1) )
(Hrange_perm: perm_interval (restrPermMap HlocksLt)
b1 (unsigned ofs) LKSIZE Cur Writable)
(HH: forall i, 0 <= (Z.of_nat i) < LKSIZE ->
Mem.perm_order'' (pdata (S i)) (Some Writable))
(Amatch : match_self (code_inject _ _ SelfSim) mu th_state1 m1 th_state2 m2)
(Hat_external: semantics.at_external CoreSem th_state1 m1 =
Some (FREE_LOCK, (Vptr b1 ofs :: nil)%list)),
let ofs2:=  unsigned ofs + delt in
let new_perms2:=
setPermBlock_var_pair b2 ofs2 LKSIZE_nat
(pdata, fun _:nat => None) (getThreadR cnt2) in
let evnt1:= Events.freelock (b1, unsigned ofs) in
exists event2 (m2' : mem),
let Hcmpt2:= memcompat2 CMatch in
let st2':= remLockfFullUpdate st2 tid cnt2 (Kresume sum_state2 Vundef)
new_perms2 (b2, unsigned ofs + delt) in
match_self (code_inject _ _ SelfSim) mu th_state1 m1 th_state2 m2 /\
inject_sync_event mu evnt1 event2 /\
syncStep(Sem:=HybridSem (Some (S hb))) true cnt2 Hcmpt2 st2' m2' event2.