Ltac forget_contains12:=
match goal with
| [ H: context[@contains12 _ _ _ _ _ _ ?CM ?i ?cnt1] |- _ ] =>
let HH:= fresh "HH" in
let Hcnt:= fresh "Hcnt" in
remember (@contains12 _ _ _ _ _ _ CM i cnt1) as Hcnt eqn:HH; clear HH
| [ |- context[@contains12 _ _ _ _ _ _ ?CM ?i ?cnt1] ] =>
let HH:= fresh "HH" in
let Hcnt:= fresh "Hcnt" in
remember (@contains12 _ _ _ _ _ _ CM i cnt1) as Hcnt eqn:HH; clear HH
end.
Ltac forget_contains21:=
match goal with
| [ H: context[@contains21 _ _ _ _ _ _ ?CM ?i ?cnt1] |- _ ] =>
let HH:= fresh "HH" in
let Hcnt:= fresh "Hcnt" in
remember (@contains21 _ _ _ _ _ _ CM i cnt1) as Hcnt eqn:HH; clear HH
| [ |- context[@contains21 _ _ _ _ _ _ ?CM ?i ?cnt1] ] =>
let HH:= fresh "HH" in
let Hcnt:= fresh "Hcnt" in
remember (@contains21 _ _ _ _ _ _ CM i cnt1) as Hcnt eqn:HH; clear HH
end.
Ltac consolidate_containsThread:=
repeat match goal with
| [ H: ThreadPool.containsThread _ _ |- _ ] => simpl in H
end;
repeat match goal with
| [ H1: containsThread ?st ?i,
H2: containsThread ?st ?i |- _ ] =>
replace H2 with H1 in * by ( apply Axioms.proof_irr); clear H2
end.
Ltac clean_cnt:=
try forget_contains12;
try forget_contains21;
consolidate_containsThread.
Ltac clean_cnt':=
match goal with
| [ CMatch: concur_match _ _ ?st1 _ ?st2 _ |- _] =>
match goal with
| [ Hcnt1: containsThread st1 ?i,
Hcnt2: containsThread st2 ?i |- _ ] =>
(*Check if contains12 or contains21 is already used. *)
first [match goal with
| [ HH: context[contains21] |- _ ] =>  idtac
| [  |- context[contains21] ] =>  idtac
| _ => fail 1
end;
repeat(
match goal with
| [   |- context[Hcnt1] ] =>
replace Hcnt1 with (contains21 CMatch Hcnt2)
by apply Axioms.proof_irr
| [ HH:context[Hcnt1]  |- _ ] =>
replace Hcnt1 with (contains21 CMatch Hcnt2) in HH
by apply Axioms.proof_irr
end) |
repeat(
match goal with
| [   |- context[Hcnt2] ] =>
replace Hcnt2 with (contains12 CMatch Hcnt1)
by apply Axioms.proof_irr
| [ HH:context[Hcnt2]  |- _ ] =>
replace Hcnt2 with (contains12 CMatch Hcnt1) in HH
by apply Axioms.proof_irr
end) ]
end
end.

Lemma concur_match_same_running:
forall (m : option mem) (cd : option compiler_index) (mu : meminj)
(c1 : ThreadPool (Some hb)) (m1 : mem) (c2 : ThreadPool (Some (S hb)))
(m2 : mem),
concur_match cd mu c1 m1 c2 m2 ->
forall i : nat,
machine_semantics.running_thread (HybConcSem (Some hb) m) c1 i <->
machine_semantics.running_thread (HybConcSem (Some (S hb)) m) c2 i.