(** ** Proofs of internal step safety and simulation*)

Lemma tsim_fstep_safe:
forall tpc tpc' tpf mc mc' mf i fi fg tr
(pfc: containsThread tpc i) (pff: containsThread tpf i)
(Hcompc: mem_compatible tpc mc)
(Hcompf: mem_compatible tpf mf)
(HmaxF: max_inv mf)
(HinvF: invariant tpf)
(Hge_wd: ge_wd fg the_ge)
(Hfg: forall b1 b2, fg b1 = Some b2 -> b1 = b2)
(Hren_incr: ren_incr fg fi)
(Hstrong_sim: strong_tsim fi pfc pff Hcompc Hcompf)
(Hmem_wd: valid_mem mc)
(Hstep_internal: internal_step pfc Hcompc tpc' mc'),
exists tpf' mf' fi' tr',
(forall U, fmachine_step (i :: U, tr, tpf) mf (U, tr', tpf') mf') /\
max_inv mf' /\
ren_incr fi fi' /\
ren_separated fi fi' mc mf /\
(forall (pfc': containsThread tpc' i) (pff': containsThread tpf' i)
(Hcompc': mem_compatible tpc' mc') (Hcompf': mem_compatible tpf' mf'),
strong_tsim fi' pfc' pff' Hcompc' Hcompf' /\
(forall b2, (~exists b1, fi' b1 = Some b2) ->
forall ofs, (getThreadR pff').1 # b2 ofs = (getThreadR pff).1 # b2 ofs /\
(getThreadR pff').2 # b2 ofs = (getThreadR pff).2 # b2 ofs)) /\
(forall j (pffj : containsThread tpf j),
i <> j ->
forall (b1 b2 : block),
fi' b1 = Some b2 ->
fi b1 = None ->
forall ofs, (getThreadR pffj).1 # b2 ofs = None /\ (getThreadR pffj).2 # b2 ofs = None) /\
(forall (bl : block) (ofsl : Z)
rmap
(b1 b2 : block) (ofs : Z),
fi' b1 = Some b2 ->
fi b1 = None ->
lockRes tpf (bl, ofsl) = Some rmap -> rmap.1 # b2 ofs = None /\ rmap.2 # b2 ofs = None).