Section MEMORY_CONSTRUCTION_II.
Variable j12 j23 j12' j23':meminj.
Variable m1 m1' m2 : mem.
Definition AccessMap_II_FUN (b2:block):
Z -> perm_kind -> option permission :=
if plt b2 (Mem.nextblock m2)
then (fun ofs2 k =>
match j23 b2 with
None => PMap.get b2 m2.(Mem.mem_access) ofs2 k
| Some (b3,d3) =>
match source j12 m1 b2 ofs2 with
Some(b1,ofs1) => PMap.get b1 m1'.(Mem.mem_access) ofs1 k
| None => PMap.get b2 m2.(Mem.mem_access) ofs2 k
end
end)
else (fun ofs2 k =>
match source j12' m1' b2 ofs2 with
Some(b1,ofs1) => PMap.get b1 m1'.(Mem.mem_access) ofs1 k
| None => None
end).
Definition ContentMap_II_ValidBlock_FUN b2 ofs2: memval :=
match source j12 m1 b2 ofs2 with
Some(b1,ofs1) =>
match j23' b2 with
None => ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
| Some(b3,ofs3) =>
inject_memval j12'
(ZMap.get ofs1 (PMap.get b1 m1'.(Mem.mem_contents)))
end
| None => ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
end.
Definition ContentMap_II_InvalidBlock_FUN b2 ofs2: memval :=
match source j12' m1' b2 ofs2 with
None => Undef
| Some(b1,ofs1) =>
inject_memval j12'
(ZMap.get ofs1 (PMap.get b1 m1'.(Mem.mem_contents)))
end.
Definition ContentMap_II_Block_FUN b ofs : memval:=
if plt b (Mem.nextblock m2)
then ContentMap_II_ValidBlock_FUN b ofs
else ContentMap_II_InvalidBlock_FUN b ofs.
Variable MINMAX_Offset: block -> option (Z * Z).
Hypothesis MINMAX: forall b2 ,
match MINMAX_Offset b2 with
Some(mn,mx) =>
(forall ofs, ofs < mn \/ ofs > mx ->
Plt b2 (Mem.nextblock m2) ->
ZMap.get ofs (Mem.mem_contents m2)!!b2 = Undef) /\
forall b1 delta, j12 b1 = Some(b2,delta) \/ j12' b1 = Some(b2,delta)->
forall z, z + delta < mn \/ z + delta > mx ->
ZMap.get z (Mem.mem_contents m1')!!b1 = Undef
| None =>
(Plt b2 (Mem.nextblock m2) ->
forall ofs, ZMap.get ofs (Mem.mem_contents m2)!!b2 = Undef)
/\
forall b1 delta, j12 b1 = Some(b2,delta) \/ j12' b1 = Some(b2,delta)->
forall z, ZMap.get z (Mem.mem_contents m1')!!b1 = Undef
end.

Lemma CM_block_II_existsT: forall b,
{ M : ZMap.t memval |
fst M = Undef /\
forall ofs, ZMap.get ofs M =
ContentMap_II_Block_FUN b ofs}.