Definition mkEE (m1 m1' m2 m3 m3':Mem.mem) (Ext12: Mem.extends m1 m2)
(Fwd1: mem_forward m1 m1')
(Ext23: Mem.extends m2 m3) (Fwd3: mem_forward m3 m3')
(Ext13' : Mem.extends m1' m3')
(UnchOn3: Mem.unchanged_on (loc_out_of_bounds m1) m3 m3')
: Mem.mem'.
destruct (mkAccessMap_EE_existsT m1 m1' m2) as [AM [ADefault PAM]].
destruct (ContentsMap_EE_existsT m1 m1' m2) as [CM [CDefault PCM]].
eapply Mem.mkmem with (nextblock:=m3'.(Mem.nextblock))
(mem_access:=AM)
(mem_contents:=CM).
(* (NB: forall b, Mem.valid_block m2 b -> Mem.valid_block m3' b)*)
(*  apply (mkContentsMap_EE_exists m1 m1' m2).*)
(*eapply Mem.mkmem with (nextblock:=m3'.(Mem.nextblock)) (mem_access:=(Mem.mem_access m2')).*)
(*  apply m3'.*)
(*access_max*)
intros. rewrite PAM. unfold AccessMap_EE_FUN'.
destruct (plt b (Mem.nextblock m1')).
remember (plt b m2.(Mem.nextblock)) as z.
destruct z as [z|z]; clear Heqz.
(*Case valid*) (*clear Inval. specialize (Val z). destruct (Val Max ofs) as [MaxA MaxB]. destruct (Val Cur ofs) as [CurA CurB]. clear Val.*)
remember (Mem.perm_dec m1 b ofs Max Nonempty) as zz.
destruct zz; clear Heqzz. apply m1'. apply m2.
(*Case invalid*) apply m1'. reflexivity. (*nextblock_noaccess*)
intros. rewrite PAM.
unfold AccessMap_EE_FUN'.
destruct (plt b (Mem.nextblock m1')).
exfalso. apply H; clear - Ext13' p.
destruct Ext13'. rewrite <- mext_next. apply p.
trivial.
(*Default*)
intros. simpl. rewrite PCM.
unfold ContentsMap_EE_FUN.
destruct (plt b (Mem.nextblock m1')).
remember (CM_block_EE_existsT m1 m1' m2 b).
destruct s. apply a.
reflexivity.
Defined.

Lemma interpolate_EE: forall m1 m2 (Ext12: Mem.extends m1 m2) m1'
(Fwd1: mem_forward m1 m1') m3 (Ext23: Mem.extends m2 m3) m3'
(Fwd3: mem_forward m3 m3') (Ext13' : Mem.extends m1' m3')
(UnchOn3: Mem.unchanged_on (loc_out_of_bounds m1) m3 m3'),
exists m2', mem_forward m2 m2' /\ Mem.extends m1' m2' /\
Mem.extends m2' m3' /\
Mem.unchanged_on (loc_out_of_bounds m1) m2 m2'.