Require Import VST.veric.juicy_base.
Require Import VST.veric.shares.
Require Import VST.veric.juicy_mem VST.veric.juicy_mem_lemmas VST.veric.juicy_mem_ops.
Require Import VST.veric.res_predicates.
Require Import VST.veric.extend_tc.
Require Import VST.veric.Clight_seplog.
Require Import VST.veric.Clight_assert_lemmas.
Require Import VST.veric.Clight_new.
Require Import VST.veric.tycontext.
Require Import VST.veric.expr2.
Require Import VST.veric.expr_lemmas.
Require Import VST.veric.Clight_lemmas.
Require Import VST.veric.Clight_initial_world.

Definition only_blocks {S: block -> Prop} (S_dec: forall b, {S b}+{~S b}) (w: rmap) : rmap.
 refine (proj1_sig (make_rmap (fun loc => if S_dec (fst loc) then w @ loc else core (w @ loc))
                              _ (level w) _ (ghost_of_approx w))).
Proof.
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) *)
  hnf; auto.
(* Goal: @eq resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 extensionality loc;  unfold compose.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) *)
 if_tac; try apply resource_at_approx.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w')) (approx (@level rmap ag_rmap w')) (resource_at (@core rmap Join_rmap Sep_rmap w') loc)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 repeat  rewrite core_resource_at. rewrite <- level_core.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w2)) (approx (@level rmap ag_rmap w2)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
apply resource_at_approx.
Defined.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Definition not_dec: forall {S: block -> Prop} (f: forall b, {S b}+{~S b}),
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
                            forall b, {~S b}+{~ ~ S b}.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. intros. destruct (f b). right; intuition. left; auto.
Qed.

Lemma join_only_blocks:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall {S} S_dec phi, identity (ghost_of phi) -> join (@only_blocks S S_dec phi)
                        (only_blocks (not_dec S_dec) phi) phi.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. intros.
(* Goal: @join rmap Join_rmap (@only_blocks S S_dec phi) (@only_blocks (fun b : block => not (S b)) (@not_dec S S_dec) phi) phi *)
  unfold only_blocks.
(* Goal: @join rmap Join_rmap w1' w2' w' *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  apply resource_at_join2.
(* Goal: @eq nat (@level rmap ag_rmap (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (@level rmap ag_rmap phi) *)
(* Goal: forall loc : AV.address, @join resource Join_resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  repeat rewrite level_make_rmap. auto.
(* Goal: @eq nat (@level rmap ag_rmap (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (@level rmap ag_rmap phi) *)
(* Goal: forall loc : AV.address, @join resource Join_resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  repeat rewrite level_make_rmap. auto.
(* Goal: @eq resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 intro;   repeat rewrite resource_at_make_rmap. unfold compose.
(* Goal: @join resource Join_resource (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
 destruct (S_dec (fst loc)); simpl.
(* Goal: @join resource Join_resource (resource_at phi loc) (if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (resource_at phi loc) *)
(* Goal: @join resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)) (if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  try rewrite if_false by intuition. apply join_comm; apply core_unit.
(* Goal: @join resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)) (if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  rewrite if_true by intuition; apply core_unit.
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  rewrite !ghost_of_make_rmap.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply identity_unit'; auto.
Qed.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Lemma Exists_dec: forall {T} (f: T -> Prop)(f_dec: forall x, {f x}+{~f x}) (l: list T),
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
                   {Exists f l}+{~Exists f l}.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  Proof. intros. induction l; simpl. right; intro. inv H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
         destruct IHl. left; constructor 2; auto. destruct (f_dec a). left; constructor 1; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
        right; intro Hx; inv Hx; auto.
  Qed.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Lemma only_blocks_at: forall {S} S_dec phi loc,
   @only_blocks S S_dec phi @ loc =
    if S_dec (fst loc) then phi @ loc else core (phi @ loc).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   unfold only_blocks; intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite resource_at_make_rmap. auto.
Qed.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Lemma level_only_blocks: forall {S} S_dec phi,
   level (@only_blocks S S_dec phi) = level phi.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. intros. apply level_make_rmap.
Qed.

Definition upto_block (b: block) (w: rmap) : rmap :=  only_blocks (fun b' => plt b' b) w.

Definition beyond_block (b: block) (w: rmap) : rmap := only_blocks (not_dec (fun b' => plt b' b)) w.


Lemma join_upto_beyond_block:
  forall b phi, identity (ghost_of phi) -> join  (upto_block b phi)  (beyond_block b phi) phi.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof.  intros; apply join_only_blocks; auto.
Qed.


Lemma split_range:
  forall phi base n,
    (forall loc, adr_range base n loc ->
       match phi @ loc with YES _ _ k _ => isVAL k | _ => True end) ->
    noghost phi ->
   exists phi1, exists phi2,
      join phi1 phi2 phi /\
      forall loc, if adr_range_dec base n loc then identity (phi2 @ loc)
                                                      else identity (phi1 @ loc).
Proof.
(* Goal: forall (phi : rmap) (base : address) (n : Z) (_ : forall (loc : address) (_ : adr_range base n loc), match resource_at phi loc with | NO sh n0 => True | YES sh r k p => isVAL k | PURE k p => True end) (_ : @app_pred rmap ag_rmap noghost phi), @ex rmap (fun phi1 : rmap => @ex rmap (fun phi2 : rmap => and (@join rmap Join_rmap phi1 phi2 phi) (forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc)))) *)
  intros ???? Hg.
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
  pose proof I.
(* Goal: @ex rmap (fun phi1 : rmap => @ex rmap (fun phi2 : rmap => and (@join rmap Join_rmap phi1 phi2 phi) (forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc)))) *)
  destruct (make_rmap (fun loc => if adr_range_dec base n loc then phi @ loc else core (phi @ loc)) (ghost_of phi) (level phi)) as [phi1 [J1 J2]].
(* Goal: @eq resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
  extensionality loc;   unfold compose.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w2)) (approx (@level rmap ag_rmap w2)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
  if_tac.  apply resource_at_approx.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc))) (@core resource Join_resource Sep_resource (resource_at phi loc)) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (resource_at phi loc)) (resource_at phi loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (ghost_of phi)) (ghost_of phi) *)
(* Goal: @ex rmap (fun phi1 : rmap => @ex rmap (fun phi2 : rmap => and (@join rmap Join_rmap phi1 phi2 phi) (forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc)))) *)
  repeat rewrite core_resource_at. rewrite <- level_core. apply resource_at_approx.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  { apply ghost_of_approx. }
(* Goal: and (@list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl))) (and (@list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) (@list_disjoint ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl')))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
  clear H0.
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
  pose proof I.
(* Goal: @ex rmap (fun phi1 : rmap => @ex rmap (fun phi2 : rmap => and (@join rmap Join_rmap phi1 phi2 phi) (forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc)))) *)
 destruct (make_rmap (fun loc => if adr_range_dec base n loc then core (phi @ loc) else phi @ loc) (ghost_of phi) (level phi)) as [phi2 [J3 J4]].
(* Goal: @eq resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
  extensionality loc;   unfold compose.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
  if_tac.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc))) (@core resource Join_resource Sep_resource (resource_at phi loc)) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (resource_at phi loc)) (resource_at phi loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (ghost_of phi)) (ghost_of phi) *)
(* Goal: @ex rmap (fun phi1 : rmap => @ex rmap (fun phi2 : rmap => and (@join rmap Join_rmap phi1 phi2 phi) (forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc)))) *)
  repeat rewrite core_resource_at. rewrite <- level_core. apply resource_at_approx.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w2)) (approx (@level rmap ag_rmap w2)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
  apply resource_at_approx.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  { apply ghost_of_approx. }
(* Goal: and (@list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl))) (and (@list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) (@list_disjoint ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl')))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
 clear H0.
(* Goal: @ex rmap (fun phi1 : rmap => @ex rmap (fun phi2 : rmap => and (@join rmap Join_rmap phi1 phi2 phi) (forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc)))) *)
  destruct J2 as [J2 Hg1], J4 as [J4 Hg2].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  exists phi1; exists phi2; split; auto.
(* Goal: @join rmap Join_rmap phi1 phi2 phi *)
(* Goal: forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc) *)
  apply resource_at_join2; [congruence | congruence | | ].
(* Goal: forall loc : AV.address, @join resource Join_resource (resource_at phi1 loc) (resource_at phi2 loc) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of phi1) (ghost_of phi2) (ghost_of phi) *)
(* Goal: forall loc : address, if adr_range_dec base n loc then @identity resource Join_resource (resource_at phi2 loc) else @identity resource Join_resource (resource_at phi1 loc) *)
  intros; rewrite J2; rewrite J4.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
  if_tac.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply join_unit2. apply core_unit. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply join_unit1. apply core_unit. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite Hg1, Hg2; apply identity_unit'; auto.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros. rewrite J2; rewrite J4. if_tac; apply core_identity.
Qed.

Definition blockslice_rmap (S: block -> Prop) (phi: rmap) :=
    forall loc: address, ~S (fst loc) -> identity (phi @ loc).

Definition eq_mod_blockslice (S: block -> Prop) (phi phi': rmap) :=
 forall loc, (S (fst loc) -> phi @ loc = phi' @ loc) .

Definition blockslice_mpred (S: block -> Prop) (P: mpred) :=
  (forall phi, P phi -> forall loc, ~S (fst loc) -> identity (phi @ loc)) /\
  (forall phi phi', blockslice_rmap S phi -> blockslice_rmap S phi' ->
                        eq_mod_blockslice S phi phi' ->
         P phi -> P phi').

Definition blockslice_mpred_rmap:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall S (Sdec: forall b, {S b}+{~S b}) P phi,
   blockslice_mpred S P -> P phi -> blockslice_rmap S phi.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold blockslice_mpred, blockslice_rmap; intros.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 destruct H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 eapply H; eauto.
Qed.


(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Lemma rev_prog_vars': forall {F V} vl, rev (@prog_vars' F V vl) = prog_vars' (rev vl).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   induction vl. simpl; auto.
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
   destruct a. destruct g.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
   simpl. rewrite IHvl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   clear. induction (rev vl); simpl; intros; auto. destruct a; destruct g; simpl; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    rewrite IHl. auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
   simpl.
(* Goal: @eq (list (prod ident (globvar V))) (@app (prod ident (globvar V)) (@rev (prod ident (globvar V)) (@prog_vars' F V vl)) (@cons (prod ident (globvar V)) (@pair ident (globvar V) i v) (@nil (prod ident (globvar V))))) (@prog_vars' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) (@nil (prod ident (globdef F V)))))) *)
   transitivity (prog_vars' (rev vl) ++ (@prog_vars' F V ((i,Gvar v)::nil))).
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V vl)) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) (@nil (prod ident (globdef F V)))))) *)
    rewrite IHvl. f_equal.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
    simpl.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
    clear.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    induction (rev vl); simpl; intros; auto.
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
    destruct a. destruct g.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    auto.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@cons (prod ident F) (@pair ident F i0 f0) (@prog_funct' F V l)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@cons (prod ident F) (@pair ident F i0 f0) (@prog_funct' F V (@app (prod ident (globdef F V)) l (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V))))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V l) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@prog_funct' F V (@app (prod ident (globdef F V)) l (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
    rewrite <- IHl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    simpl. auto.
Qed.

Definition init_data2pred (d: init_data)  (sh: share) (a: val) (rho: environ) : mpred :=
 match d with
  | Init_int8 i => mapsto sh (Tint I8 Unsigned noattr) a (Vint (Int.zero_ext 8 i))
  | Init_int16 i => mapsto sh (Tint I16 Unsigned noattr) a (Vint (Int.zero_ext 16 i))
  | Init_int32 i => mapsto sh (Tint I32 Unsigned noattr) a (Vint i)
  | Init_int64 i => mapsto sh (Tlong Unsigned noattr) a (Vlong i)
  | Init_float32 r =>  mapsto sh (Tfloat F32 noattr) a (Vsingle r)
  | Init_float64 r =>  mapsto sh (Tfloat F64 noattr) a (Vfloat r)
  | Init_space n => mapsto_zeros n sh a
  | Init_addrof symb ofs =>
       match Map.get (ge_of rho) symb with
       | Some b => mapsto sh (Tpointer Tvoid noattr) a (Vptr b ofs)
       | _ => mapsto_ sh (Tpointer Tvoid noattr) a
       end
 end.

Fixpoint init_data_list2pred  (dl: list init_data)
                           (sh: share) (v: val)  : environ -> pred rmap :=
  match dl with
  | d::dl' => 
      lift2 sepcon (init_data2pred d sh v) 
                  (init_data_list2pred dl' sh (offset_val (init_data_size d) v))
  | nil => lift0 emp
 end.

Definition readonly2share (rdonly: bool) : share :=
  if rdonly then Ers else Ews.

Definition globals_of_env (rho: environ) (i: ident) : val := 
  match Map.get (ge_of rho) i with Some b => Vptr b Ptrofs.zero | None => Vundef end.

Definition globvar2pred (gv: ident->val) (idv: ident * globvar type) : assert :=
   if (gvar_volatile (snd idv))
                       then  lift0 TT
                       else    init_data_list2pred (gvar_init (snd idv))
                                   (readonly2share (gvar_readonly (snd idv))) (gv (fst idv)).


Definition globvars2pred (gv: ident->val) (vl: list (ident * globvar type)) : assert :=
  (lift2 andp) (fun rho => prop (gv = globals_of_env rho))
  (fold_right (lift2 sepcon) (lift0 emp) (map (globvar2pred gv) vl)).

Lemma globvars2pred_rev:
  forall gv l, globvars2pred gv (rev l) = globvars2pred gv l.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros. unfold globvars2pred.
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) (@rev (prod ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
 rewrite map_rev.
(* Goal: @eq assert (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@andp rmap ag_rmap) (fun rho : environ => @prop rmap ag_rmap (@eq (forall _ : ident, val) gv (globals_of_env rho))) (@fold_right (forall _ : environ, @pred rmap ag_rmap) (forall _ : environ, @pred rmap ag_rmap) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap)) (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap)) (@rev assert (@map (prod ident (globvar type)) assert (globvar2pred gv) l)))) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@andp rmap ag_rmap) (fun rho : environ => @prop rmap ag_rmap (@eq (forall _ : ident, val) gv (globals_of_env rho))) (@fold_right (forall _ : environ, @pred rmap ag_rmap) (forall _ : environ, @pred rmap ag_rmap) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap)) (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap)) (@map (prod ident (globvar type)) assert (globvar2pred gv) l))) *)
  rewrite fold_left_rev_right.
(* Goal: @eq assert (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@andp rmap ag_rmap) (fun rho : environ => @prop rmap ag_rmap (@eq (forall _ : ident, val) gv (globals_of_env rho))) (@fold_left (forall _ : environ, @pred rmap ag_rmap) assert (fun (x : forall _ : environ, @pred rmap ag_rmap) (y : assert) => @lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) y x) (@map (prod ident (globvar type)) assert (globvar2pred gv) l) (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap)))) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@andp rmap ag_rmap) (fun rho : environ => @prop rmap ag_rmap (@eq (forall _ : ident, val) gv (globals_of_env rho))) (@fold_right (forall _ : environ, @pred rmap ag_rmap) (forall _ : environ, @pred rmap ag_rmap) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap)) (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap)) (@map (prod ident (globvar type)) assert (globvar2pred gv) l))) *)
 rewrite fold_symmetric.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
 f_equal.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
 f_equal. extensionality x y rho; apply sepcon_comm.
(* Goal: forall x y z : assert, @eq assert (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) z y) x) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) z (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) y x)) *)
(* Goal: forall y : assert, @eq assert (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) y (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap))) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap)) y) *)
 intros; extensionality rho; apply sepcon_assoc.
(* Goal: forall y : assert, @eq assert (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) y (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap))) (@lift2 (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap) (@lift0 (@pred rmap ag_rmap) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap)) y) *)
 intros; extensionality rho; apply sepcon_comm.
Qed.

Lemma writable_blocks_rev:
  forall rho l, writable_blocks l rho = writable_blocks (rev l) rho.
Proof.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
induction l; simpl; auto.
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
destruct a.
(* Goal: @eq mpred (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap (writable_block i z rho) (writable_blocks l rho)) (writable_blocks (@app (prod ident Z) (@rev (prod ident Z) l) (@cons (prod ident Z) (@pair ident Z i z) (@nil (prod ident Z)))) rho) *)
rewrite writable_blocks_app.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@cons (prod ident F) (@pair ident F i0 f0) (@prog_funct' F V l)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@cons (prod ident F) (@pair ident F i0 f0) (@prog_funct' F V (@app (prod ident (globdef F V)) l (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V))))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V l) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@prog_funct' F V (@app (prod ident (globdef F V)) l (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
rewrite <- IHl.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl.
(* Goal: @eq mpred (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap (writable_block i z rho) (writable_blocks l rho)) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap (writable_blocks l rho) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap (writable_block i z rho) (@emp rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap))) *)
rewrite sepcon_emp.
(* Goal: @eq mpred (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap (writable_block i z rho) (writable_blocks l rho)) (@sepcon rmap Join_rmap Perm_rmap ag_rmap Age_rmap (writable_blocks l rho) (writable_block i z rho)) *)
apply sepcon_comm.
Qed.

Lemma add_variables_nextblock:
  forall F V vl (ge: Genv.t F V) i g ul, list_norepet (map (@fst _ _) (vl++(i,g)::ul)) ->
   Genv.find_symbol (Genv.add_globals ge (vl++(i,g)::ul)) i =
          Some (Genv.advance_next vl (Genv.genv_next ge)).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 induction vl; intros.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 inv H. clear H3. simpl.
 change positive with block.
 replace (Some (Genv.genv_next ge)) with (Genv.find_symbol (Genv.add_global ge (i,g)) i).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 2:{
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  unfold Genv.add_global, Genv.find_symbol; simpl. rewrite PTree.gss. f_equal; unfold block; omega.
  }
  forget (Genv.add_global ge (i, g)) as ge1.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert H2 ge1; induction ul; simpl; intros; auto.
  spec IHul; [intuition |].
  rewrite IHul.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  unfold Genv.find_symbol, Genv.add_global. simpl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite PTree.gso; auto.
  simpl length. simpl Genv.advance_next.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl.
  rewrite (IHvl  (Genv.add_global ge a) i g ul).
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
  f_equal.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H. inv H; auto.
