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 *)
(* Thread states *)
(* angel, lock permissions and new thread permissions *)
(* Thread states *)
(* angel,lock permissions and new thread permissions *)
(** *Compiled diagrams*)
(*TODO: 1. Find a better name 2. Simplify / Clean it? *)

(* Large diagram: Diagram of steps over external calls. Called "Large" because in a thread-local view, it steps all interactions in one step. *)
Lemma large_external_diagram:
forall cd f mu j'' code1 code2 cge age args1 rel_trace m1 m1'''
args2 rel_trace2 FUN
m2 m2' m2'' m2''' lev1 lev1' lev2 lev2' s1'
p Hlt dpm1 dpm2 name signature
(Hfun: FUN = AST.EF_external name signature)
(Hun_dsnt_ret: doesnt_return FUN)
(Hun_dsnt_ret_sig: AST.sig_res signature = None)
(Hinj_delts: Events.inject_delta_map mu dpm1 dpm2)
(Heqrel_trace1 : rel_trace = Events.Event_acq_rel lev1 dpm1 lev1' :: nil)
(Heqrel_trace : rel_trace2 = Events.Event_acq_rel lev2 dpm2 lev2' :: nil)
(HAge: age =  (Genv.globalenv Asm_program))
(HCge: cge = (Clight.globalenv C_program) )
(Hext_rel1 : Events.external_call
FUN (Clight.genv_genv cge)
args1 m1 rel_trace Vundef m1''')
(Hext_rel2 : Events.external_call
FUN age
args2 m2 rel_trace2 Vundef m2''')
(Hnb_eq : Mem.nextblock m2'' = Mem.nextblock m2')
(Hstrict_evolution : strict_injection_evolution f mu lev1 lev2)
(Hstrict_evolution' : strict_injection_evolution mu j'' lev1' lev2')
(Hafter_ext : Clight.after_external None code1 m1''' = Some s1')
(Hmatch_states : compiler_match cd f code1 m1 code2 m2)
(Hat_external1 : Clight.at_external (Clight.set_mem code1 m1) =
Some (FUN, args1))
(Hat_external2 : Asm.at_external Asm_g (Asm.set_mem code2 m2) =
Some (FUN, args2))
(Hinterference2' : mem_interference (@restrPermMap p m2'' Hlt) lev2' m2''')
(Hconsecutive : consecutive_until (Mem.nextblock m2) lev2 (Mem.nextblock m2'))
(Hconsecutive' : consecutive_until (Mem.nextblock m2'') lev2' (Mem.nextblock m2''')),
exists (cd' : compiler_index) (j''' : meminj) (s2' : Asm.state),
Asm.after_external Asm_g None code2 m2''' = Some s2' /\
inject_incr mu j''' /\ compiler_match cd' j''' s1' m1''' s2' m2'''.