Definition freeable_blocks: list (block * BinInt.Z * BinInt.Z) -> mpred :=
  fold_right (fun (bb: block*BinInt.Z * BinInt.Z) a => 
                        match bb with (b,lo,hi) => 
                                          sepcon (VALspec_range (hi-lo) Share.top (b,lo)) a
                        end)
                    emp.

(* Specifications: *)
Lemma perm_of_res_val : forall r, perm_of_res r = Some Freeable -> exists v pp, r = YES Share.top readable_share_top (VAL v) pp.
Lemma free_list_juicy_mem_i: forall jm bl m' F, free_list (m_dry jm) bl = Some m' -> app_pred (freeable_blocks bl * F) (m_phi jm) -> exists jm', free_list_juicy_mem jm bl jm' /\ m_dry jm' = m' /\ level jm = level jm'.
Lemma free_juicy_mem_ext: forall jm1 jm2 b lo hi m1 m2 H1 H2, jm1=jm2 -> m1=m2 -> free_juicy_mem jm1 m1 b lo hi H1 = free_juicy_mem jm2 m2 b lo hi H2.
Lemma free_list_juicy_mem_lem: forall P jm bl jm', free_list_juicy_mem jm bl jm' -> app_pred (freeable_blocks bl * P) (m_phi jm) -> app_pred P (m_phi jm').
Lemma xelements_app: forall A (rho: PTree.t A) i al bl, PTree.xelements rho i al ++ bl = PTree.xelements rho i (al++bl).
Lemma PTree_elements_remove: forall {A} (T: PTree.tree A) i e, In e (PTree.elements (PTree.remove i T)) -> In e (PTree.elements T) /\ fst e <> i.
Lemma VALspec_range_free: forall n b phi1 jm, app_pred (VALspec_range n Share.top (b, 0)) phi1 -> join_sub phi1 (m_phi jm) -> {m' | free (m_dry jm) b 0 n = Some m' }.
Lemma Forall_filter: forall {A} P (l: list A) f, Forall P l -> Forall P (filter f l).
Lemma can_free_list: forall Delta F f jm ge ve te (NOREP: list_norepet (map (@fst _ _) (fn_vars f))) (COMPLETE: Forall (fun it => complete_type cenv_cs (snd it) = true) (fn_vars f)) (HGG: genv_cenv ge = cenv_cs), guard_environ (func_tycontext' f Delta) (Some f) (construct_rho (filter_genv ge) ve te) -> (F * stackframe_of f (construct_rho (filter_genv ge)ve te))%pred (m_phi jm) -> exists m2, free_list (m_dry jm) (blocks_of_env ge ve) = Some m2.
Lemma necR_m_dry': forall jm jm', m_dry jm = m_dry jm' -> (necR (m_phi jm) (m_phi jm')) -> necR jm jm'.
Lemma age_juicy_mem_i: forall jm jm', m_dry jm = m_dry jm' -> age (m_phi jm) (m_phi jm') -> age jm jm'.
Lemma free_list_resource_decay: forall bl jm jm', free_list_juicy_mem jm bl jm' -> resource_decay (nextblock (m_dry jm)) (m_phi jm) (m_phi jm').
Lemma alloc_juicy_variables_age: forall {ge rho jm jm1 vl rho' jm' jm1'}, age jm jm1 -> age jm' jm1' -> alloc_juicy_variables ge rho jm vl = (rho', jm') -> alloc_juicy_variables ge rho jm1 vl = (rho', jm1').
Lemma alloc_juicy_variables_resource_decay: forall ge rho jm vl rho' jm', alloc_juicy_variables ge rho jm vl = (rho', jm') -> resource_decay (nextblock (m_dry jm)) (m_phi jm) (m_phi jm') /\ (nextblock (m_dry jm) <= nextblock (m_dry jm'))%positive.
Lemma juicy_mem_alloc_block: forall jm n jm2 b F, juicy_mem_alloc jm 0 n = (jm2, b) -> app_pred F (m_phi jm) -> 0 <= n < Ptrofs.modulus -> app_pred (F * memory_block Share.top n (Vptr b Ptrofs.zero)) (m_phi jm2).
Lemma alloc_juicy_variables_lem2: forall jm f (ge: genv) ve te jm' (F: pred rmap) (HGG: genv_cenv ge = cenv_cs) (COMPLETE: Forall (fun it => complete_type cenv_cs (snd it) = true) (fn_vars f)) (Hsize: Forall (fun var => @sizeof ge (snd var) <= Ptrofs.max_unsigned) (fn_vars f)), list_norepet (map fst (fn_vars f)) -> alloc_juicy_variables ge empty_env jm (fn_vars f) = (ve, jm') -> app_pred F (m_phi jm) -> app_pred (F * stackframe_of f (construct_rho (filter_genv ge) ve te)) (m_phi jm').
Lemma free_list_juicy_mem_ghost: forall m l m', free_list_juicy_mem m l m' -> ghost_of (m_phi m') = ghost_of (m_phi m).
Lemma alloc_juicy_variables_ghost: forall l ge rho jm, ghost_of (m_phi (snd (alloc_juicy_variables ge rho jm l))) = ghost_of (m_phi jm).
Lemma call_cont_idem: forall k, call_cont (call_cont k) = call_cont k.
Lemma call_cont_current_function: forall {k i f e t l}, call_cont k = Kcall i f e t :: l -> current_function k = Some f.
Lemma semax_return: forall Delta R ret, semax Espec Delta (fun rho => tc_expropt Delta ret (ret_type Delta) rho && RA_return R (cast_expropt ret (ret_type Delta) rho) rho) (Sreturn ret) R.