Qed.

Definition load_store_init_data1 (ge: Genv.t fundef type) (m: mem) (b: block) (p: Z) (d: init_data) : Prop :=
  match d with
  | Init_int8 n =>
      Mem.load Mint8unsigned m b p = Some(Vint(Int.zero_ext 8 n))
  | Init_int16 n =>
      Mem.load Mint16unsigned m b p = Some(Vint(Int.zero_ext 16 n))
  | Init_int32 n =>
      Mem.load Mint32 m b p = Some(Vint n)
  | Init_int64 n =>
      Mem.load Mint64 m b p = Some(Vlong n)
  | Init_float32 n =>
      Mem.load Mfloat32 m b p = Some(Vsingle n)
  | Init_float64 n =>
      Mem.load Mfloat64 m b p = Some(Vfloat n)
  | Init_addrof symb ofs =>
      Mem.load Mptr m b p = Some
             match Genv.find_symbol ge symb with
                | Some b' => Vptr b' ofs
                | None => Vint Int.zero
              end
  | Init_space n =>
      forall z, 0 <= z < Z.max n 0 ->
           Mem.load Mint8unsigned m b (p+z) = Some (Vint Int.zero)
  end.

Definition initializer_aligned (z: Z) (d: init_data) : bool :=
  match d with
  | Init_int16 n => Zeq_bool (z mod 2) 0
  | Init_int32 n => Zeq_bool (z mod 4) 0
  | Init_int64 n => Zeq_bool (z mod 8) 0
  | Init_float32 n =>  Zeq_bool (z mod 4) 0
  | Init_float64 n =>  Zeq_bool (z mod 8) 0
  | Init_addrof symb ofs =>  Zeq_bool (z mod (size_chunk Mptr)) 0
  | _ => true
  end.

Fixpoint initializers_aligned (z: Z) (dl: list init_data) : bool :=
  match dl with
  | nil => true
  | d::dl' => andb (initializer_aligned z d) (initializers_aligned (z + init_data_size d) dl')
  end.

Lemma init_data_list_size_pos: forall dl, init_data_list_size dl >= 0.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. induction dl; simpl; intros. omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 pose proof (init_data_size_pos a); omega.
Qed.

Require Import FunInd.

Remark store_zeros_load_outside:
  forall m b p n m',
  store_zeros m b p n = Some m' ->
  forall chunk b' p',
  b' <> b \/ p' + size_chunk chunk <= p \/ p + n <= p' ->
  Mem.load chunk m' b' p' = Mem.load chunk m b' p'.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros until n.  functional induction (store_zeros m b p n); intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  inv H; auto.
(* Goal: @eq (option val) (load chunk m'0 b' p') (load chunk m b' p') *)
(* Goal: @eq (option val) (load chunk m' b' p') (load chunk m b' p') *)
  transitivity (Mem.load chunk m' b' p').
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply IHo. auto. intuition omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  eapply Mem.load_store_other; eauto. simpl. intuition omega.
(* Goal: @eq (option val) (load chunk m' b' p') (load chunk m b' p') *)
  discriminate.
Qed.

Lemma load_store_zeros:
  forall m b z N m', store_zeros m b z N = Some m' ->
         forall z', z <= z' < z + N -> load Mint8unsigned m' b z' = Some (Vint Int.zero).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
 symmetry in H; apply R_store_zeros_correct in H.
  remember (Some m') as m1.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert z'  m' Heqm1 H0; induction H; intros. omegaContradiction.
  subst _res.
 destruct (Z.eq_dec z' p).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 2:{ apply IHR_store_zeros; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
   clear - H0 n0.  destruct H0. omega.
  }
  subst z'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (load_store_similar _ _ _ _ _ _ e0) with Mint8unsigned; simpl; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  omega.
  destruct H1.
(* Goal: not (@In ident i (@map (prod ident A) ident (@fst ident A) (@prog_funct' A B vl))) *)
(* Goal: @list_norepet ident (@map (prod ident A) ident (@fst ident A) (@prog_funct' A B vl)) *)
 simpl in H2. subst x.
  replace (Int.zero_ext 8 Int.zero) with (Int.zero) in H1 by reflexivity.
  rewrite <- H1.
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
  clear - H. apply R_store_zeros_complete in H.
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
 symmetry.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 symmetry in H; symmetry; eapply store_zeros_load_outside; eauto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 right. simpl; omega.
  inv Heqm1.
Qed.

Lemma read_as_zero_lem1:
 forall m b z len,
  (forall i, z <= i < z+len ->
     load Mint8unsigned m b i = Some (Vint Int.zero)) ->
  Genv.read_as_zero m b z len.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros; hnf; intros.
transitivity
  (Some (decode_val chunk (list_repeat (size_chunk_nat chunk) (Byte Byte.zero)))).
2: destruct chunk; reflexivity.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
apply loadbytes_load; auto.
clear H2.
rewrite size_chunk_conv in *.
(* pose proof (loadbytes_load Mint8unsigned m b). *)
forget (size_chunk_nat chunk) as n.
assert (forall i, p <= i < p + (Z.of_nat n) ->
                     loadbytes m b i 1 = Some (Byte Byte.zero::nil)).
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
specialize (H i).
spec H; [ omega |].
apply load_loadbytes in H.
destruct H as [j [? ?]].
destruct j; inv H3;
 try solve [apply loadbytes_length in H;inv H].
destruct j; inv H5;
 try solve [apply loadbytes_length in H;inv H].
destruct m0; try solve [inv H4].
rewrite (decode_byte_val i0) in H4.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
simpl in H.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
rewrite H. repeat f_equal.
clear - H4.
rewrite zero_ext_inrange in H4.
assert (Int.unsigned Int.zero = Int.unsigned (Int.repr (Byte.unsigned i0))) by congruence.
rewrite Int.unsigned_zero in H.
rewrite Int.unsigned_repr in H.
assert (Byte.repr 0 = Byte.repr (Byte.unsigned i0)) by congruence.
rewrite Byte.repr_unsigned in H0.
rewrite <- H0. reflexivity.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
clear.
pose proof (Byte.unsigned_range i0).
destruct H;
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 split; auto.
apply Z.le_trans with Byte.modulus.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
omega.
compute; congruence.
rewrite Int.unsigned_repr.
pose proof (Byte.unsigned_range i0).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
change (two_p 8) with Byte.modulus; omega.
pose proof (Byte.unsigned_range i0).
assert (Byte.modulus < Int.max_unsigned) by (compute; congruence).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
omega.
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
clear - H2.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
revert p H2; induction n; intros.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
apply loadbytes_empty. omega.
rewrite inj_S. unfold Z.succ.
rewrite Z.add_comm.
change (list_repeat (S n) (Byte Byte.zero)) with
 (list_repeat 1 (Byte Byte.zero) ++ list_repeat n (Byte Byte.zero)).
apply loadbytes_concat.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
apply H2. rewrite inj_S; omega.
apply IHn.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
apply H2.  rewrite inj_S; omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
omega. omega.
Qed.

Remark store_init_data_outside:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall {F V} genv b i m p m',
  @Genv.store_init_data F V genv m b p i = Some m' ->
  forall chunk b' q,
  b' <> b \/ q + size_chunk chunk <= p \/ p + init_data_size i <= q ->
  Mem.load chunk m' b' q = Mem.load chunk m b' q.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros. destruct i; simpl in *;
  try (eapply Mem.load_store_other; eauto; fail).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  inv H; auto.
(* Goal: @eq (option val) (load chunk m' b' q) (load chunk m b' q) *)
  destruct (Genv.find_symbol genv i); try congruence.
(* Goal: @eq (option val) (load chunk m' b' q) (load chunk m b' q) *)
  eapply Mem.load_store_other; eauto; intuition.
Qed.

Remark store_init_data_list_outside:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall {F V} genv b il m p m',
  @Genv.store_init_data_list F V genv m b p il = Some m' ->
  forall chunk b' q,
  b' <> b \/ q + size_chunk chunk <= p ->
  Mem.load chunk m' b' q = Mem.load chunk m b' q.
Proof.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  induction il; simpl.
(* Goal: forall (m : mem) (p : Z) (m' : mem) (_ : @eq (option mem) (@Some mem m) (@Some mem m')) (chunk : memory_chunk) (b' : block) (q : Z) (_ : or (not (@eq block b' b)) (Z.le (Z.add q (size_chunk chunk)) p)), @eq (option val) (load chunk m' b' q) (load chunk m b' q) *)
(* Goal: forall (m : mem) (p : Z) (m' : mem) (_ : @eq (option mem) match @Genv.store_init_data F V genv m b p a with | Some m'0 => @Genv.store_init_data_list F V genv m'0 b (Z.add p (init_data_size a)) il | None => @None mem end (@Some mem m')) (chunk : memory_chunk) (b' : block) (q : Z) (_ : or (not (@eq block b' b)) (Z.le (Z.add q (size_chunk chunk)) p)), @eq (option val) (load chunk m' b' q) (load chunk m b' q) *)
  intros; congruence.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros. destruct (Genv.store_init_data genv m b p a) as [m1|] eqn:?; try congruence.
(* Goal: @eq (option val) (load chunk m' b' q) (load chunk m b' q) *)
  transitivity (Mem.load chunk m1 b' q).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  eapply IHil; eauto. generalize (init_data_size_pos a). intuition omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  eapply store_init_data_outside; eauto. tauto.
Qed.

Lemma load_store_init_data_lem1:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall {ge m1 b D m2 m3},
   store_zeros m1 b 0 (init_data_list_size D) = Some m2 ->
   Genv.store_init_data_list ge m2 b 0 D = Some m3 ->
   forall dl' a dl, dl' ++ a :: dl = D ->
   load_store_init_data1 ge m3 b (init_data_list_size dl') a.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
  pose proof (Genv.store_init_data_list_charact _ _ H0).
  subst D.
  change (init_data_list_size dl') with (0 + init_data_list_size dl').
  forget 0 as z.
  assert (forall z', z <= z' < z + init_data_list_size (dl' ++ a :: dl) ->
               Mem.load Mint8unsigned m2 b z' = Some (Vint Int.zero))
    by (eapply load_store_zeros; eauto).
  clear H m1.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert z m2 H0 H1 H2; induction dl'; intros.
  simpl app in *. simpl init_data_list_size in *.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  replace (z+0) with z by omega.
  simpl in H0.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
  invSome.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  spec H2. {
(* Goal: and (iff (@identity resource Join_resource (resource_at w2 loc)) (@identity resource Join_resource (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc))) (forall _ : not (@identity resource Join_resource (resource_at w2 loc)), @eq resource (resource_at w2 loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc)) *)
    clear - H1.
    apply read_as_zero_lem1; intros; apply H1.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
    omega.
  }
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct a; simpl in H2|-*; try solve [destruct H2; auto]; intros.
  rewrite (store_init_data_list_outside _ _ _ _ _ _ H4) by (right; simpl; omega).
  simpl in H0. inv H0. apply H1.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl.
  pose proof (init_data_list_size_pos dl).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  omega.
  destruct H2 as [[b' [? ?]] ?].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite H. auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl.
  simpl in H0. invSome.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite Zplus_assoc. apply IHdl' with m; auto.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
  rewrite <- (H1 z').
  destruct (store_init_data_list_outside' _ _ ge b (a0::nil) m2 z m).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl. rewrite H0; auto.
  destruct (H3 b z').
  destruct H6. simpl in H7. omegaContradiction.
  destruct H5. clear - H6 H5; unfold access_at,contents_at in *.
  Transparent load. unfold load. Opaque load.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
  simpl in *. rewrite H6.
  destruct (valid_access_dec m Mint8unsigned b z' Readable);
   destruct (valid_access_dec m2 Mint8unsigned b z' Readable);
  unfold valid_access in *; try congruence.
  contradiction n. clear - v H5.
  unfold range_perm, perm in *.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct v; split; auto; intros.
  apply (equal_f ) with (b,ofs) in H5. apply equal_f with Cur in H5. simpl in H5.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite H5; auto.
  contradiction n. clear - v H5.
  unfold range_perm, perm in *.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct v; split; auto; intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply (equal_f ) with (b,ofs) in H5.  apply equal_f with Cur in H5. simpl in H5. rewrite <- H5; auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl.
  pose proof (init_data_size_pos a0).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  omega.
  simpl app in H2.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  spec H2. {
(* Goal: and (iff (@identity resource Join_resource (resource_at w2 loc)) (@identity resource Join_resource (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc))) (forall _ : not (@identity resource Join_resource (resource_at w2 loc)), @eq resource (resource_at w2 loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc)) *)
     clear - H1.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
     apply read_as_zero_lem1; intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
     apply H1. simpl; auto.
  }
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  clear - H2.
  forget (dl'++a::dl) as D.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. destruct a0; simpl in *; try solve [destruct H2; auto]; intros.
Qed.

(*
Lemma read_sh_readonly:
  forall NU, read_sh = mk_lifted (readonly2share true) NU.
Proof.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl. unfold read_sh. simpl. f_equal; auto with extensionality.
Qed.  
*)

Lemma zero_ext_inj: forall i,
   Int.zero_ext 8 (Int.repr (Byte.unsigned i)) = Int.zero ->
   i = Byte.zero.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @eq Byte.int i Byte.zero *)
assert (MU: 256 < Int.max_unsigned).
(* Goal: @eq Z Int.max_unsigned (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
 unfold Int.max_unsigned, Int.modulus, Int.wordsize, Wordsize_32.wordsize in *.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
  unfold two_power_nat, shift_nat in *; simpl in *.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 replace (Zpos (4294967296 - 1)) with (4294967295). omega. reflexivity.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
rewrite Int.zero_ext_and in H by omega.
(*
 by (unfold Int.wordsize, Wordsize_32.wordsize; split; simpl in *; omega). *)
(* Goal: @eq Byte.int i Byte.zero *)
pose proof (Int.modu_and (Int.repr (Byte.unsigned i)) (Int.repr (two_p 8)) (Int.repr 8)).
(* Goal: False *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 spec H0.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 apply Int.is_power2_two_p; simpl.  unfold Int.zwordsize; simpl. omega.
(* Goal: @eq Byte.int i Byte.zero *)
 replace (Int.sub (Int.repr (two_p 8)) Int.one) with (Int.repr (two_p 8 - 1)) in H0.
(* Goal: and (@list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl))) (and (@list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) (@list_disjoint ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl')))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
 rewrite <- H0 in H. clear H0.
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 rewrite Int.modu_divu in H.
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 replace (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p 8))) with Int.zero in H.
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: @eq Int.int Int.zero (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p (Zpos (xO (xO (xO xH))))))) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 rewrite Int.sub_zero_l in H.
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: @eq Int.int Int.zero (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p (Zpos (xO (xO (xO xH))))))) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 pose proof (Int.unsigned_repr (Byte.unsigned i)).
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: @eq Int.int Int.zero (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p (Zpos (xO (xO (xO xH))))))) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 assert (Int.unsigned (Int.repr (Byte.unsigned i)) = Int.unsigned Int.zero).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite H; auto.
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: @eq Int.int Int.zero (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p (Zpos (xO (xO (xO xH))))))) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 rewrite H0 in H1.
(* Goal: @eq Byte.int i Byte.zero *)
(* Goal: and (Z.le Z0 (Byte.unsigned i)) (Z.le (Byte.unsigned i) Int.max_unsigned) *)
(* Goal: @eq Int.int Int.zero (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p (Zpos (xO (xO (xO xH))))))) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 clear - MU H1. rewrite Int.unsigned_zero in H1.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite <- (Byte.repr_unsigned i). unfold Byte.zero. f_equal. auto.
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 clear - MU. pose proof (Byte.unsigned_range i).
(* Goal: and (Z.le Z0 (Byte.unsigned i)) (Z.le (Byte.unsigned i) Int.max_unsigned) *)
(* Goal: @eq Int.int Int.zero (Int.divu (Int.repr (Byte.unsigned i)) (Int.repr (two_p (Zpos (xO (xO (xO xH))))))) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 unfold Byte.modulus, Byte.wordsize, Wordsize_8.wordsize in *.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  unfold two_power_nat, shift_nat in *; simpl in *. omega.
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 clear - MU.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
 unfold Int.divu. unfold Int.zero. f_equal.
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
 symmetry. apply Zdiv_small.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 split.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct (Int.unsigned_range (Int.repr (Byte.unsigned i))); auto.
 repeat rewrite Int.unsigned_repr.
(* Goal: and (Z.le Z0 (Byte.unsigned i)) (Z.le (Byte.unsigned i) Int.max_unsigned) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 destruct (Byte.unsigned_range i).
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 apply H0. simpl.  unfold two_power_pos, shift_pos; simpl. omega.
(* Goal: and (Z.le Z0 (Byte.unsigned i)) (Z.le (Byte.unsigned i) Int.max_unsigned) *)
(* Goal: not (@eq Int.int (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 destruct (Byte.unsigned_range i).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 split; auto. replace Byte.modulus with 256 in H0 by reflexivity. omega.
(* Goal: @eq Z (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
 clear - MU. replace (two_p 8) with 256 by reflexivity.
(* Goal: not (@eq Int.int (Int.repr (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH)))))))))) Int.zero) *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 unfold Int.zero. intro.
(* Goal: False *)
(* Goal: @eq Int.int (Int.repr (Z.sub (two_p (Zpos (xO (xO (xO xH))))) (Zpos xH))) (Int.sub (Int.repr (two_p (Zpos (xO (xO (xO xH)))))) Int.one) *)
 pose proof (Int.unsigned_repr 256).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 spec H0. split; omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite H in H0. rewrite Int.unsigned_repr in H0 by omega. inv H0.
(* Goal: @eq Z (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
 replace (two_p 8) with 256 by reflexivity.
(* Goal: @eq Int.int (Int.repr (Z.sub (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH))))))))) (Zpos xH))) (Int.sub (Int.repr (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH)))))))))) Int.one) *)
 unfold Int.one.
(* Goal: @eq Int.int (Int.repr (Z.sub (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH))))))))) (Zpos xH))) (Int.sub (Int.repr (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH)))))))))) (Int.repr (Zpos xH))) *)
 rewrite Int.sub_signed.
