intros r1 r2[r J]; inversion J; subst; simpl.
- if_tac.
+ subst.
if_tac.
* eauto with *.
* apply join_to_bot_l in RJ; subst;
congruence.
+ if_tac; constructor.
- destruct k; try solve [constructor].
+ apply po_join_sub_sh.
eexists; eauto.
+ apply po_join_sub_sh.
* eexists; eauto.
+ apply po_join_sub_sh.
* eexists; eauto.
- destruct k.
+ if_tac.
* hnf. destruct (perm_of_sh _); apply I.
* apply perm_order''_trans with (perm_of_sh sh3).
-- apply po_join_sub_sh.
++ eexists; eauto.
-- destruct  (perm_of_sh sh3) eqn:E.
++ constructor.
++ pose proof @perm_of_empty_inv _ E; subst.
apply join_to_bot_l in RJ; subst; congruence.
+ if_tac.
* hnf. destruct (perm_of_sh _); apply I.
* apply perm_order''_trans with (perm_of_sh sh1).
-- apply po_join_sub_sh.
++ eexists; eauto.
-- destruct  (perm_of_sh sh1) eqn:E.
++ constructor.
++ pose proof @perm_of_empty_inv _ E; subst; congruence.
+ if_tac.
* hnf. destruct (perm_of_sh _); apply I.
* apply perm_order''_trans with (perm_of_sh sh1).
-- apply po_join_sub_sh.
++ eexists; eauto.
-- destruct  (perm_of_sh sh1) eqn:E.
++ constructor.
++ pose proof @perm_of_empty_inv _ E; subst; congruence.
- destruct k; try constructor.
+ apply po_join_sub_sh; eexists; eauto.
+ apply po_join_sub_sh; eexists; eauto.
+ apply po_join_sub_sh; eexists; eauto.
- constructor.
Qed.

(* Specifications: *)
Lemma mem_access_coh_sub: forall phi1 phi2 m,
max_access_cohere m phi1 ->
join_sub phi2 phi1 ->
max_access_cohere m phi2.
Lemma mem_cohere_sub: forall phi1 phi2 m,
mem_cohere' m phi1 ->
join_sub phi2 phi1 ->
mem_cohere' m phi2.
Lemma compatible_threadRes_sub:
forall js i (cnt:containsThread js i),
forall all_juice,
join_all js all_juice ->
join_sub (getThreadR cnt) all_juice.
Lemma mem_compat_thread_max_cohere {tp m} (compat: mem_compatible tp m):
forall {i} cnti,
max_access_cohere m (@getThreadR _ _ _ i tp cnti).
Lemma thread_mem_compatible: forall tp m,
mem_compatible tp m ->
mem_thcohere tp m.
Lemma compatible_lockRes_sub: forall js l phi,
lockRes js l = Some (Some phi) ->
forall all_juice,
join_all js all_juice ->
join_sub phi all_juice.
Lemma lock_mem_compatible: forall tp m,
mem_compatible tp m ->
mem_lock_cohere (lockGuts tp) m.