Hint Resolve xtree_rep_nullval: saturate_local.
(* X_DEFS ends. *)
(* Y_DEFS *)
Inductive YTree: Type :=
| YLeaf: YTree
| YNode: list (tree (unit * YTree) * unit) -> Z -> YTree.
Definition y_tree_rep (t: tree val) (p: val): mpred :=
tree_rep (fun q L R p: val => data_at Tsh t_struct_Ytree (q, (L, R)) p) t p.
Definition y_list_rep (l: list val) (p: val): mpred :=
list_rep (fun q n p: val => data_at Tsh t_struct_Ylist (q, n) p) l p.
Fixpoint ytree_rep (t: YTree) (p: val): mpred :=
match t with
| YLeaf =>
!!(p = nullval) && emp
| YNode ttl v =>
let rep1 (t: unit * YTree) p := ytree_rep (snd t) p in
let rep2 (t: tree (unit * YTree) * unit) p :=
EX s: tree val, y_tree_rep s p * iter_tree_sepcon2 rep1 (fst t) s in
let rep3 (t: list (tree (unit * YTree) * unit)) p :=
EX r: list val, y_list_rep r p * iter_sepcon2 rep2 t r in
EX q: val,
data_at Tsh t_struct_Ynode (q, Vint (Int.repr v)) p * rep3 ttl q
end.
Definition t_ytree_rep (t: tree (unit * YTree)) (p: val): mpred :=
EX s: tree val, y_tree_rep s p * iter_tree_sepcon2 (fun t p => ytree_rep (snd t) p) t s.
Definition lt_ytree_rep (t: list (tree (unit * YTree) * unit)) (p: val): mpred :=
EX r: list val, y_list_rep r p * iter_sepcon2 (fun t p => t_ytree_rep (fst t) p) t r.

(* Specifications: *)
Theorem ytree_rep_spec: forall t p,
ytree_rep t p =
match t with
| YLeaf =>
!!(p = nullval) && emp
| YNode ttl v =>
EX q: val,
data_at Tsh t_struct_Ynode (q, Vint (Int.repr v)) p * lt_ytree_rep ttl q
end.
Lemma y_list_rep_valid_pointer: forall t p, y_list_rep t p |-- valid_pointer p.
Hint Resolve y_list_rep_valid_pointer: valid_pointer.
Lemma y_list_rep_local_facts: forall t p, y_list_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = nil)).
Hint Resolve y_list_rep_local_facts: saturate_local.
Lemma y_tree_rep_valid_pointer: forall t p, y_tree_rep t p |-- valid_pointer p.
Hint Resolve y_tree_rep_valid_pointer: valid_pointer.
Lemma y_tree_rep_local_facts: forall t p, y_tree_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = E)).
Hint Resolve y_tree_rep_local_facts: saturate_local.
Lemma ytree_rep_valid_pointer:
forall t p, ytree_rep t p |-- valid_pointer p.