(* Goal: @eq Int.int (Int.repr (Z.sub (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH))))))))) (Zpos xH))) (Int.repr (Z.sub (Int.signed (Int.repr (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH))))))))))) (Int.signed (Int.repr (Zpos xH))))) *)
 pose proof (Int.min_signed_neg).
(* Goal: @eq Int.int (Int.repr (Z.sub (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH))))))))) (Zpos xH))) (Int.repr (Z.sub (Int.signed (Int.repr (Zpos (xO (xO (xO (xO (xO (xO (xO (xO xH))))))))))) (Int.signed (Int.repr (Zpos xH))))) *)
 assert (Int.max_signed = 2147483647).
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 clear.  unfold Int.max_signed, Int.half_modulus, Int.modulus, Int.wordsize, two_power_nat; simpl.
(* Goal: @eq Z (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
 reflexivity.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  repeat rewrite Int.signed_repr; auto;  split; try omega.
Qed.

Lemma max_unsigned_eq: Int.max_unsigned = 4294967295.
Proof.
(* Goal: @eq Z Int.max_unsigned (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
 unfold Int.max_unsigned, Int.modulus, Int.wordsize, Wordsize_32.wordsize in *.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl. unfold shift_nat. simpl. reflexivity.
Qed.

Lemma decode_val_getN_lem1:
  forall j i b,
          decode_val Mint32 (getN 4 i b) = Vint Int.zero ->
          0 <= j-i < 4 ->
          nth (nat_of_Z (j-i)) (getN 4 i b) Undef = Byte Byte.zero.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
 unfold decode_val in H.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 revert H; case_eq (getN 4 i b); intros. inv H.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 unfold getN in H. destruct l; inv H.
 destruct (proj_bytes
         (ZMap.get i b
          :: ZMap.get (i + 1) b
             :: ZMap.get (i + 1 + 1) b :: ZMap.get (i + 1 + 1 + 1) b :: nil))
    eqn:PB.
*
 simpl proj_bytes in PB.
 destruct (ZMap.get i b); inv PB.
 destruct (ZMap.get (i+1) b); inv H2.
 destruct (ZMap.get (i+1+1) b); inv H3.
 destruct (ZMap.get (i+1+1+1) b); inv H2.
 unfold decode_int in H1.
 assert (Int.repr (int_of_bytes (rev_if_be (i0 :: i1 :: i2 :: i3 :: nil))) = Int.repr 0) by
    (forget (Int.repr (int_of_bytes (rev_if_be (i0 :: i1 :: i2 :: i3 :: nil)))) as foo; inv H1; auto).
 clear H1.
 assert (forall b0 b1 b2 b3, Int.repr (int_of_bytes (b0::b1::b2::b3::nil)) = Int.repr 0 ->
      (Byte.unsigned b0=0/\Byte.unsigned b1=0/\Byte.unsigned b2=0/\Byte.unsigned b3=0)).
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 clear. intros.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
   simpl in H.
  pose proof (Byte.unsigned_range b0).
  pose proof (Byte.unsigned_range b1).
  pose proof (Byte.unsigned_range b2).
  pose proof (Byte.unsigned_range b3).
(* Goal: @eq Z (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
  replace (Byte.modulus) with 256 in * by reflexivity.
  pose proof (Int.unsigned_repr  (Byte.unsigned b0 +
       (Byte.unsigned b1 +
        (Byte.unsigned b2 + (Byte.unsigned b3 + 0) * 256) * 256) * 256)).
  spec H4.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  clear H. rewrite max_unsigned_eq; omega.
  rewrite H in H4.
 rewrite Int.unsigned_repr in H4 by (rewrite max_unsigned_eq; omega).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  omega.
 assert (Byte.unsigned i0=0/\Byte.unsigned i1=0/\Byte.unsigned i2=0/\Byte.unsigned i3=0).
 unfold rev_if_be in H. destruct Archi.big_endian; simpl in H; apply H1 in H; intuition.
 clear H1 H.
  assert (forall i, Byte.unsigned i = 0 -> i = Byte.zero).
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  clear. intros. pose proof (Byte.repr_unsigned i). rewrite H in H0. symmetry; auto.
 destruct H2 as [? [? [? ?]]]. apply H in H1; apply H in H2; apply H in H3; apply H in H4.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
 subst.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 assert (j-i=0 \/ j-i=1 \/ j-i=2 \/ j-i=3) by omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H1 as [? | [?|[?|?]]]; rewrite H1; simpl; auto.
*
 unfold proj_value in H1.
 unfold Val.load_result in H1.
 clear PB.
 destruct (ZMap.get i b); inv H1.
(* Not true if Archi.ptr64=false *)
Abort.

Lemma Zmax_Z_of_nat:
 forall n, Z.max (Z_of_nat n) 0 = Z_of_nat n.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @eq Z (Z.max (Z.of_nat n) Z0) (Z.of_nat n) *)
apply Z.max_l.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
omega.
Qed.
(*
Lemma Zmax_of_nat:
  forall n, Z_of_nat (nat_of_Z n) = Z.max n 0.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
 apply nat_of_Z_max.
Qed.
*)

Lemma snd_split_fullshare_not_bot: snd (Share.split fullshare) <> Share.bot.
Proof.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
intro.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
case_eq (Share.split fullshare); intros.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
rewrite H0 in H. simpl in H. subst.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
apply Share.split_nontrivial in H0; auto.
(* Goal: False *)
apply Share.nontrivial in H0. contradiction.
Qed.

Lemma readable_readonly2share: forall ro, readable_share (readonly2share ro).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
  unfold readable_share. intro.
(* Goal: False *)
  apply identity_share_bot in H.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  assert (H9: Share.Rsh <> Share.bot). {
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
    unfold Share.Rsh. intro.
(* Goal: False *)
    destruct (Share.split Share.top) eqn:?.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    pose proof (Share.split_nontrivial _ _ _ Heqp). spec H1; auto. contradiction Share.nontrivial.
  }
(* Goal: False *)
  clear H9.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
  destruct ro; simpl in *.
(* Goal: False *)
(* Goal: False *)
  unfold Ers in H.
(* Goal: False *)
  rewrite Share.distrib1 in H.
(* Goal: False *)
  apply lub_bot_e in H. destruct H as [_ ?].
(* Goal: False *)
(* Goal: False *)
  rewrite glb_split_x in H.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
  destruct (Share.split Share.Rsh) eqn:H0. simpl in *.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  subst.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  pose proof (Share.split_nontrivial _ _ _ H0). spec H; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply snd_split_fullshare_not_bot in H. auto.
(* Goal: False *)
  unfold Ews in H.
(* Goal: False *)
  rewrite Share.distrib1 in H.
(* Goal: False *)
  apply lub_bot_e in H. destruct H as [_ ?].
(* Goal: False *)
  rewrite Share.glb_idem in H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply snd_split_fullshare_not_bot in H. auto.
Qed.

(*
Lemma nonunit_readonly2share: forall v, nonunit (readonly2share (@gvar_readonly type v)).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  destruct (gvar_readonly v); simpl.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
  clear.  unfold Share.Lsh. repeat intro.
  pose proof (fst_split_fullshare_not_bot).
(* Goal: False *)
  apply unit_identity in H. apply identity_share_bot in H. contradiction H0; apply H.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
  clear. repeat intro. pose proof (Share.nontrivial).
(* Goal: False *)
  apply unit_identity in H. apply identity_share_bot in H. contradiction H0; apply H.
Qed.
*)

(*
Lemma readable_splice_extern: forall v, readable_share (Share.lub extern_retainer (readonly2share (@gvar_readonly type v))).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
  apply readable_share_lub. apply readable_readonly2share.
Qed.
*)

Lemma init_data_lem:
forall (ge: genv) (v : globvar type) (b : block) (m1 : mem')
  (m3 m4 : Memory.mem) (phi0 : rmap) (a : init_data) (z : Z) (rho: environ)
  (w1 wf : rmap),
   load_store_init_data1 ge m3 b z a ->
   contents_at m4 = contents_at m3 ->
   join w1 wf (beyond_block b (inflate_initial_mem m4 phi0)) ->
   (forall loc : address,
     if adr_range_dec (b, z) (init_data_size a) loc
     then identity (wf @ loc) /\ access_at m4 loc Cur = Some (Genv.perm_globvar v)
     else identity (w1 @ loc)) ->
   forall (Hg: noghost w1) (VOL:  gvar_volatile v = false)
          (AL: initializer_aligned z a = true)
           (LO:   0 <= z) (HI: z + init_data_size a < Ptrofs.modulus)
         (RHO: ge_of rho = filter_genv ge),
  (init_data2pred a  (readonly2share (gvar_readonly v))
       (Vptr b (Ptrofs.repr z))) rho w1.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
  assert (APOS:= init_data_size_pos a).
  assert (READABLE:= readable_readonly2share (gvar_readonly v)).
  Transparent load.
  unfold init_data2pred, mapsto.
  unfold mapsto_zeros, address_mapsto, res_predicates.address_mapsto,
    fst,snd.
  rewrite Ptrofs.unsigned_repr by (unfold Ptrofs.max_unsigned; omega).
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl.
  unfold mapsto, tc_val, is_int, is_long, is_float.
  destruct (readable_share_dec
            (readonly2share (gvar_readonly v))); [clear r | tauto].
  destruct a; 
  repeat rewrite prop_true_andp by 
    first [apply I
            | apply sign_ext_range'; compute; split; congruence
            | apply zero_ext_range'; compute; split; congruence
            ];
  try left; simpl in H; unfold load in H;
  try (if_tac in H; [ | discriminate H]);
  repeat rewrite prop_true_andp by apply I;
  try match type of H with Some (decode_val ?ch ?B) = Some (?V) =>
            exists B; replace V with (decode_val ch B) by (inversion H; auto);
            clear H; repeat split; auto
       end.
* (* Int8 *)
  apply Zone_divide.
* (* Int8 *)
  intro loc; specialize (H2 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. hnf. if_tac; auto.
  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf. rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (destruct loc; destruct H; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
  unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
* (* Int16 *)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in AL. apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
* (* Int16 *)
  intro loc; specialize (H2 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. simpl size_chunk. hnf; if_tac; auto.
  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (  destruct loc; destruct H; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
* (* Int32 *)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in AL. apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
* (* Int32 *)
  intro loc; specialize (H2 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. simpl size_chunk. hnf; if_tac; auto.
  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (  destruct loc; destruct H; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
* (* Int64 *)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in AL. apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
* (* Int64 *)
  intro loc; specialize (H2 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. simpl size_chunk. hnf; if_tac; auto.
  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (  destruct loc; destruct H; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
* (* Float32 *)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in AL. apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
* (* Float32 *)
  intro loc; specialize (H2 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. simpl size_chunk. hnf; if_tac; auto.
  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (  destruct loc; destruct H; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
* (* Float64 *)
   clear - AL.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in AL. apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
  rewrite <- Zeq_is_eq_bool in *.
  apply Zmod_divides; [ omega | ].
  apply Zmod_divides in AL; [ | omega].
  destruct AL as [c ?]. exists (2 * c). rewrite Z.mul_assoc. apply H.
*  intro loc; specialize (H2 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in H2. simpl size_chunk. hnf; if_tac; auto.
  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (  destruct loc; destruct H; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H; subst b0.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
* (* address_mapsto_zeros *)
 rewrite address_mapsto_zeros_eq.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 split; auto. 
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  split; auto. simpl in HI. clear - HI. destruct (Z.max_spec z0 0); destruct H; omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 split; auto.
(* Goal: not (@In ident i (@map (prod ident A) ident (@fst ident A) (@prog_funct' A B vl))) *)
(* Goal: @list_norepet ident (@map (prod ident A) ident (@fst ident A) (@prog_funct' A B vl)) *)
  intro loc. hnf. specialize (H2 loc); simpl in H2.
rewrite Zmax_Z_of_nat.
rewrite nat_of_Z_max.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
if_tac; auto.

  exists READABLE.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true by (  destruct loc; destruct H3; subst; simpl; unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'. rewrite H4.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct loc; destruct H3; subst b0.
  specialize (H (z1-z)).  spec H; [omega |].
  if_tac in H; [ | discriminate].
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  replace (z+(z1-z)) with z1 in * by omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
  inv H.
  assert (contents_at m3 (b,z1) = Byte Byte.zero).
    unfold contents_at.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
    simpl. forget (ZMap.get z1 (PMap.get b (mem_contents m3))) as byt.
    clear - H7.
    unfold decode_val in H7.
(* Goal: @eq (option val) (load chunk m' b' p') (load chunk m b' p') *)
    revert H7; case_eq (proj_bytes (byt::nil)); intros; try discriminate.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
    simpl in  H. destruct byt; inv H.
    unfold decode_int in H7.
    replace (rev_if_be (i::nil)) with (i::nil) in H7 by (unfold rev_if_be; destruct Archi.big_endian; auto).
    simpl int_of_bytes in H7.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
    replace (Byte.unsigned i + 0) with (Byte.unsigned i) in H7 by omega.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V (@rev (prod ident (globdef F V)) vl)) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
    f_equal.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   apply zero_ext_inj. forget (Int.zero_ext 8 (Int.repr (Byte.unsigned i))) as j; inv H7; auto.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.

* (* symbol case *)
 rewrite RHO.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  case_eq (Map.get (filter_genv ge) i); try destruct p0; auto; intros.
+
  unfold filter_genv, Map.get in H4.
(* Goal: @eq (option val) (load chunk m' b' p') (load chunk m b' p') *)
  revert H4; case_eq (Genv.find_symbol ge i); intros; try discriminate.
  inv H5.
  left. split; [apply I | ].
  rewrite H4 in H.
 exists  (getN (size_chunk_nat Mptr) z (mem_contents m3) !! b).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 repeat split; auto.
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
 clear - H. 
 cbv iota. congruence.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl in AL. apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
  intro loc; specialize (H2 loc). hnf. simpl init_data_size in H2.
 replace (if Archi.ptr64 then 8 else 4) with (size_chunk Mptr) in H2
   by (unfold Mptr; destruct Archi.ptr64; reflexivity).
 if_tac; [ | apply H2].
  exists READABLE. hnf. 
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1. hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true
   by (destruct loc, H,H5; subst; simpl;
        unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
  unfold inflate_initial_mem'. rewrite H6.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H5.  subst b1.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
(* Goal: @join resource Join_resource (resource_at w1 loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
  rewrite H0.
  destruct loc; destruct H5; subst b1.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nth_getN; simpl; omega.
+
  erewrite mapsto__exp_address_mapsto by (auto; reflexivity).
  rewrite exp_address_mapsto_VALspec_range_eq.
  rewrite Ptrofs.unsigned_repr by (change Ptrofs.max_unsigned with (Ptrofs.modulus-1); omega).
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
  split.
  simpl in AL|-*.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply Zmod_divide.  intro Hx; inv Hx. apply Zeq_bool_eq; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  hnf. split; auto. intro loc; specialize (H2 loc). hnf.
  simpl init_data_size in H2.
 replace (if Archi.ptr64 then 8 else 4) with (size_chunk Mptr) in H2
   by (unfold Mptr; destruct Archi.ptr64; reflexivity).
 if_tac; [ | apply H2].
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gfun fundef type f))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 (@Gvar fundef type v))) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
 destruct H2.
  apply join_comm in H1.
  apply (resource_at_join _ _ _ loc) in H1.
  apply H2 in H1.
  eexists.
  hnf. exists READABLE.
  hnf; rewrite H1.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  rewrite if_true
   by (destruct loc, H,H5; subst; simpl;
        unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem. rewrite resource_at_make_rmap.
  unfold inflate_initial_mem'. rewrite H6.
 unfold Genv.perm_globvar. rewrite VOL. rewrite preds_fmap_NoneP.
  destruct (gvar_readonly v);  repeat f_equal; auto with extensionality.
Qed.

Lemma init_data_list_size_app:
  forall dl1 dl2, init_data_list_size (dl1++dl2) =
                   init_data_list_size dl1 + init_data_list_size dl2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. induction dl1; intros; simpl; auto. rewrite IHdl1; omega.
Qed.


Lemma max_unsigned_modulus:
  Ptrofs.max_unsigned + 1 = Ptrofs.modulus.
Proof.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 unfold Ptrofs.max_unsigned. omega.
Qed.

Lemma init_data_list_lem:
  forall (ge: genv) m0 (v: globvar type) m1 b m2 m3 m4  phi0 rho,
     alloc m0 0 (init_data_list_size (gvar_init v)) = (m1,b) ->
     store_zeros m1 b 0 (init_data_list_size (gvar_init v)) = Some m2 ->
     Genv.store_init_data_list ge m2 b 0 (gvar_init v) = Some m3 ->
     drop_perm m3 b 0 (init_data_list_size (gvar_init v))
               (Genv.perm_globvar v) = Some m4 ->
  forall
   (Hg: noghost phi0) (SANITY: init_data_list_size (gvar_init v) < Ptrofs.modulus)
   (VOL:  gvar_volatile v = false)
   (AL: initializers_aligned 0 (gvar_init v) = true)
   (RHO: ge_of rho = filter_genv ge),
     init_data_list2pred (gvar_init v) (readonly2share (gvar_readonly v)) (Vptr b Ptrofs.zero)
            rho (beyond_block b (inflate_initial_mem m4 phi0)).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
set (phi := beyond_block b (inflate_initial_mem m4 phi0)).
assert (forall loc, fst loc <> b -> identity (phi @ loc)).
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold phi; intros.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold beyond_block. rewrite only_blocks_at.
  if_tac; [ |  apply core_identity].
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem.  rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'.
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold access_at.
  rewrite nextblock_noaccess. apply NO_identity.
  rewrite (nextblock_drop _ _ _ _ _ _ H2).
  rewrite (Genv.store_init_data_list_nextblock _ _ _ _ _ H1).
  rewrite (Genv.store_zeros_nextblock _ _ _ _ H0).
  assert (nextblock m1 = Pos.succ b /\ b = nextblock m0).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   clear - H. Transparent alloc. inv H.  simpl. auto. Opaque alloc.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 destruct H5; unfold block in *; xomega.
 assert (forall loc, if adr_range_dec (b,0)  (init_data_list_size (gvar_init v)) loc
                             then access_at m4 loc Cur = Some (Genv.perm_globvar v)
                             else identity (phi @ loc)).
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
  intro. if_tac.
     destruct loc; destruct H4; subst b0.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
     unfold access_at. simpl. forget (Genv.perm_globvar v) as p.
      forget (init_data_list_size (gvar_init v)) as n.
     clear - H2 H5. unfold drop_perm in H2.
      destruct (range_perm_dec m3 b 0 n Cur Freeable); inv H2.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
      simpl.  rewrite PMap.gss.
       destruct (zle 0 z); try omegaContradiction. destruct (zlt z n); try omegaContradiction.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
       simpl; auto.
(* Goal: @eq resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    destruct loc.
  destruct (eq_dec b b0). subst b0.
(* Goal: and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
  unfold phi. unfold beyond_block. rewrite only_blocks_at.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
   simpl. rewrite if_true by (unfold block; xomega).
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem.  rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'.
  replace (access_at m4 (b,z) Cur) with (@None permission).
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
  apply NO_identity.
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
  symmetry.  transitivity (access_at m3 (b,z) Cur).
  clear - H4 H2. unfold access_at; unfold drop_perm in H2.
   destruct (range_perm_dec m3 b 0 (init_data_list_size (gvar_init v)) Cur
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
         Freeable); inv H2. simpl. rewrite PMap.gss.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold adr_range in H4. destruct (zle 0 z); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   destruct (zlt z (init_data_list_size (gvar_init v)) ); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  contradiction H4. split; auto.
  transitivity (access_at m2 (b,z) Cur).
  apply store_init_data_list_outside' in H1.
(* Goal: not (@eq Z ofs Z0) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  destruct H1 as [? [? ?]]; congruence.
  transitivity (access_at m1 (b,z) Cur).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  clear - H0. erewrite store_zeros_access; eauto.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
  clear - H H4. Transparent alloc. inv H. Opaque alloc. unfold access_at; simpl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite PMap.gss. destruct (zle 0 z); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   destruct (zlt z (init_data_list_size (gvar_init v)) ); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  contradiction H4. split; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   apply H3. auto.
  clear H3.
  assert (contents_at m4 = contents_at m3).
  clear - H2; unfold contents_at, drop_perm in *.
   destruct (range_perm_dec m3 b 0 (init_data_list_size (gvar_init v)) Cur
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
         Freeable); inv H2. simpl. auto.
   clear H2.
   forget (gvar_init v) as dl.
   remember dl as D.
   rewrite HeqD in AL,H4|-*.
   assert (nil++dl=D) by (subst; auto).
   remember (@nil init_data) as dl'.
   remember (core phi) as w'.
   remember phi as w.
(* Goal: @join resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)) (resource_at w' loc) (resource_at w' loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) (resource_at w' loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
   assert (join w' w phi). subst. apply core_unit.
   unfold Ptrofs.zero.
   remember 0 as z. rewrite Heqz in H,H0,H1.
   replace z with (init_data_list_size dl') in AL,H4|-* by (subst; auto).
   clear z Heqz.
   assert (forall loc, if adr_range_dec (b,init_data_list_size dl') (init_data_list_size dl) loc
                               then identity (w' @ loc)  else identity (w @ loc)).
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
  intro. subst. if_tac. rewrite <- core_resource_at. apply core_identity.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  specialize (H4 loc). rewrite if_false in H4 by auto; auto.
  assert (noghost w) as Hgw.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  { subst w phi.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
    unfold beyond_block, only_blocks, inflate_initial_mem; simpl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    rewrite !ghost_of_make_rmap; auto. }
   clear Heqw' Heqw Heqdl' HeqD.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   revert dl' w' w AL H2 H4 H5 H6 Hgw; induction dl; simpl; intros.
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at w2 loc)) (@identity resource Join_resource (resource_at w2' loc))) (forall _ : not (@identity resource Join_resource (resource_at w2 loc)), @eq resource (resource_at w2 loc) (resource_at w2' loc)) *)
   apply all_resource_at_identity; auto; intro loc.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   specialize (H6 loc); if_tac in H6; auto. destruct loc; destruct H7.
   omegaContradiction.
  assert (SANITY': init_data_list_size dl' + init_data_size a + init_data_list_size dl < Ptrofs.modulus).
  clear - H2 SANITY.
  subst D.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite init_data_list_size_app in SANITY. simpl in SANITY. omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (split_range w (b,init_data_list_size dl') (init_data_size a)) as [w1 [w2 [? ?]]]; auto.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros. apply (resource_at_join _ _ _ loc) in H5.
  specialize (H6 loc). rewrite if_true in H6. apply H6 in H5.
(* Goal: @identity resource Join_resource match access_at m (@pair block Z (nextblock m0) Z0) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end | None => NO Share.bot bot_unreadable end *)
  rewrite H5.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
    unfold phi; clear. unfold beyond_block. rewrite only_blocks_at.
   if_tac; [ |   destruct (inflate_initial_mem m4 phi0 @ loc);
                [rewrite core_NO | rewrite core_YES | rewrite core_PURE]; auto].
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
  unfold inflate_initial_mem; rewrite resource_at_make_rmap.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold inflate_initial_mem'. destruct (access_at m4 loc); try destruct p; simpl; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (phi0 @ loc); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct loc. destruct H7; split; auto.
  pose proof (init_data_list_size_pos dl).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  exists w1; exists w2; split3; auto.
  clear IHdl.
  destruct (join_assoc H7 (join_comm H5)) as [wf [? ?]].
  assert (forall loc, if adr_range_dec (b,init_data_list_size dl') (init_data_size a) loc
                                 then identity (wf @ loc) /\
                                         access_at m4 loc Cur = Some (Genv.perm_globvar v)
                                 else identity (w1 @ loc)).
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
     intro. specialize (H8 loc); specialize (H6 loc); specialize (H4 loc).
       apply (resource_at_join _ _ _ loc) in H9;
       apply (resource_at_join _ _ _ loc) in H10.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 if_tac.  rewrite if_true in H6,H4. apply H8 in H9. rewrite <- H9; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   destruct loc; destruct H11; subst b0. split; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
   pose proof (init_data_list_size_pos dl); omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   destruct loc; destruct H11; subst b0. split; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
   pose proof (init_data_list_size_pos dl); omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 auto.
  pose proof (load_store_init_data_lem1 H0 H1 _ _ _ H2).
  unfold phi in *; clear phi.
  eapply init_data_lem; try eassumption.
  apply ghost_of_join in H7.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl; eapply split_identity; eauto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  clear - AL. apply andb_true_iff in AL. destruct AL; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  pose proof (init_data_list_size_pos dl'); omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  pose proof (init_data_list_size_pos dl); omega.
  destruct (join_assoc (join_comm H7) (join_comm H5)) as [wg [? ?]].
  specialize (IHdl  (dl' ++ (a::nil))  wg w2).
  replace (init_data_list_size (dl' ++ a :: nil)) with
             (init_data_list_size dl' + init_data_size a) in IHdl.
  rewrite Ptrofs.add_unsigned.
  repeat rewrite Ptrofs.unsigned_repr
       by (pose proof (init_data_list_size_pos dl'); pose proof (init_data_list_size_pos dl);
      pose proof (init_data_size_pos a); pose proof max_unsigned_modulus; omega).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply IHdl; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply andb_true_iff in AL; destruct AL; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite app_ass; auto.
  intro loc; specialize (H6 loc); specialize (H8 loc); specialize (H4 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  if_tac. rewrite if_true in H4; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct loc; destruct H11; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  split; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  pose proof (init_data_size_pos a); omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  if_tac in H8; auto.
  rewrite if_false in H6.
  apply join_comm in H5.
  apply (resource_at_join _ _ _ loc) in H7.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply H8 in H7. rewrite H7; auto.
(* Goal: @eq resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct loc.
  intros [? ?]. subst b0.
  forget (init_data_list_size dl') as u.
 destruct (zlt z (u + init_data_size a)).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply H12.  split; auto. omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply H11.  split; auto. omega.
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at w2 loc)) (@identity resource Join_resource (resource_at w2' loc))) (forall _ : not (@identity resource Join_resource (resource_at w2 loc)), @eq resource (resource_at w2 loc) (resource_at w2' loc)) *)
  intro loc. specialize (H4 loc); specialize (H6 loc); specialize (H8 loc).
  apply (resource_at_join _ _ _ loc) in H7.
  apply (resource_at_join _ _ _ loc) in H9.
  apply (resource_at_join _ _ _ loc) in H10.
  apply (resource_at_join _ _ _ loc) in H5.
(* Goal: @eq resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct loc.
  if_tac in H8.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite if_false; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 clear - H11; destruct H11; intros [? ?]. omega.
  if_tac in H4.
  rewrite if_true.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply H8 in H9. rewrite <- H9 in *. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct H12; subst b0. split; auto.
  forget (init_data_list_size dl') as u.
  assert (~ (u <= z < u + init_data_size a)) by (contradict H11; destruct H11; split; auto; omega).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite if_false. apply H8 in H7. rewrite H7; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 contradict H12. destruct H12; split; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  pose proof (init_data_size_pos a); omega.
  apply ghost_of_join, join_comm in H7.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl; eapply split_identity; eauto.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
 clear.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  induction dl'; simpl; intros; try omega.
Qed.

Definition all_initializers_aligned (prog: program) :=
  forallb (fun idv => andb (initializers_aligned 0 (gvar_init (snd idv)))
                                 (Zlt_bool (init_data_list_size (gvar_init (snd idv))) Ptrofs.modulus))
                      (prog_vars prog) = true.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Lemma forallb_rev: forall {A} f (vl: list A), forallb f (rev vl) = forallb f vl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. induction vl; simpl; auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  rewrite forallb_app. rewrite IHvl. simpl. rewrite andb_comm.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite <- andb_assoc. f_equal; auto.
Qed.

Lemma store_init_data_list_access:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall  {F V} (ge: Genv.t F V) m b z dl m',
     Genv.store_init_data_list ge m b z dl = Some m' ->
     access_at m = access_at m'.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros. revert z m m' H; induction dl; simpl; intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  inv H; auto.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
 invSome.
(* Goal: @eq (forall (_ : address) (_ : perm_kind), option permission) (access_at m) (access_at m') *)
  transitivity (access_at m0).
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
  clear - H.
  destruct a; simpl in H;
   try solve [unfold access_at; extensionality loc; rewrite (store_access _ _ _ _ _ _ H); auto].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  inv H; auto. invSome.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold access_at; extensionality loc; rewrite (store_access _ _ _ _ _ _ H2); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  eapply IHdl; eauto.
Qed.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
Lemma rev_prog_funct': forall {F V} vl, rev (@prog_funct' F V vl) = prog_funct' (rev vl).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   induction vl. simpl; auto.
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
   destruct a. destruct g.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
   simpl.
   transitivity (prog_funct' (rev vl) ++ (@prog_funct' F V ((i,Gfun f)::nil))).
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V vl)) (@prog_funct' F V (@app (prod ident (globdef F V)) (@rev (prod ident (globdef F V)) vl) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) (@nil (prod ident (globdef F V)))))) *)
    rewrite IHvl. f_equal.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
    simpl.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
    clear.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    induction (rev vl); simpl; intros; auto.
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
    destruct a. destruct g.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    auto.
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@cons (prod ident F) (@pair ident F i0 f0) (@prog_funct' F V l)) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@cons (prod ident F) (@pair ident F i0 f0) (@prog_funct' F V (@app (prod ident (globdef F V)) l (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V))))))) *)
(* Goal: @eq (list (prod ident F)) (@app (prod ident F) (@prog_funct' F V l) (@cons (prod ident F) (@pair ident F i f) (@nil (prod ident F)))) (@prog_funct' F V (@app (prod ident (globdef F V)) l (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gfun F V f)) (@nil (prod ident (globdef F V)))))) *)
(* Goal: @eq (list (prod ident F)) (@rev (prod ident F) (@prog_funct' F V (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) (@prog_funct' F V (@rev (prod ident (globdef F V)) (@cons (prod ident (globdef F V)) (@pair ident (globdef F V) i (@Gvar F V v)) vl))) *)
    rewrite <- IHl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    simpl. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    simpl; auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
    simpl. rewrite IHvl.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
    clear.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    induction (rev vl); simpl; intros; auto. destruct a. destruct g.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    f_equal; auto. auto.
Qed.


Lemma alloc_global_beyond2:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  forall {F V} (ge: Genv.t F V) m iv m', Genv.alloc_global ge m iv = Some m' ->
       forall loc, (fst loc > nextblock m)%positive ->
        access_at m' loc Cur = None.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
 destruct loc as [b ofs]; simpl in *.
 unfold access_at, Genv.alloc_global in *.
Transparent alloc.
 destruct iv; destruct g; simpl @fst; simpl @ snd;
 [forget 1 as N |  forget  (init_data_list_size (gvar_init v)) as N];
 revert H; case_eq (alloc m 0 N); intros; repeat invSome;
 match goal with H: drop_perm ?m _ _ _ _ = _ |- _ =>
   unfold drop_perm in H;
  destruct (range_perm_dec m b0 0 N Cur Freeable); inv H
 end;
  inv H; simpl in *;
 repeat rewrite PMap.gss;
 repeat rewrite PMap.gso by (intro Hx; inv Hx; xomega);
 try (apply nextblock_noaccess; xomega).
 apply store_zeros_access in H1.
 apply store_init_data_list_outside' in H4.
 destruct H4 as [? [? ?]]. rewrite H2 in H1.
 change (access_at m2 (b,ofs) Cur = None).
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 rewrite H1. unfold access_at; simpl.
 repeat rewrite PMap.gso by (intro Hx; inv Hx; xomega).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 apply nextblock_noaccess; xomega.
Qed.

Lemma alloc_global_access:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 forall {F V} (ge: Genv.t F V) m i v m', Genv.alloc_global ge m (i, Gvar v) = Some m' ->
  forall z, access_at m' (nextblock m, z) Cur =
                    if range_dec 0 z (init_data_list_size (gvar_init v))
                    then Some (Genv.perm_globvar v) else None.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
unfold Genv.alloc_global in H.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z (init_data_list_size (@gvar_init V v)) then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
forget (init_data_list_size (gvar_init v)) as N.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
revert H; case_eq (alloc m 0 N); intros.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
invSome. invSome.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
unfold drop_perm in H4.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
destruct (range_perm_dec m2 b 0 N Cur Freeable); inv H4.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold access_at. simpl.
(* Goal: @eq (option permission) (@PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) b (fun (ofs : Z) (k : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs N) (Z.ge ofs N) (zlt ofs N)) then @Some permission (@Genv.perm_globvar V v) else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m2) ofs k) (mem_access m2)) z Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
apply store_zeros_access in H0.
(* Goal: @eq (option permission) (@PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) b (fun (ofs : Z) (k : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs N) (Z.ge ofs N) (zlt ofs N)) then @Some permission (@Genv.perm_globvar V v) else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m2) ofs k) (mem_access m2)) z Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
apply store_init_data_list_access in H3.
(* Goal: @eq (option permission) (@PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) b (fun (ofs : Z) (k : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs N) (Z.ge ofs N) (zlt ofs N)) then @Some permission (@Genv.perm_globvar V v) else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m2) ofs k) (mem_access m2)) z Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
rewrite H0 in H3. clear m1 H0.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
inv H. unfold access_at in H3. simpl in *.
(* Goal: @eq (option permission) (@PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m) (fun (ofs : Z) (k : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs N) (Z.ge ofs N) (zlt ofs N)) then @Some permission (@Genv.perm_globvar V v) else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m) (mem_access m2) ofs k) (mem_access m2)) z Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
apply equal_f with (nextblock m, z) in H3. apply equal_f with Cur in H3.
simpl in H3. rewrite PMap.gss in *.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
destruct (zle 0 z). simpl. destruct (zlt z N).
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
simpl in *.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite if_true; auto. rewrite if_false; auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 intros [? ?]. xomega.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl. rewrite if_false by omega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
simpl in H3; auto.
Qed.

Lemma alloc_global_inflate_same:
  forall n i v gev m G m0,
  Genv.alloc_global gev m0 (i, Gvar v) = Some m ->
   (forall z : Z, initial_core gev G n @ (nextblock m0, z) = NO Share.bot bot_unreadable) ->
   inflate_initial_mem m0 (initial_core gev G n) =
   upto_block (nextblock m0) (inflate_initial_mem m (initial_core gev G n)).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
 apply rmap_ext.
  unfold upto_block, inflate_initial_mem;
(* Goal: @eq nat (@level rmap ag_rmap (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (@level rmap ag_rmap phi) *)
(* Goal: forall loc : AV.address, @join resource Join_resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  rewrite level_only_blocks; repeat rewrite level_make_rmap. auto.
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at w2 loc)) (@identity resource Join_resource (resource_at w2' loc))) (forall _ : not (@identity resource Join_resource (resource_at w2 loc)), @eq resource (resource_at w2 loc) (resource_at w2' loc)) *)
 intro loc.
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)) (@identity resource Join_resource (resource_at (@only_blocks (fun b' : block => Coqlib.Plt b' (nextblock m0)) (fun b' : block => plt b' (nextblock m0)) phi) loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc) (resource_at (@only_blocks (fun b' : block => Coqlib.Plt b' (nextblock m0)) (fun b' : block => plt b' (nextblock m0)) phi) loc)) *)
 unfold upto_block. rewrite only_blocks_at.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))))) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))))) loc)) *)
 unfold inflate_initial_mem.
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
 repeat rewrite resource_at_make_rmap.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 if_tac.
 destruct (alloc_global_old _ _ _ _ H _ H1) as [? ?];
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold inflate_initial_mem'; rewrite H2; rewrite H3; auto.
 destruct (eq_dec (fst loc) (nextblock m0)).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 2:{
 assert (access_at m loc Cur = None).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  eapply alloc_global_beyond2; try eassumption. unfold block in *; xomega.
 assert (access_at m0 loc Cur = None).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold access_at. apply nextblock_noaccess. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold inflate_initial_mem'; rewrite H2; rewrite H3; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite core_NO; auto.
 }
 clear H1.
 specialize (H0 (snd loc)).
 assert (access_at m0 loc Cur = None).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  unfold access_at. apply nextblock_noaccess. rewrite <- e; xomega.
 unfold inflate_initial_mem' at 1. rewrite H1.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
  unfold inflate_initial_mem'.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
 destruct loc; simpl in e; subst.
 rewrite (alloc_global_access _ _ _ _ _ H).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 if_tac. unfold Genv.perm_globvar. simple_if_tac. simpl in H0. rewrite H0. rewrite core_NO; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simple_if_tac; rewrite core_YES; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite core_NO; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold upto_block, only_blocks, inflate_initial_mem; rewrite !ghost_of_make_rmap; auto.
Qed.

Lemma find_id_rev: forall i G,
 list_norepet (map fst G) -> find_id i (rev G) = find_id i G.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
induction G; simpl; intros; auto.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
inv H. destruct a. simpl in *. specialize (IHG H3).
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
if_tac. subst.
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
clear - H2.
(* Goal: @eq (option funspec) (find_id i0 (@app (prod ident funspec) (@rev (prod ident funspec) G) (@cons (prod ident funspec) (@pair ident funspec i0 f) (@nil (prod ident funspec))))) (@Some funspec f) *)
(* Goal: @eq (option funspec) (find_id i (@app (prod ident funspec) (@rev (prod ident funspec) G) (@cons (prod ident funspec) (@pair ident funspec i0 f) (@nil (prod ident funspec))))) (find_id i G) *)
rewrite In_rev in H2. rewrite <- map_rev in H2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 induction (rev G); simpl; auto. rewrite if_true; auto.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
 destruct a;  simpl in *.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 if_tac. subst. intuition. apply IHl; intuition.
(* Goal: @eq (option funspec) (find_id i (@app (prod ident funspec) (@rev (prod ident funspec) G) (@cons (prod ident funspec) (@pair ident funspec i0 f) (@nil (prod ident funspec))))) (find_id i G) *)
 rewrite <- IHG. clear IHG.
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
 clear - H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 induction (rev G); simpl; auto. rewrite if_false; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct a; simpl in *. if_tac; auto.
Qed.


Definition prog_var_block (rho: environ) (il: list ident) (b: block) : Prop :=
  Exists (fun id => match ge_of rho id with Some b' => b'=b | _ => False end) il.

Lemma match_fdecs_in:
  forall i vl G,
     In i (map (@fst _ _) G) ->
     match_fdecs vl G ->
     In i (map (@fst _ _) vl).
Proof.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 induction vl; simpl; intros; auto.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 inv H0. inv H.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
 inv H0.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H. inv H. simpl; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 right. apply (IHvl G0); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* EXPERIMENT right; apply (IHvl G); auto. *)
Qed.

Lemma match_fdecs_norepet:
  forall vl G,
     list_norepet (map (@fst _ _) vl) ->
     match_fdecs vl G ->
     list_norepet (map (@fst _ _) G).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 induction vl; simpl; intros.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
 inv H0. constructor.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 inv H0. inv H.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 simpl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 constructor; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 contradict H2. eapply match_fdecs_in; eauto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* EXPERIMENT  inv H; eauto. *)
Qed.

Lemma list_norepet_prog_funct':
  forall A B (vl: list (ident * globdef A B)),
        list_norepet (map (@fst _ _) vl) ->
       list_norepet (map (@fst _ _) (prog_funct' vl)).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 induction vl; simpl; intros.
(* Goal: match_fdecs (@nil (prod ident fundef)) (@nil (prod ident funspec)) *)
 constructor.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 inv H. destruct a as [i [?|?]].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 simpl. constructor; auto.
(* Goal: not (@In ident i (@map (prod ident A) ident (@fst ident A) (@prog_funct' A B vl))) *)
(* Goal: @list_norepet ident (@map (prod ident A) ident (@fst ident A) (@prog_funct' A B vl)) *)
 simpl in H2. contradict H2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 clear - H2; induction vl; simpl in *; auto. destruct a.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct g; simpl in *; auto. destruct H2; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply IHvl; auto.
Qed.

(* EXPERIMENT
Lemma match_fdecs_nil:
  forall vl, match_fdecs vl nil.
(* Goal: match_fdecs (@nil (prod ident fundef)) (@nil (prod ident funspec)) *)
Proof. induction vl; try constructor 3; auto; constructor.
Qed.
*)

Lemma match_fdecs_rev':
  forall vl G vl' G',
   list_norepet (map (@fst _ _) (rev vl ++ vl')) ->
   match_fdecs vl G ->
   match_fdecs vl' G' ->
   match_fdecs (rev vl ++ vl') (rev G ++ G').
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
induction vl; intros.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
simpl in *.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
destruct G; inv H0. apply H1.
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
destruct a.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
inv H0.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl. do 2 rewrite app_ass.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl.
(* Goal: match_fdecs (@app (prod ident fundef) (@rev (prod ident fundef) vl) (@cons (prod ident fundef) (@pair ident fundef i f) vl')) (@app (prod ident funspec) (@rev (prod ident funspec) G0) (@cons (prod ident funspec) (@pair ident funspec i fspec) G')) *)
apply IHvl.
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
clear - H.
simpl rev in *.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
repeat rewrite map_app in H.
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@app (prod ident fundef) (@rev (prod ident fundef) vl) (@cons (prod ident fundef) (@pair ident fundef i f) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
repeat rewrite map_app.
simpl in H|-*.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
repeat rewrite map_app in H.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
simpl in H.
(* Goal: @list_norepet ident (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
rewrite list_norepet_app.
(* Goal: and (@list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl))) (and (@list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) (@list_disjoint ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl')))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
repeat rewrite list_norepet_app in H.
(* Goal: and (@eq ghost (ghost_of (beyond_block b w)) (ghost_of (beyond_block b w'))) (forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc))) *)
decompose [and] H; clear H.
(* Goal: and (@list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl))) (and (@list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl'))) (@list_disjoint ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl')))) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
clear H0.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
repeat split; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
constructor; auto.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
intro.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
apply (H5 i i); auto.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
apply in_app. right; left; auto.
(* Goal: @list_disjoint ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) vl')) *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
intros j k ? ? ?; subst k.
(* Goal: False *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
apply (H5 j j).
(* Goal: @In ident j (@app ident (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl)) (@cons ident i (@nil ident))) *)
(* Goal: @In ident j (@map (prod ident fundef) ident (@fst ident fundef) vl') *)
(* Goal: @eq ident j j *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
rewrite in_app.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
destruct H0. right; left; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
left; rewrite map_rev, <- in_rev; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite map_rev, <- in_rev in H; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
destruct H0; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
subst j. specialize (H4 i i). contradiction H4; auto.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
left; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
constructor 2; auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
(* EXPERIMENT simpl. rewrite app_ass.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
apply IHvl; auto.
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
clear - H.
(* Goal: @list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
rewrite map_app in H.
rewrite map_app.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
simpl in *.
(* Goal: @list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
rewrite map_app in H.
rewrite app_ass in H.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
simpl in *.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
auto.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl.
constructor 3.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
auto.
*)
Qed.

Lemma match_fdecs_rev:
  forall vl G,
   list_norepet (map (@fst _ _) vl) ->
   match_fdecs (rev vl) (rev G) = match_fdecs vl G.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros; apply prop_ext; split; intros.
*
(* Goal: match_fdecs vl G *)
  rewrite (app_nil_end vl).
(* Goal: match_fdecs (@app (prod ident fundef) vl (@nil (prod ident fundef))) G *)
  rewrite (app_nil_end G).
(* Goal: match_fdecs (@app (prod ident fundef) vl (@nil (prod ident fundef))) (@app (prod ident funspec) G (@nil (prod ident funspec))) *)
  rewrite <- (rev_involutive vl), <- (rev_involutive G).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply match_fdecs_rev'; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite rev_involutive, <- app_nil_end; auto.
(* Goal: match_fdecs (@nil (prod ident fundef)) (@nil (prod ident funspec)) *)
  constructor.
*
(* Goal: match_fdecs (@rev (prod ident fundef) vl) (@rev (prod ident funspec) G) *)
  rewrite (app_nil_end (rev vl)).
(* Goal: match_fdecs (@app (prod ident fundef) (@rev (prod ident fundef) vl) (@nil (prod ident fundef))) (@rev (prod ident funspec) G) *)
  rewrite (app_nil_end (rev G)).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply match_fdecs_rev'; auto.
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@app (prod ident fundef) (@rev (prod ident fundef) vl) (@nil (prod ident fundef)))) *)
(* Goal: match_fdecs (@nil (prod ident fundef)) (@nil (prod ident funspec)) *)
  rewrite <- app_nil_end.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite map_rev. rewrite list_norepet_rev; auto.
(* Goal: match_fdecs (@nil (prod ident fundef)) (@nil (prod ident funspec)) *)
  constructor.
Qed.

Lemma initial_core_rev:
  forall (gev: Genv.t fundef type) G n (vl: list (ident * globdef fundef type))
    (H: list_norepet (map fst (rev vl)))
    (SAME_IDS : match_fdecs (prog_funct' vl) (rev G)),
    initial_core gev G n = initial_core gev (rev G) n.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros.
     unfold initial_core;  apply rmap_ext.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
+   repeat rewrite level_make_rmap; auto.
+   intro loc; repeat rewrite resource_at_make_rmap; unfold initial_core'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    if_tac; auto. case_eq (@Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z loc)); intros; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    replace (find_id i G) with (find_id i (rev G)); auto.
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
    clear - H SAME_IDS.
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
    assert (list_norepet (map (@fst _ _) (rev G))).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
     eapply match_fdecs_norepet; eauto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   clear - H; induction vl; simpl in *; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   destruct a; destruct g; simpl in *; auto.
(* Goal: @list_norepet ident (@cons ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
   rewrite map_app in H. rewrite list_norepet_app in H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   destruct H as [? [? ?]]. constructor; auto.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
   simpl in H1.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
   apply list_disjoint_sym in H1.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
   pose proof (list_disjoint_notin i H1).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
   inv H0. spec H2. left; auto. contradict H2.
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) (@rev (prod ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
   rewrite map_rev. rewrite <- in_rev.
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
   clear - H2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   induction vl; simpl in *; auto. destruct a. destruct g.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
   destruct H2. simpl in *; left; auto. right; auto. right; auto. 
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   rewrite map_app, list_norepet_app in H.   destruct H as [? [? ?]]; auto. 
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply find_id_rev; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    rewrite <- list_norepet_rev, <- map_rev. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
+ rewrite !ghost_of_make_rmap; auto.
Qed.

Definition hackfun phi0 phi :=
  level phi0 = level phi /\ ghost_of phi0 = ghost_of phi /\
  forall loc, (identity (phi0 @ loc) <-> identity (phi @ loc)) /\
                  (~identity (phi0 @ loc) -> (phi0 @ loc = phi @ loc)).

Lemma alloc_Gfun_inflate:
  forall n rho i f fs gv vl gev m0 m G0 G,
   Genv.alloc_global gev m0 (i, Gfun f) = Some m ->
   (forall phi : rmap,
    hackfun (inflate_initial_mem m0 (initial_core gev (G0 ++ (i, fs) :: G) n))
      phi ->
  (globvars2pred gv vl rho) phi) ->
  Genv.find_symbol gev i = Some (nextblock m0) ->
  ~ In i (map fst vl) ->
  forall phi : rmap,
  hackfun (inflate_initial_mem m (initial_core gev (G0 ++ (i, fs) :: G) n)) phi ->
      (globvars2pred gv vl rho) phi.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
(* Goal: @app_pred rmap ag_rmap (globvars2pred gv vl rho) phi *)
 apply H0.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H3 as [H3' [Hg H3]]; split. rewrite inflate_initial_mem_level in H3'|-*; auto.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 split.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 { unfold inflate_initial_mem in *; rewrite ghost_of_make_rmap in *; auto. }
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
 intro loc; specialize (H3 loc).
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
 clear - H3 H2 H1 H.
 assert (exists fs', find_id i (G0 ++ (i,fs)::G) = Some fs').
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 clear. induction G0; simpl. exists fs; rewrite if_true; eauto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct IHG0 as [fs' ?]. destruct a. if_tac. subst i0; exists f; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 eauto.
 forget (G0++(i,fs)::G) as GG.  clear G0 fs G.
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
 destruct H0 as [fs H0].
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
 destruct H3.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
 destruct (eq_dec loc (nextblock m0, 0)).
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
 subst loc.
 unfold inflate_initial_mem in *.
 rewrite resource_at_make_rmap in *.
 unfold inflate_initial_mem' in *.
 replace (access_at m0 (nextblock m0, 0) Cur) with (@None permission) in *.
 replace (access_at m (nextblock m0, 0) Cur) with (Some Nonempty) in *.
 unfold initial_core in *. rewrite resource_at_make_rmap in *.
 unfold initial_core' in *.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
 simpl in *.
 rewrite (Genv.find_invert_symbol gev i H1) in H3,H4. rewrite H0 in *. destruct fs.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (resource_at phi (@pair block Z (nextblock m0) Z0)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (resource_at phi (@pair block Z (nextblock m0) Z0))) *)
(* Goal: @eq (option permission) (@Some permission Nonempty) (access_at m (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
 rewrite <- H3.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 split.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 split; intro. apply PURE_identity. apply NO_identity. intro. contradiction H5.
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
 apply NO_identity.
(* Goal: @eq (option permission) (access_at m (@pair block Z (nextblock m0) Z0) Cur) (@Some permission Nonempty) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 (@pair block Z (nextblock m0) Z0) Cur) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) (resource_at phi loc)) *)
 symmetry. clear - H.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  unfold Genv.alloc_global in H.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert H; case_eq (alloc m0 0 1); intros. unfold drop_perm in H0.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct (range_perm_dec m1 b 0 1 Cur Freeable); inv H0.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  unfold access_at; simpl. apply alloc_result in H; subst b. rewrite PMap.gss.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct (zle 0 0); try omegaContradiction. destruct (zlt 0 1); try omegaContradiction; simpl. auto.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 symmetry. apply nextblock_noaccess. simpl; unfold block; clear; xomega.
 replace (inflate_initial_mem m0 (initial_core gev GG n) @ loc)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   with (inflate_initial_mem m (initial_core gev GG n) @ loc); auto.
(* Goal: @eq resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev GG n)) loc) (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev GG n)) loc) *)
 clear - n0 H.
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
 unfold inflate_initial_mem; repeat rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
 unfold inflate_initial_mem'.
(* Goal: @eq resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end *)
 assert (H8: access_at m0 loc = access_at m loc); [ | rewrite H8; auto].
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  unfold Genv.alloc_global in H.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert H; case_eq (alloc m0 0 1); intros. unfold drop_perm in H0.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct (range_perm_dec m1 b 0 1 Cur Freeable); inv H0.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
  unfold alloc; inv H. unfold access_at; simpl.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
  destruct loc as [b z]; simpl in *.
(* Goal: @eq (forall _ : perm_kind, option permission) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m0) z k) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (k0 : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Nonempty else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs0 : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs0) (Z.gt Z0 ofs0) (zle Z0 ofs0)) (@proj_sumbool (Z.lt ofs0 (Zpos xH)) (Z.ge ofs0 (Zpos xH)) (zlt ofs0 (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) ofs k0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0))) z k) *)
(* Goal: @eq resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (eq_dec b (nextblock m0)).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  subst. repeat rewrite PMap.gss. assert (z<>0) by congruence.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  destruct (zle 0 z). simpl. destruct (zlt z 1); try omegaContradiction. simpl.
(* Goal: @eq (forall _ : perm_kind, option permission) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (mem_access m0) z k) (fun _ : perm_kind => @None permission) *)
(* Goal: @eq (forall _ : perm_kind, option permission) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m0) z k) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (k0 : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Nonempty else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs0 : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs0) (Z.gt Z0 ofs0) (zle Z0 ofs0)) (@proj_sumbool (Z.lt ofs0 (Zpos xH)) (Z.ge ofs0 (Zpos xH)) (zlt ofs0 (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) ofs k0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0))) z k) *)
(* Goal: @eq resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end *)
  extensionality k.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nextblock_noaccess. xomega.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
   destruct (zlt z 1); try omegaContradiction. simpl.
(* Goal: @eq (forall _ : perm_kind, option permission) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (mem_access m0) z k) (fun _ : perm_kind => @None permission) *)
(* Goal: @eq (forall _ : perm_kind, option permission) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m0) z k) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (k0 : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Nonempty else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs0 : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs0) (Z.gt Z0 ofs0) (zle Z0 ofs0)) (@proj_sumbool (Z.lt ofs0 (Zpos xH)) (Z.ge ofs0 (Zpos xH)) (zlt ofs0 (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) ofs k0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0))) z k) *)
(* Goal: @eq resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end *)
  extensionality k.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  apply nextblock_noaccess. xomega.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite PMap.gss. rewrite PMap.gso by auto. rewrite PMap.gso by auto. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 case_eq (access_at m loc Cur); auto.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  unfold Genv.alloc_global in H.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert H; case_eq (alloc m0 0 1); intros. unfold drop_perm in H0.
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct (range_perm_dec m1 b 0 1 Cur Freeable); inv H0.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  unfold contents_at; simpl. unfold access_at in H1; simpl in H1.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  destruct (eq_dec b (fst loc)). subst. rewrite PMap.gss in H1.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (zle 0 (snd loc)); simpl in H1; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (zlt (snd loc) 1); simpl in H1; auto. assert (snd loc = 0) by omega.
  destruct loc; apply alloc_result in H; simpl in *; congruence.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 clear r H8. inv H. simpl in *. rewrite H3 in *; rewrite PMap.gss in *.
  destruct (zle 0 (snd loc)); try omegaContradiction.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (zlt (snd loc) 1); try omegaContradiction. inv H1; auto.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
  clear H8 r. inv H. simpl in H1; rewrite <- H3 in H1; rewrite PMap.gss in H1.
  destruct (zle 0 (snd loc)); try omegaContradiction.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (zlt (snd loc) 1); try omegaContradiction. inv H1; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite PMap.gso in H1 by auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  replace (PMap.get (fst loc) (mem_contents m1)) with (PMap.get (fst loc) (mem_contents m0)); auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  inv H; simpl. rewrite PMap.gso; auto.
Qed.

Lemma resource_identity_dec:
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 forall (r: resource), {identity r}+{~identity r}.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros. destruct r.
(* Goal: sumbool (@identity resource Join_resource (NO sh n)) (not (@identity resource Join_resource (NO sh n))) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
destruct (eq_dec sh Share.bot).
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
subst; left; apply NO_identity.
(* Goal: or (not (@eq block (nextblock m0) (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
right. intro. apply identity_NO in H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
destruct H. inv H. contradiction n0; auto.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
destruct H as [? [? ?]]. inv H.
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
 right; apply YES_not_identity.
(* Goal: @identity resource Join_resource (PURE (FUN f0 c) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1)))) *)
(* Goal: @In (prod ident funspec) (@pair ident funspec i fd) (@app (prod ident funspec) G0 G) *)
left; apply PURE_identity.
Qed.

Lemma hackfun_sep:
 forall w1 w2 w w', hackfun w w' -> join w1 w2 w ->
   exists w1', exists w2', join w1' w2' w' /\ hackfun w1 w1' /\ hackfun w2 w2'.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 pose proof I.
 destruct (make_rmap (fun loc => if resource_identity_dec (w1 @ loc) then core (w' @ loc) else w1 @ loc) (ghost_of w1) (level w))  as [w1' [? ?]]; clear H1.
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc)) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 extensionality loc.
(* Goal: @eq resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 unfold compose. if_tac. rewrite core_resource_at.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 replace (level w) with (level w') by (destruct H; auto).
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w')) (approx (@level rmap ag_rmap w')) (resource_at (@core rmap Join_rmap Sep_rmap w') loc)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 rewrite <- level_core. apply resource_at_approx.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w1 loc)) (resource_at w1 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w1)) (ghost_of w1) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 replace (level w) with (level w1) by (apply join_level in H0; destruct H0; auto).
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w2)) (approx (@level rmap ag_rmap w2)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 apply resource_at_approx.
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w1)) (ghost_of w1) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 destruct (join_level _ _ _ H0) as [<- _].
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w1)) (approx (@level rmap ag_rmap w1)) (ghost_of w1)) (ghost_of w1) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 apply ghost_of_approx.
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 pose proof I.
 destruct (make_rmap (fun loc => if resource_identity_dec (w2 @ loc) then core (w' @ loc) else w2 @ loc) (ghost_of w2) (level w))  as [w2' [? ?]]; clear H1.
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc)) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 extensionality loc.
(* Goal: @eq resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 unfold compose. if_tac. rewrite core_resource_at.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 replace (level w) with (level w') by (destruct H; auto).
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w')) (approx (@level rmap ag_rmap w')) (resource_at (@core rmap Join_rmap Sep_rmap w') loc)) (resource_at (@core rmap Join_rmap Sep_rmap w') loc) *)
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 rewrite <- level_core. apply resource_at_approx.
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 replace (level w) with (level w2) by (apply join_level in H0; destruct H0; auto).
(* Goal: @eq resource (resource_fmap (approx (@level rmap ag_rmap w2)) (approx (@level rmap ag_rmap w2)) (resource_at w2 loc)) (resource_at w2 loc) *)
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w)) (ghost_of w2)) (ghost_of w2) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 apply resource_at_approx.
(* Goal: @eq ghost (ghost_fmap (approx (@level rmap ag_rmap w1)) (approx (@level rmap ag_rmap w1)) (ghost_of w1)) (ghost_of w1) *)
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 destruct (join_level _ _ _ H0) as [_ <-]; apply ghost_of_approx.
(* Goal: @ex rmap (fun w1' : rmap => @ex rmap (fun w2' : rmap => and (@join rmap Join_rmap w1' w2' w') (and (hackfun w1 w1') (hackfun w2 w2')))) *)
 exists w1'; exists w2'; split3.
(* Goal: @join rmap Join_rmap w1' w2' w' *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
 apply resource_at_join2. destruct H; congruence. destruct H; congruence.
(* Goal: forall loc : AV.address, @join resource Join_resource (resource_at w1' loc) (resource_at w2' loc) (resource_at w' loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
 intro loc; apply (resource_at_join _ _ _ loc) in H0. destruct H3 as [-> _], H5 as [-> _].
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 destruct H. destruct H1 as [Hg H1], (H1 loc).
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 if_tac. apply H6 in H0. rewrite H0.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 if_tac.  apply H3 in H7. apply identity_core in H7.
(* Goal: @join resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)) (resource_at w' loc) (resource_at w' loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (if resource_identity_dec (resource_at w2 loc) then @core resource Join_resource Sep_resource (resource_at w' loc) else resource_at w2 loc) (resource_at w' loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
 rewrite <- H7 at 2. apply core_unit.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite H5 by auto. apply core_unit.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 spec H5. contradict H6; apply split_identity in H0; auto. rewrite <- H5.
(* Goal: @join resource Join_resource (resource_at w loc) (@core resource Join_resource Sep_resource (resource_at w loc)) (resource_at w loc) *)
(* Goal: @join resource Join_resource (resource_at w1 loc) (resource_at w2 loc) (resource_at w loc) *)
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
 if_tac. apply join_comm in H0. apply H7 in H0. rewrite H0. apply join_comm; apply core_unit.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 auto.
(* Goal: @join ghost ghost_join (ghost_of w1') (ghost_of w2') (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
 destruct H3 as [_ ->], H5 as [_ ->].
(* Goal: @join ghost ghost_join (ghost_of w1) (ghost_of w2) (ghost_of w') *)
(* Goal: hackfun w1 w1' *)
(* Goal: hackfun w2 w2' *)
 destruct H as (? & <- & _).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply ghost_of_join; auto.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 destruct H; split. apply join_level in H0; destruct H0; congruence.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H3 as [H3 ->]; split; auto.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 intro loc. rewrite H3. clear - H1. if_tac. pose (core_identity (w' @ loc)). intuition.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 intuition.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 destruct H; split. apply join_level in H0; destruct H0; congruence.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H5 as [H5 ->]; split; auto.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 intro loc. rewrite H5. clear - H1. if_tac. pose (core_identity (w' @ loc)). intuition.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 intuition.
Qed.

Lemma init_datalist_hack:
  forall b sh rho dl phi0 z,
   (init_data_list2pred dl sh (Vptr b z) rho) phi0 ->
  forall phi,
     hackfun phi0 phi ->
   readable_share sh ->
   (init_data_list2pred dl sh (Vptr b z) rho) phi.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  induction dl; intros. destruct H0 as [H0' [Hg H0]]. simpl in *.
  apply all_resource_at_identity. intro loc; destruct (H0 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply (resource_at_identity _ loc) in H. apply H2; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite <- Hg; apply ghost_of_identity; auto.

  rename H1 into H_READABLE.
 simpl init_data_list2pred in H|-*.
 destruct H as [w1 [w2 [? [? ?]]]].
 destruct (hackfun_sep _ _ _ _ H0 H) as [w1' [w2' [? [? ?]]]].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 exists w1'; exists w2'; split3; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 2: eapply IHdl; eauto.
 clear - H_READABLE H1 H4. destruct H4 as [H4' [Hg H4]].

  unfold init_data2pred in *;
  unfold mapsto, address_mapsto in *;
  destruct a; simpl in *;
  (destruct (readable_share_dec sh); [| tauto]);
  try
  (destruct H1 as [[H1' H1]|[H1x _]]; [|solve[inv H1x]];
        left; split;
    [ first [ apply I
           | apply sign_ext_range'; compute; split; congruence
           | apply zero_ext_range'; compute; split; congruence ]
    | simpl in H1 |- *;
      destruct H1 as [bl [[? H8] Hg']]; exists bl; split; [|rewrite <- Hg; auto]; split; [assumption | ]; intro loc; specialize (H8 loc);
      if_tac; [ destruct H8 as [p H8]; exists p; destruct (H4 loc) as [_ H5];
                rewrite <- H5; [rewrite H8; auto| rewrite H8; apply YES_not_identity]
              | destruct (H4 loc) as [HH _]; clear - H8 HH; intuition]]).
 rewrite address_mapsto_zeros_eq in H1|-*.
 rewrite nat_of_Z_max in *.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 split.  destruct H1; omega.
 destruct H1 as [H1' [H1 Hg1]]; split; [|simpl; rewrite <- Hg; auto].
 intro loc; specialize (H1 loc).
 assert (H99:  Z.max (Z.max z0 0) 0 = Z.max z0 0).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
   apply Z.max_l. apply Zmax_bound_r. omega.
 rewrite H99 in *.
 hnf in H1|-*.
 if_tac; [destruct H1 as [p H1]; exists p; hnf in H1|-*; rewrite <- H4'; destruct (H4 loc) as [_ H5]
          | destruct (H4 loc) as [HH _]; intuition].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite <- H5; auto. rewrite H1; apply YES_not_identity.

(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct (Map.get (ge_of rho) i); try destruct p; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H1 as [[H1' H1]|[H1' H1]];  [left|right]; split; auto.
 destruct H1 as [bl [[? H8] Hg1]].
 exists bl; split; [|simpl; rewrite <- Hg; auto]; split; [assumption | ]; intro loc; specialize (H8 loc).
 destruct (H4 loc).
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 hnf in H8|-*; if_tac. destruct H8 as [p H8]; exists p; hnf in H8|-*.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite <- H4'; rewrite <- H1; auto. rewrite H8; apply YES_not_identity.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 intuition.
 destruct H1 as [bl [? H8]].
 exists bl,x. destruct H8 as [[H8' H8] Hg1].
 split; [|simpl; rewrite <- Hg; auto].
 split; [assumption | ]; intro loc; specialize (H8 loc).
 destruct (H4 loc).
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 hnf in H8|-*; if_tac. destruct H8 as [p H8]; exists p; hnf in H8|-*.
  rewrite <- H4'. rewrite <- H0. rewrite H8. reflexivity.
 rewrite H8.
 apply YES_not_identity.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 intuition.
 unfold mapsto_ in *.
 unfold mapsto in *.
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
  simpl in *.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite if_true in H1|-* by auto.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 destruct H1. destruct H. contradiction. destruct H as [ _ ?].
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) *)
 right. split. hnf; auto.
 destruct H as [v2' ?]; exists v2'.
 destruct H as [x ?]; exists x.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H; split; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H; split; auto.
 intros loc; specialize (H1 loc).
 destruct (H4 loc).
 rename H1 into H8.
(* Goal: and (iff (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) (if @not_dec (fun b' : block => Coqlib.Plt b' b) (fun b' : block => plt b' b) (@fst block Z loc) then resource_at w' loc else @core resource Join_resource Sep_resource (resource_at w' loc))) *)
 hnf in H8|-*; if_tac. destruct H8 as [p H8]; exists p; hnf in H8|-*.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite <- H4'; rewrite <- H3; auto. rewrite H8; apply YES_not_identity.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 intuition.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 hnf in H0|-*. rewrite <- Hg; auto.
Qed.

Lemma another_hackfun_lemma:
 forall n i v gev m G phi m0,
    hackfun (inflate_initial_mem m (initial_core gev G n)) phi ->
    Genv.alloc_global gev m0 (i, Gvar v) = Some m ->
    hackfun (inflate_initial_mem m0 (initial_core gev G n))
      (upto_block (nextblock m0) phi).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros. destruct H; split.
 rewrite inflate_initial_mem_level in H|-*.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold upto_block. rewrite level_only_blocks. auto.
(* Goal: and (@eq ghost (ghost_of (inflate_initial_mem m0 (@initial_world.initial_core function gev G n))) (ghost_of (upto_block (nextblock m0) phi))) (forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)) (@identity resource Join_resource (resource_at (upto_block (nextblock m0) phi) loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc) (resource_at (upto_block (nextblock m0) phi) loc))) *)
 clear H; rename H1 into H.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 destruct H as [Hg H]; split.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 { unfold upto_block, only_blocks, inflate_initial_mem in *; rewrite !ghost_of_make_rmap in *; auto. }
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)) (@identity resource Join_resource (resource_at (upto_block (nextblock m0) phi) loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc) (resource_at (upto_block (nextblock m0) phi) loc)) *)
 intro loc; specialize (H loc).
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct (plt (fst loc) (nextblock m0)).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold upto_block. rewrite only_blocks_at. rewrite if_true by auto.
 replace (inflate_initial_mem m0 (initial_core gev G n) @ loc)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   with (inflate_initial_mem m (initial_core gev G n) @ loc); auto.
 try rename p into z.   (* Coq 8.3/8.4 compatibility *)
(* Goal: @eq resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev G n)) loc) (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)) (@identity resource Join_resource (resource_at (upto_block (nextblock m0) phi) loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc) (resource_at (upto_block (nextblock m0) phi) loc)) *)
 clear - z H0.
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
 unfold inflate_initial_mem; repeat rewrite resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
 unfold inflate_initial_mem'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct (alloc_global_old _ _ _ _ H0 _ z) as [? ?]. rewrite H; rewrite H1; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold upto_block. rewrite only_blocks_at. rewrite if_false by auto.
 unfold inflate_initial_mem; repeat rewrite resource_at_make_rmap;
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
   unfold inflate_initial_mem'.
(* Goal: and (iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end), @eq resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
 replace (access_at m0 loc Cur) with (@None permission).
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
 clear.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 pose proof (core_identity (phi @ loc)).
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
 assert (identity (NO Share.bot bot_unreadable)) by apply NO_identity.
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
 intuition.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 symmetry; apply nextblock_noaccess. auto.
Qed.

Lemma hackfun_beyond_block:
  forall b w w', hackfun w w' -> hackfun (beyond_block b w) (beyond_block b w').
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros. destruct H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 split. unfold beyond_block. repeat rewrite level_only_blocks. auto.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
 clear H. destruct H0 as [Hg H0]; split.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 { unfold beyond_block, only_blocks; rewrite !ghost_of_make_rmap; auto. }
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at (beyond_block b w) loc)) (@identity resource Join_resource (resource_at (beyond_block b w') loc))) (forall _ : not (@identity resource Join_resource (resource_at (beyond_block b w) loc)), @eq resource (resource_at (beyond_block b w) loc) (resource_at (beyond_block b w') loc)) *)
 intro loc; specialize (H0 loc).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 unfold beyond_block. repeat  rewrite only_blocks_at. if_tac. auto.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
 clear. pose proof (core_identity (w @ loc)); pose proof (core_identity (w' @ loc)); intuition.
Qed.

Lemma Pos_to_nat_eq_S:
  forall b, Pos.to_nat b = S (nat_of_Z (Z.pos b) - 1).
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
Proof. intros. simpl; pose proof (Pos2Nat.is_pos b); omega.
Qed.


Lemma alloc_global_inflate_initial_eq:
  forall gev m0 i f m G n loc,
      Genv.alloc_global gev m0 (i, Gfun f) = Some m ->
   ~ identity (inflate_initial_mem m0 (initial_core gev G n) @ loc) ->
     inflate_initial_mem m0 (initial_core gev G n) @ loc =
      inflate_initial_mem m (initial_core gev G n) @ loc.
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros. rename H0 into H9.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold inflate_initial_mem. simpl. rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
unfold inflate_initial_mem'.
(* Goal: @eq resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
destruct loc.
(* Goal: @eq resource match access_at m0 (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end match access_at m (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end *)
destruct (plt b (nextblock m0)).
*
(* Goal: @eq resource match access_at m0 (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end match access_at m (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end *)
destruct (alloc_global_old gev _ _ _ H (b,z) p) as [? ?].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite H0,H1. auto.
*
(* Goal: False *)
contradiction H9; clear H9.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold inflate_initial_mem. simpl. rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
unfold inflate_initial_mem'.
unfold access_at; rewrite nextblock_noaccess.
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
apply NO_identity.
(* Goal: not (Coqlib.Plt (@fst block Z (@pair block Z b z)) (nextblock m0)) *)
apply n0.
Qed.

(*
 Lemma alloc_global_inflate_identity_iff:
  forall gev m0 i f m G n loc,
      Genv.alloc_global gev m0 (i, Gfun f) = Some m ->
     (identity (inflate_initial_mem m0 (initial_core gev G n) @ loc) <->
      identity (inflate_initial_mem m (initial_core gev G n) @ loc)).
Proof.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
intros.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold inflate_initial_mem. simpl. rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
unfold inflate_initial_mem'.
(* Goal: @eq resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
destruct loc.
(* Goal: @eq resource match access_at m0 (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end match access_at m (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end *)
destruct (plt b (nextblock m0)).
*
destruct (alloc_global_old gev _ _ _ H (b,z) p) as [? [? ?]].
(* Goal: and (iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at phi loc)))) (forall _ : not (@identity resource Join_resource (NO Share.bot bot_unreadable)), @eq resource (NO Share.bot bot_unreadable) (@core resource Join_resource Sep_resource (resource_at phi loc))) *)
(* Goal: @eq (option permission) (@None permission) (access_at m0 loc Cur) *)
rewrite H0,H2. intuition.
*
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
unfold access_at at 1. rewrite nextblock_noaccess by auto.
split; [ intros _ | intro; apply NO_identity].
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
unfold Genv.alloc_global in H.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
destruct (alloc m0 0 1) eqn:?.
destruct (peq b (nextblock m0)).
+
(* Goal: @identity resource Join_resource match access_at m0 (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
subst b. clear n0.
unfold drop_perm in H.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
destruct (range_perm_dec m1 b0 0 1 Cur Freeable); inv H.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold access_at; simpl.
pose proof (alloc_result _ _ _ _ _ Heqp). subst b0.
(* Goal: @eq (forall _ : perm_kind, option permission) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (mem_access m0) z k) (fun k : perm_kind => @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) b (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (k0 : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Nonempty else @PMap.get (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs0 : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs0) (Z.gt Z0 ofs0) (zle Z0 ofs0)) (@proj_sumbool (Z.lt ofs0 (Zpos xH)) (Z.ge ofs0 (Zpos xH)) (zlt ofs0 (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) ofs k0) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0))) z k) *)
(* Goal: @eq resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev GG n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite PMap.gss.
(* Goal: @identity resource Join_resource match access_at m0 (@pair block Z (nextblock m0) z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z (nextblock m0) z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z (nextblock m0) z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z (nextblock m0) z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z (nextblock m0) z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z (nextblock m0) z) end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
destruct (zeq z 0). subst z.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
destruct (zle 0 0); try omega. destruct (zlt 0 1); try omega.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl.
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
destruct (initial_core gev G n @ (nextblock m0, 0)); try apply NO_identity.
(* Goal: @identity resource Join_resource (PURE (FUN f0 c) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1)))) *)
(* Goal: @In (prod ident funspec) (@pair ident funspec i fd) (@app (prod ident funspec) G0 G) *)
apply PURE_identity.
replace (if zle 0 z && zlt z 1
     then Some Nonempty
     else (mem_access m1) !! (nextblock m0) z Cur)
with ((mem_access m1) !! (nextblock m0) z Cur)
  by (destruct (zle 0 z); destruct (zlt z 1); try omega; auto).
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
destruct ((mem_access m1) !! (nextblock m0) z Cur) eqn:?; try apply NO_identity.
elimtype False.
pose proof (perm_alloc_3 _ _ _ _ _ Heqp z Cur) p.
spec H; [ | omega].
unfold perm.
(* Goal: match_fdecs (@nil (prod ident fundef)) (@nil (prod ident funspec)) *)
rewrite Heqo. constructor.
+
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
unfold access_at.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
simpl.
rewrite nextblock_noaccess.  apply NO_identity.
apply nextblock_drop in H. rewrite H in *. clear H.
apply nextblock_alloc in Heqp. rewrite Heqp in *; clear Heqp.
contradict n0.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
apply Plt_succ_inv in n0; destruct n0; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
subst. contradiction n1; auto.
Qed.
*)

 Lemma alloc_global_identity_lemma3:
   forall gev m0 i f m G n loc,
    Genv.alloc_global gev m0 (i, Gfun f) = Some m ->
    identity (inflate_initial_mem m (initial_core gev G n) @ loc) ->
    identity (inflate_initial_mem m0 (initial_core gev G n) @ loc).
Proof.
(* Goal: forall (gev : Genv.t (Ctypes.fundef function) type) (m0 : mem) (i : ident) (f : Ctypes.fundef function) (m : mem) (G : funspecs) (n : nat) (loc : AV.address) (_ : @eq (option mem) (@Genv.alloc_global (Ctypes.fundef function) type gev m0 (@pair ident (globdef (Ctypes.fundef function) type) i (@Gfun (Ctypes.fundef function) type f))) (@Some mem m)) (_ : @identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev G n)) loc)), @identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev G n)) loc) *)
intros until 1.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold inflate_initial_mem. simpl. rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
unfold inflate_initial_mem'.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 intros.
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (adr_range_dec (nextblock m0, 0) 1 loc).
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
  destruct loc; destruct a. subst b. assert (z=0) by omega. subst z.
  unfold access_at; rewrite nextblock_noaccess. apply NO_identity.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl. apply Plt_strict.
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (plt (fst loc) (nextblock m0)).
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  destruct (alloc_global_old _ _ _ _ H _ p) as [? ?].
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite H1,H2. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold access_at. rewrite nextblock_noaccess by auto.
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
  apply NO_identity.
Qed.

Lemma identity_inflate_at_Gfun:
  forall n i f gev m G0 G loc m0,
 list_norepet (map fst (G0 ++ G)) ->
 Genv.find_symbol gev i = Some (nextblock m0) ->
 Genv.alloc_global gev m0 (i, Gfun f) = Some m ->
 In i (map fst G) ->
 (identity (inflate_initial_mem m0 (initial_core gev (G0 ++ G) n) @ loc) <->
 identity (inflate_initial_mem m (initial_core gev (G0 ++ G) n) @ loc)).
Proof.
(* Goal: forall (n : nat) (i : ident) (f : Ctypes.fundef function) (gev : Genv.t (Ctypes.fundef function) type) (m : mem) (G0 G : list (prod ident funspec)) (loc : AV.address) (m0 : mem') (_ : @list_norepet ident (@map (prod ident funspec) ident (@fst ident funspec) (@app (prod ident funspec) G0 G))) (_ : @eq (option block) (@Genv.find_symbol (Ctypes.fundef function) type gev i) (@Some block (nextblock m0))) (_ : @eq (option mem) (@Genv.alloc_global (Ctypes.fundef function) type gev m0 (@pair ident (globdef (Ctypes.fundef function) type) i (@Gfun (Ctypes.fundef function) type f))) (@Some mem m)) (_ : @In ident i (@map (prod ident funspec) ident (@fst ident funspec) G)), iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
intros until m0. intros NR H8 ? ?.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
destruct (eq_dec loc (nextblock m0, 0)).
*
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
subst loc.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
unfold initial_core.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))))) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))))) loc)) *)
unfold inflate_initial_mem.
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) *)
rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
unfold inflate_initial_mem'.
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) *)
rewrite !resource_at_make_rmap.
rewrite nextblock_access_empty
  by (apply Pos2Nat.inj_ge; omega).
(* Goal: iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource match access_at m (@pair block Z b ofs) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) end | None => NO Share.bot bot_unreadable end) *)
split; intros _; [ |apply NO_identity].
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
unfold Genv.alloc_global in H.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
destruct (alloc m0 0 1) eqn:?.
(* Goal: @identity resource Join_resource match access_at m (@pair block Z (nextblock m0) Z0) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end | None => NO Share.bot bot_unreadable end *)
assert (H9: 0 <= 0 < 1) by (clear; omega).
(* Goal: @identity resource Join_resource match access_at m0 (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
assert (H6 := alloc_result _ _ _ _ _ Heqp); subst b.
(* Goal: @identity resource Join_resource match access_at m (@pair block Z (nextblock m0) Z0) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end | None => NO Share.bot bot_unreadable end *)
assert (H1 := perm_drop_1 _ _ _ _ _ _ H 0 Cur H9).
(* Goal: @identity resource Join_resource match access_at m (@pair block Z (nextblock m0) Z0) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end | None => NO Share.bot bot_unreadable end *)
destruct (perm_mem_access _ _ _ _ H1) as [p [H4 H5]].
(* Goal: @identity resource Join_resource match access_at m (@pair block Z (nextblock m0) Z0) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end | None => NO Share.bot bot_unreadable end *)
assert (H2 := perm_drop_2 _ _ _ _ _ _ H 0 Cur p H9).
(* Goal: @identity resource Join_resource match access_at m (@pair block Z (nextblock m0) Z0) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end | None => NO Share.bot bot_unreadable end *)
rewrite H5.
unfold perm in *.
(* Goal: @identity resource Join_resource match p with | Freeable => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Readable => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Nonempty => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end end *)
unfold access_at in H5. simpl in H5. destruct ((mem_access m) !! (nextblock m0) 0 Cur); inv H5.
(* Goal: @identity resource Join_resource match p with | Freeable => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Readable => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Nonempty => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end end *)
spec H2; [constructor | ].
(* Goal: @identity resource Join_resource match p with | Freeable => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Readable => YES Ers readable_Ers (VAL (contents_at m (@pair block Z (nextblock m0) Z0))) NoneP | Nonempty => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z (nextblock m0) Z0) end end *)
destruct p; try solve [inv H2].
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
unfold initial_core'. simpl.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite Genv.find_invert_symbol with (id:=i) by auto.
(* Goal: @identity resource Join_resource match match find_id i (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1))) | None => NO Share.bot bot_unreadable end with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => match find_id i (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1))) | None => NO Share.bot bot_unreadable end end *)
destruct (list_in_map_inv _ _ _ H0) as [[i' fd] [H10 H11]]; simpl in H10, H11.
(* Goal: @identity resource Join_resource match match find_id i (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1))) | None => NO Share.bot bot_unreadable end with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => match find_id i (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1))) | None => NO Share.bot bot_unreadable end end *)
subst i'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite find_id_i with (fs:=fd); auto.
(* Goal: @identity resource Join_resource match match fd with | mk_funspec fsig cc A P Q P_ne Q_ne => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1))) end with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => match fd with | mk_funspec fsig cc A P Q P_ne Q_ne => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1))) end end *)
(* Goal: @In (prod ident funspec) (@pair ident funspec i fd) (@app (prod ident funspec) G0 G) *)
destruct fd.
(* Goal: @identity resource Join_resource (PURE (FUN f0 c) (SomeP (SpecTT A) (fun (ts : list Type) (a : _functor (dependent_type_functor_rec ts A) (@pred rmap ag_rmap)) (a0 : bool) (a1 : environ) => approx n (@packPQ A P Q ts (@fmap (dependent_type_functor_rec ts A) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) a) a0 a1)))) *)
(* Goal: @In (prod ident funspec) (@pair ident funspec i fd) (@app (prod ident funspec) G0 G) *)
apply PURE_identity.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
apply in_app. right; auto.
*
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
clear NR.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@initial_world.initial_core function gev (@app (prod ident funspec) G0 G) n)) loc)) *)
unfold initial_core.
(* Goal: iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))))) loc)) (@identity resource Join_resource (resource_at (inflate_initial_mem m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))))) loc)) *)
unfold inflate_initial_mem.
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) *)
rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource (inflate_initial_mem' m0 (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) (@identity resource Join_resource (inflate_initial_mem' m (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc)) *)
unfold inflate_initial_mem'.
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@proj1_sig rmap (fun phi : rmap => and (@eq nat (@level rmap ag_rmap phi) n) (and (@eq (forall _ : AV.address, resource) (resource_at phi) (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n)) (@eq ghost (ghost_of phi) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds)))))) (make_rmap (@initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))) n (initial_world.initial_core_obligation_1 function gev (@app (prod ident funspec) G0 G) n) (@eq_refl ghost (ghost_fmap (approx n) (approx n) (@nil (option (prod (@sigT ghost.Ghost (fun g : ghost.Ghost => @sig (@ghost.G g) (fun a : @ghost.G g => @ghost.valid g a))) preds))))))) loc end | None => NO Share.bot bot_unreadable end) *)
rewrite !resource_at_make_rmap.
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) *)
pose proof (Pos.ltb_spec (fst loc) (nextblock m0)).
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) *)
destruct ((fst loc <? nextblock m0)%positive); inv H1.
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) *)
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) *)
destruct (alloc_global_old _ _ _ _ H loc H2) as [? ?].
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) *)
(* Goal: iff (@identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n loc end | None => NO Share.bot bot_unreadable end) *)
rewrite H3.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
rewrite H1; split; intro; auto.
destruct loc as [b ofs]. simpl fst in *; simpl snd in *.
(* Goal: iff (@identity resource Join_resource match access_at m0 (@pair block Z b ofs) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b ofs))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b ofs))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b ofs))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) end | None => NO Share.bot bot_unreadable end) (@identity resource Join_resource match access_at m (@pair block Z b ofs) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) end | None => NO Share.bot bot_unreadable end) *)
rewrite (nextblock_access_empty m0) by (apply Pos.le_ge; auto).
(* Goal: iff (@identity resource Join_resource (NO Share.bot bot_unreadable)) (@identity resource Join_resource match access_at m (@pair block Z b ofs) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) end | None => NO Share.bot bot_unreadable end) *)
split; intros _; [ |apply NO_identity].
(* Goal: @identity resource Join_resource match access_at m (@pair block Z b ofs) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m (@pair block Z b ofs))) NoneP | Some (Nonempty as p) => match @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => @initial_world.initial_core' function gev (@app (prod ident funspec) G0 G) n (@pair block Z b ofs) end | None => NO Share.bot bot_unreadable end *)
replace (access_at m (b,ofs) Cur) with (@None permission).
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
apply NO_identity.
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
symmetry.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
unfold Genv.alloc_global in H.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
destruct (alloc m0 0 1) eqn:?.
assert (H6 := alloc_result _ _ _ _ _ Heqp); subst b0.
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
clear - n0 H2 Heqp H.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
assert (b <> nextblock m0 \/ ofs <> 0). {
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  destruct (eq_block b (nextblock m0)). subst. right. congruence. left; auto.
}
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
rewrite <- (access_drop_3 _ _ _ _ _ _ H) by (destruct H0; auto; right; omega).
(* Goal: @eq (option permission) (access_at m1 (@pair block Z b ofs) Cur) (@None permission) *)
rewrite <- (alloc_access_other _ _ _ _ _ Heqp)by (destruct H0; auto; right; omega).
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
apply nextblock_access_empty. zify; omega.
Qed.

Lemma global_initializers:
  forall (prog: program) G m n rho,
     list_norepet (prog_defs_names prog) ->
     all_initializers_aligned prog ->
    match_fdecs (prog_funct prog) G ->
    ge_of rho = filter_genv (globalenv prog) ->
    Genv.init_mem prog = Some m ->
     app_pred (globvars2pred (globals_of_env rho) (prog_vars prog) rho)
  (inflate_initial_mem m (initial_core (Genv.globalenv prog) G n)).
Proof.
  intros until rho. intros ? AL SAME_IDS RHO ?.
  unfold all_initializers_aligned in AL.
  unfold Genv.init_mem in H0.
  unfold globalenv, Genv.globalenv in *.
  unfold prog_vars, prog_funct in *.
  change (prog_defs prog) with (AST.prog_defs prog) in AL, SAME_IDS |- *.
  destruct (program_of_program prog) as [fl prog_pub main].
  forget (prog_comp_env prog) as cenv.
  clear prog.
  simpl in *|-. simpl prog_vars'. simpl initial_core.
  match goal with |- context [initial_core ?A] =>
     remember A as gev end.
  rewrite <- (rev_involutive fl) in *.
  rewrite alloc_globals_rev_eq in H0.
  forget (rev fl) as vl'. clear fl; rename vl' into vl.
  unfold prog_defs_names in H. simpl in  H.

  rewrite <- rev_prog_vars' in AL|-*.
  rewrite <- rev_prog_funct' in SAME_IDS.
  rewrite globvars2pred_rev.
  rewrite forallb_rev in AL.
  rewrite <- (rev_involutive G) in  SAME_IDS.
  rewrite match_fdecs_rev in SAME_IDS.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  2:{
    apply list_norepet_prog_funct'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    rewrite <- list_norepet_rev, <- map_rev; auto.
  }
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  rewrite initial_core_rev with (vl:=vl) by auto.
  rewrite map_rev in H. rewrite list_norepet_rev in H.
  forget (rev G) as G'; clear G; rename G' into G.
  rename H into H2.
  assert (H :=add_globals_hack _ _ prog_pub H2 Heqgev).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  assert (H1: forall j, In j (map (@fst _ _) G) -> ~ In j (map (@fst _ _) (prog_vars' vl))). {
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    intros.
    pose proof (match_fdecs_in j _ _ H1 SAME_IDS).
    clear - H3 H2.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
    intro.
(* Goal: False *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
    induction vl. inv H.
    inv H2. specialize (IHvl H5).
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents (mkmem (@PMap.set (prod memval (PTree.t memval)) (nextblock m0) (@ZMap.init memval Undef) (mem_contents m0)) (@PMap.set (forall (_ : Z) (_ : perm_kind), option permission) (nextblock m0) (fun (ofs : Z) (_ : perm_kind) => if andb (@proj_sumbool (Z.le Z0 ofs) (Z.gt Z0 ofs) (zle Z0 ofs)) (@proj_sumbool (Z.lt ofs (Zpos xH)) (Z.ge ofs (Zpos xH)) (zlt ofs (Zpos xH))) then @Some permission Freeable else @None permission) (mem_access m0)) (Pos.succ (nextblock m0)) (fun (b : positive) (ofs : Z) => Memory.Mem.alloc_obligation_1 m0 Z0 (Zpos xH) b ofs) (fun (b : positive) (ofs : Z) (k : perm_kind) (H : not (Coqlib.Plt b (Pos.succ (nextblock m0)))) => Memory.Mem.alloc_obligation_2 m0 Z0 (Zpos xH) b ofs k H) (fun b : positive => Memory.Mem.alloc_obligation_3 m0 b)))))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (nextblock m0) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
(* Goal: @eq resource match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m1)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end match p with | Freeable => YES Share.top readable_share_top (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Writable => YES Ews (@writable_readable Ews writable_Ews) (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Readable => YES Ers readable_Ers (VAL (@ZMap.get memval (@snd block Z loc) (@PMap.get (ZMap.t memval) (@fst block Z loc) (mem_contents m0)))) NoneP | Nonempty => match resource_at (@initial_world.initial_core function gev GG n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => resource_at (@initial_world.initial_core function gev GG n) loc end end *)
    destruct a as [i [a|a]]; simpl in *.
(* Goal: @In ident j (@map (prod ident fundef) ident (@fst ident fundef) vl') *)
(* Goal: @eq ident j j *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
    destruct H3. subst j.
    clear - H H4.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply H4; clear H4. induction vl; simpl in *; auto.
    destruct a as [i' [a|a]]; auto .
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    destruct H. simpl in *; subst; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    right; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply IHvl; auto.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
    destruct H; subst.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply H4; clear - H3. induction vl; simpl in *; auto.
    destruct a as [i' [a|a]]; auto .
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    destruct H3. simpl in *; subst; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    right; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply IHvl; auto.
  }
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  assert (H1': forall j, In j (map fst (prog_funct' vl)) -> In j (map fst G)). {
   clear - SAME_IDS.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
   forget (prog_funct' vl) as fs. intro.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
   induction SAME_IDS. auto. simpl. intuition.
  }
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  assert (NRG: list_norepet (map fst G)). {
     clear - SAME_IDS H2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
     eapply match_fdecs_norepet; eauto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
     apply list_norepet_prog_funct'; auto.
  }
  clear SAME_IDS Heqgev.
  change (map fst vl) with (map fst (@nil (ident*funspec)) ++ map fst vl) in H2.
  change G with (nil++G).
  set (G0 := @nil (ident*funspec)) in *.
  change G with (G0++G) in NRG.
  clearbody G0.
  move H2 after H. move H1 after H.

  assert (H3: forall phi, hackfun (inflate_initial_mem m (initial_core gev (G0++G) n)) phi ->
           (globvars2pred (globals_of_env rho) (prog_vars' vl) rho) phi).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  2:{
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
    apply H3. clear.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    split. auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    split; auto.
(* Goal: forall loc : AV.address, and (iff (@identity resource Join_resource (resource_at w2 loc)) (@identity resource Join_resource (resource_at w2' loc))) (forall _ : not (@identity resource Join_resource (resource_at w2 loc)), @eq resource (resource_at w2 loc) (resource_at w2' loc)) *)
    intro loc. intuition.
  }
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  intros. rename H3 into HACK; revert phi HACK.
                     (* The purpose of going through hackfun is doing this induction. *)
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert H m G0 G NRG H2 H0 H1 H1'; induction vl; intros.
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) *)
  + split. hnf; auto. apply resource_at_empty2.
    intro l. do 2 apply proj2 in HACK; specialize (HACK l).
    unfold inflate_initial_mem in HACK|-*.
    rewrite resource_at_make_rmap in *.
    unfold inflate_initial_mem' in HACK|-*.
    inversion H0; clear H0; subst m.
    unfold access_at, empty in HACK; simpl in HACK; rewrite PMap.gi in HACK.
(* Goal: @identity resource Join_resource (NO Share.bot bot_unreadable) *)
(* Goal: @eq (option permission) (@None permission) (access_at m (@pair block Z b ofs) Cur) *)
      destruct HACK as [HACK _]. rewrite <- HACK. apply NO_identity.
    destruct HACK as (? & <- & _).
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
    unfold inflate_initial_mem, initial_core; rewrite !ghost_of_make_rmap.
    rewrite <- (ghost_core nil); apply core_identity.
  + simpl in H0.
(* Goal: not (@eq Z ofs Z0) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
    revert H0; case_eq (alloc_globals_rev gev empty vl); intros; try congruence.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    spec IHvl. clear - AL. simpl in AL. destruct a. destruct g; auto. simpl in AL.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
      apply andb_true_iff in AL; destruct AL; auto.
     spec IHvl; [ intros | ].
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
    assert (H4': (Pos.to_nat b <= length vl)%nat). {
    clear - H4. rewrite Zlength_correct in H4.
      rewrite <- Z2Nat.inj_pos.
       rewrite <- Nat2Z.id .
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
       apply Z2Nat.inj_le. specialize (Pos2Z.is_pos b). omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
       omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
       omega.
     }
 fold fundef in *.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 assert (POS := Pos2Z.is_pos b). {
 rewrite H.
 rewrite Pos_to_nat_eq_S.
 replace (length vl - (nat_of_Z (Z.pos b) - 1))%nat with (S (length vl - S (nat_of_Z (Z.pos b) - 1)))%nat
  by (simpl;  pose proof (Pos2Nat.is_pos b); omega).
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 simpl.
  replace (Datatypes.length vl - (Pos.to_nat b - 1))%nat with
             (S (Datatypes.length vl - S (Pos.to_nat b - 1)))%nat.
 apply iff_refl.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 clear - H4'; pose proof (Pos2Nat.is_pos b); omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite Zlength_cons. omega.
 }
(* Goal: @ex funspec (fun fs' : funspec => @eq (option funspec) (let (id', f) := a in if @eq_dec ident EqDec_ident i id' then @Some funspec f else find_id i (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G))) (@Some funspec fs')) *)
(* Goal: and (iff (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)) (@identity resource Join_resource (resource_at phi loc))) (forall _ : not (@identity resource Join_resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc)), @eq resource (resource_at (inflate_initial_mem m0 (@initial_world.initial_core function gev (@app (prod ident funspec) G0 (@cons (prod ident funspec) (@pair ident funspec i fs) G)) n)) loc) (resource_at phi loc)) *)
 destruct a.
 assert (FS: Genv.find_symbol gev i = Some (nextblock m0)).
  assert (Genv.find_symbol gev i = Some (nextblock m0)).
    apply H. apply alloc_globals_rev_nextblock in H0. rewrite H0 .
      rewrite Zlength_cons.
 rewrite Z2Pos.id.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite Zlength_correct. omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite Zlength_correct. omega.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 simpl.
   apply alloc_globals_rev_nextblock in H0. rewrite H0 .
  replace (Pos.to_nat (Z.to_pos (Z.succ (Zlength vl))))
    with (S (length vl)).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
2:{
rewrite Pos_to_nat_eq_S.
 rewrite Zlength_correct.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  rewrite Z2Pos.id by omega.
 unfold nat_of_Z.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite Z2Nat.inj_succ by omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
 rewrite Nat2Z.id. omega.
}
(* Goal: @eq Z (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
 rewrite Nat.sub_diag. reflexivity.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  auto.
(* Goal: or (@eq ident (@fst ident (globdef fundef type) (@pair ident (globdef fundef type) i0 g)) i) (@In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl)) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
  destruct g.
* (* Gfun case *)
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
  simpl.
  specialize (IHvl m0 (G0(*++(p::nil)*)) G).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply IHvl; auto.
(* Goal: @In ident i (@map (prod ident (globdef fundef type)) ident (@fst ident (globdef fundef type)) vl) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
 - clear - H2. apply list_norepet_app in H2. destruct H2 as [? [? ?]].
(* Goal: not (@In ident i (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl))) *)
(* Goal: @list_norepet ident (@map (prod ident fundef) ident (@fst ident fundef) (@prog_funct' fundef type vl)) *)
(* Goal: @eq (option funspec) (find_id i (@rev (prod ident funspec) G)) (find_id i G) *)
    inv H0.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply list_norepet_app; split3; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply list_disjoint_cons_right in H1; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 - clear - H1'; intros; apply H1'. right; auto.
 -
  clear - NRG H2 FS HACK H3 H1'.
  specialize (H1' i). simpl in H1'. spec H1'; [auto | ].
  destruct HACK as [? ? ].
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
  split. rewrite <- H.
(* Goal: @eq nat (@level rmap ag_rmap (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (@level rmap ag_rmap phi) *)
(* Goal: forall loc : AV.address, @join resource Join_resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0)) (fun loc0 : AV.address => if @not_dec S S_dec (@fst block Z loc0) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) (if s then resource_at phi loc0 else @core resource Join_resource Sep_resource (resource_at phi loc0))) then resource_at_approx phi loc0 else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc0)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc0) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc0)) (core_resource_at phi loc0))) (ghost_of_approx phi))) loc) (resource_at phi loc) *)
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
  unfold inflate_initial_mem. repeat rewrite level_make_rmap. auto.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
  destruct H0 as [Hg H0]; split.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  unfold inflate_initial_mem in *; rewrite ghost_of_make_rmap in *; auto.
  intro; specialize (H0 loc).
(* Goal: or (@In ident j (@map (prod ident fundef) ident (@fst ident fundef) (@rev (prod ident fundef) vl))) (@In ident j (@cons ident i (@nil ident))) *)
(* Goal: @In ident j (@map (prod ident fundef) ident (@fst ident fundef) vl') *)
(* Goal: @eq ident j j *)
(* Goal: match_fdecs vl G0 *)
(* Goal: match_fdecs (@cons (prod ident fundef) (@pair ident fundef i f) vl') (@cons (prod ident funspec) (@pair ident funspec i fspec) G') *)
  destruct H0.
  clear - NRG H2 FS H0 H1 H3 H1'.
(* Goal: hackfun (beyond_block b w) (beyond_block b w') *)
  split.
  rewrite <- H0.
  clear - NRG H2 FS H3 H1'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply (identity_inflate_at_Gfun n i f); auto.
(* Goal: not (@identity resource Join_resource (NO sh n)) *)
(* Goal: sumbool (@identity resource Join_resource (YES sh r k p)) (not (@identity resource Join_resource (YES sh r k p))) *)
(* Goal: sumbool (@identity resource Join_resource (PURE k p)) (not (@identity resource Join_resource (PURE k p))) *)
  intro.
  rewrite <- H1.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  eapply alloc_global_inflate_initial_eq; eauto.
  clear - H3 H.
  contradict H.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  eapply alloc_global_identity_lemma3; eauto.
* (* Gvar case *)
  specialize (IHvl m0 G0 G NRG).
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  spec IHvl. { clear - H2. apply list_norepet_app.  apply list_norepet_app in H2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
      destruct H2 as [? [? ?]].  inv H0.  split3; auto. simpl in H1.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
    apply list_disjoint_cons_right in H1; auto.
  }
  specialize (IHvl H0).
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 spec IHvl. intros. clear - H1 H4. specialize (H1 _ H4). contradict H1.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  right; auto.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  assert (FI: find_id i (G0++G) = None). {
  change (list_norepet (map fst G0 ++ (i::nil) ++ (map fst vl))) in H2.
  apply list_norepet_append_commut in H2. rewrite app_ass in H2.
 inv H2. specialize (H1 i).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 case_eq (find_id i (G0++G)); intros; auto. apply find_id_e in H2.
(* Goal: @In (prod ident funspec) (@pair ident funspec i fd) (@app (prod ident funspec) G0 G) *)
 contradiction H6. apply in_app. apply in_app_or in H2.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 destruct H2; [right|left].  change i with (fst (i,f)); apply in_map; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 contradiction H1. apply in_map_fst in H2. auto.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
 left; auto.
 }
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) *)
  split. hnf; auto.
(* Goal: or (not (@eq block (nextblock m0) (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  simpl map.  simpl fold_right.
  assert (identity (ghost_of phi)) as Hg.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  { destruct HACK as (? & <- & _).
(* Goal: @join ghost ghost_join (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if @not_dec S S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi)))) (ghost_of phi) *)
    unfold inflate_initial_mem, initial_core; rewrite !ghost_of_make_rmap.
    rewrite <- (ghost_core nil); apply core_identity. }
  pose proof (join_comm (join_upto_beyond_block (nextblock m0) phi Hg)).
  do 2 econstructor; split3; [ eassumption | |].
  unfold globvar2pred.
  unfold globals_of_env.
  rewrite RHO. unfold filter_genv, Map.get. simpl @fst; simpl @snd.
  assert (JJ:= alloc_global_inflate_same n i v _ _ (G0++G) _ H3).
 spec JJ.
(* Goal: @eq resource (resource_at (@proj1_sig rmap (fun phi0 : rmap => and (@eq nat (@level rmap ag_rmap phi0) (@level rmap ag_rmap phi)) (and (@eq (forall _ : AV.address, resource) (resource_at phi0) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (@eq ghost (ghost_of phi0) (ghost_of phi)))) (make_rmap (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (ghost_of phi) (@level rmap ag_rmap phi) (@functional_extensionality AV.address resource (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) (fun loc : AV.address => if S_dec (@fst block Z loc) as s return (@eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) (if s then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc))) then resource_at_approx phi loc else @eq_ind_r resource (resource_at (@core rmap Join_rmap Sep_rmap phi) loc) (fun r : resource => @eq resource (resource_fmap (approx (@level rmap ag_rmap phi)) (approx (@level rmap ag_rmap phi)) r) r) (@eq_ind nat (@level rmap ag_rmap (@core rmap Join_rmap Sep_rmap phi)) (fun n : nat => @eq resource (resource_fmap (approx n) (approx n) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at (@core rmap Join_rmap Sep_rmap phi) loc)) (resource_at_approx (@core rmap Join_rmap Sep_rmap phi) loc) (@level rmap ag_rmap phi) (@level_core rmap Join_rmap Perm_rmap Sep_rmap ag_rmap Age_rmap phi)) (@core resource Join_resource Sep_resource (resource_at phi loc)) (core_resource_at phi loc))) (ghost_of_approx phi))) loc) (if S_dec (@fst block Z loc) then resource_at phi loc else @core resource Join_resource Sep_resource (resource_at phi loc)) *)
 intro. unfold initial_core. rewrite resource_at_make_rmap. unfold initial_core'.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  simpl. if_tac; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 rewrite Genv.find_invert_symbol with (id:=i); auto. rewrite FI; auto.
 simpl genv_genv.
(* Goal: @identity resource Join_resource match (if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p => NO extern_retainer nonreadable_extern_retainer | PURE k p => if Z.eq_dec (@snd block Z (@pair block Z (nextblock m0) Z0)) Z0 then match @Genv.invert_symbol (Ctypes.fundef function) type gev (@fst block Z (@pair block Z (nextblock m0) Z0)) with | Some id => match find_id id (@app (prod ident funspec) G0 G) with | Some (mk_funspec fsig cc A P Q P_ne Q_ne as f) => PURE (FUN fsig cc) (SomeP (SpecTT A) (fun ts : list Type => @fmap (dependent_type_functor_rec ts (SpecTT A)) (@pred rmap ag_rmap) (@pred rmap ag_rmap) (approx n) (approx n) (@packPQ A P Q ts))) | None => NO Share.bot bot_unreadable end | None => NO Share.bot bot_unreadable end else NO Share.bot bot_unreadable end *)
 fold fundef in *. simpl.
 rewrite FS.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 assert (H99: exists t, match type_of_global {| genv_genv := gev; genv_cenv := cenv |} (nextblock m0) with
  | Some t => Some (Vptr (nextblock m0) Ptrofs.zero, t)
  | None => Some (Vptr (nextblock m0) Ptrofs.zero, Tvoid)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
  end = Some (Vptr (nextblock m0) Ptrofs.zero, t)) by (destruct (type_of_global {| genv_genv := gev; genv_cenv := cenv |} (nextblock m0)); eauto).
(* destruct H99 as [t H99]; rewrite H99; clear t H99.*)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 case_eq (gvar_volatile v); intros; auto. rename H5 into H10.
(* Goal: @eq (forall _ : AV.address, resource) (@compose AV.address resource resource (resource_fmap (approx (@level rmap ag_rmap w)) (approx (@level rmap ag_rmap w))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc))) (fun loc : AV.address => if S_dec (@fst block Z loc) then resource_at w loc else @core resource Join_resource Sep_resource (resource_at w loc)) *)
  hnf; auto.

  unfold Genv.alloc_global in H3.
(* Goal: forall _ : @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end, @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  revert H3; case_eq (alloc m0 0 (init_data_list_size (gvar_init v))); intros.
(* Goal: @eq (option permission) (access_at m' (@pair block Z (nextblock m) z) Cur) (if range_dec Z0 z N then @Some permission (@Genv.perm_globvar V v) else @None permission) *)
  invSome. invSome.
  assert (H90: Z.pos (nextblock m0) -1 = Zlength vl).
    clear - H0 H3.

  apply alloc_globals_rev_nextblock in H0. apply alloc_result in H3.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
  subst.  rewrite H0.
  rewrite Zlength_correct.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  rewrite Z2Pos.id by omega. omega.
 destruct (H i (nextblock m0)) as [_ ?].
  rewrite Zlength_cons. rewrite H90.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  split; try omega.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  rewrite Zlength_correct. omega.
  spec H7. 
  simpl length.
  replace (Pos.to_nat (nextblock m0)) with (S (length vl)).
(* Goal: @eq Z (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) (Zpos (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI (xI xH)))))))))))))))))))))))))))))))) *)
  rewrite minus_diag. reflexivity.
  clear - H90. rewrite Zlength_correct in H90. apply inj_eq_rev.
(* Goal: and (iff (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))) (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w' loc)))) (forall _ : not (@identity resource Join_resource (@core resource Join_resource Sep_resource (resource_at w loc))), @eq resource (@core resource Join_resource Sep_resource (resource_at w loc)) (@core resource Join_resource Sep_resource (resource_at w' loc))) *)
  rewrite inj_S. rewrite <- H90. clear.
  rewrite Pos_to_nat_eq_S.
(* Goal: @eq Z (Z.add (Z.sub Ptrofs.modulus (Zpos xH)) (Zpos xH)) Ptrofs.modulus *)
  replace (Z.succ (Z.pos (nextblock m0) - 1)) with (Z.pos (nextblock m0)) by omega.
  unfold nat_of_Z.
  replace (S (Z.to_nat (Z.pos (nextblock m0)) - 1))
    with (Z.to_nat (Z.pos (nextblock m0)))
  by (rewrite Z2Nat.inj_pos; pose proof (Pos2Nat.is_pos (nextblock m0)); omega).
 rewrite Z2Nat.id by (pose proof (Pos2Z.is_pos (nextblock m0)); omega).
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 auto.

(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
pose proof (init_data_list_lem {| genv_genv := gev; genv_cenv := cenv |} m0 v m1 b m2 m3 m (initial_core gev (G0 ++ G) n) rho
     H3 H6 H9 H10) .
 spec H8.
(* Goal: or (not (@eq block b (nextblock m0))) (not (@eq Z ofs Z0)) *)
(* Goal: @eq (option permission) (access_at m (@pair block Z b ofs) Cur) (@None permission) *)
 { unfold initial_core; simpl; rewrite ghost_of_make_rmap, <- (ghost_core nil); apply core_identity. }
 spec H8.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 clear - AL. simpl in AL. apply andb_true_iff in AL; destruct AL; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply andb_true_iff in H. destruct H. apply Zlt_is_lt_bool; auto.
 specialize (H8 H5).
 spec H8.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 clear - AL. simpl in AL. apply andb_true_iff in AL; destruct AL; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply andb_true_iff in H. destruct H; auto.
 specialize (H8 RHO). (* replace (nextblock m0) with b by congruence. *)
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 eapply init_datalist_hack; eauto.
(* Goal: @identity resource Join_resource match access_at m0 (@pair block Z b z) Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 (@pair block Z b z))) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) (@pair block Z b z) end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
  apply alloc_result in H3; subst b.
  eassumption.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply hackfun_beyond_block; auto.
 apply readable_readonly2share.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 apply IHvl; auto.
(* Goal: @identity resource Join_resource match access_at m loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
(* Goal: @identity resource Join_resource match access_at m0 loc Cur with | Some (Freeable as p) => YES Share.top readable_share_top (VAL (contents_at m0 loc)) NoneP | Some (Writable as p) => YES Ews (@writable_readable Ews writable_Ews) (VAL (contents_at m0 loc)) NoneP | Some (Readable as p) => YES Ers readable_Ers (VAL (contents_at m0 loc)) NoneP | Some (Nonempty as p) => match resource_at (@initial_world.initial_core function gev G n) loc with | NO sh n => NO extern_retainer nonreadable_extern_retainer | YES sh r k p0 => NO extern_retainer nonreadable_extern_retainer | PURE k p0 => resource_at (@initial_world.initial_core function gev G n) loc end | None => NO Share.bot bot_unreadable end *)
 eapply another_hackfun_lemma; eauto.
Qed.
