(* This file was originally generated by why.
   It can be modified; only the generated parts will be overwritten. *)

Require Export List.

(* should go in List *)
Lemma app_rev_cons :
 forall (A:Set) (l1 l2:list A) (x:A),
   app (rev l1) (cons x l2) = app (rev (cons x l1)) l2.
Proof.
intros; simpl.
rewrite app_ass; auto.
Qed.

Require Export reverse_spec_why.

Proof.
unfold length_order; intuition.
apply (length_order_wf global). 
Qed.




Proof.
exists nil.
inversion_clear HW_1.
exists x.
unfold is_list, app,nil; intuition.
constructor.
apply disjoint_nil2.
rewrite <- app_nil_end; auto.
rewrite (llist_function _ _ _ _ _ _ _ H H0); auto.
Qed.



Proof.
intuition.
inversion_clear HW_2.
inversion_clear H.
intuition.
inversion H3; intuition.
Qed.



Proof.
intros; subst; intuition.
(* case 1 : preservation of loop invariant *)
elim HW_2; clear HW_2; intuition.
elim H; clear H; intuition.
inversion H3.
absurd (r = null); intuition.
exists (r :: x); exists l; subst; intuition.
(* subgoal 1.1 *)
unfold llist,lpath; apply Path_cons; intuition.
rewrite acc_upd; auto.
apply llist_pset_same; auto.
unfold disjoint,caduceus_lists.disjoint in H2; intuition.
apply (H7 r); auto.
auto with *.
(* subgoal 1.2 *)
unfold llist,lpath; apply llist_pset_same; auto.
apply llist_not_starting with alloc (acc tl_global0); auto.
(* subgoal 1.3 *)
unfold disjoint; apply disjoint_cons; auto.
apply llist_not_starting with alloc (acc tl_global0); auto.
(* subgoal 1.4 *)
unfold rev,app in *|-*; rewrite app_rev_cons.
apply H1; auto.
(* case 2 : variant decreases *)
unfold length_order, length.
exists alloc.
elim HW_2; clear HW_2; intuition.
elim H; clear H; intuition.
inversion H3; intuition.
exists l; exists x0; intuition.
apply llist_pset_same; auto.
apply llist_not_starting with alloc (acc tl_global0); auto.
rewrite <- H7; simpl; omega.
Qed.


Proof.
intros; subst; intuition.
(* post-condition *)
elim HW_2; clear HW_2; intuition.
elim H; clear H; intuition.
inversion H3; clear H3; intuition.
subst.
rewrite <- H1; auto.
Qed.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "", line 0, characters 0-0: *)
(*Why goal*) Lemma rev_impl_po_1 : 
  forall (p0: (pointer global)),
  forall (alloc: alloc_table),
  forall (tl_global: (memory (pointer global) global)),
  forall (HW_1: (* CADUCEUS_14 *) (is_list tl_global alloc p0)),
  (well_founded length_order).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/linked-lists/reverse.c", line 14, characters 8-193: *)
(*Why goal*) Lemma rev_impl_po_2 : 
  forall (p0: (pointer global)),
  forall (alloc: alloc_table),
  forall (tl_global: (memory (pointer global) global)),
  forall (HW_1: (* CADUCEUS_14 *) (is_list tl_global alloc p0)),
  (* CADUCEUS_16 *)
  (exists lp:plist,
   (exists lr:plist, (((llist tl_global alloc (@null global) lp) /\
    (llist tl_global alloc p0 lr)) /\ (disjoint lp lr)) /\
    (forall (l:plist),
     ((llist tl_global alloc p0 l) -> (app (rev lr) lp) = (rev l))))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/linked-lists/reverse.c", line 21, characters 8-13: *)
(*Why goal*) Lemma rev_impl_po_3 : 
  forall (p0: (pointer global)),
  forall (alloc: alloc_table),
  forall (tl_global: (memory (pointer global) global)),
  forall (HW_1: (* CADUCEUS_14 *) (is_list tl_global alloc p0)),
  forall (p: (pointer global)),
  forall (r: (pointer global)),
  forall (tl_global0: (memory (pointer global) global)),
  forall (HW_2: (* CADUCEUS_16 *)
                (exists lp:plist,
                 (exists lr:plist, (((llist tl_global0 alloc p lp) /\
                  (llist tl_global0 alloc r lr)) /\ (disjoint lp lr)) /\
                  (forall (l:plist),
                   ((llist tl_global alloc p0 l) ->
                    (app (rev lr) lp) = (rev l)))))),
  forall (HW_3: ~(r = (@null global))),
  (valid alloc r).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/linked-lists/reverse.c", line 14, characters 8-193: *)
(*Why goal*) Lemma rev_impl_po_4 : 
  forall (p0: (pointer global)),
  forall (alloc: alloc_table),
  forall (tl_global: (memory (pointer global) global)),
  forall (HW_1: (* CADUCEUS_14 *) (is_list tl_global alloc p0)),
  forall (p: (pointer global)),
  forall (r: (pointer global)),
  forall (tl_global0: (memory (pointer global) global)),
  forall (HW_2: (* CADUCEUS_16 *)
                (exists lp:plist,
                 (exists lr:plist, (((llist tl_global0 alloc p lp) /\
                  (llist tl_global0 alloc r lr)) /\ (disjoint lp lr)) /\
                  (forall (l:plist),
                   ((llist tl_global alloc p0 l) ->
                    (app (rev lr) lp) = (rev l)))))),
  forall (HW_3: ~(r = (@null global))),
  forall (HW_4: (valid alloc r)),
  forall (result: (pointer global)),
  forall (HW_5: result = (acc tl_global0 r)),
  forall (r0: (pointer global)),
  forall (HW_6: r0 = result),
  forall (HW_7: (valid alloc r)),
  forall (tl_global1: (memory (pointer global) global)),
  forall (HW_8: tl_global1 = (upd tl_global0 r p)),
  forall (p1: (pointer global)),
  forall (HW_9: p1 = r),
  (* CADUCEUS_16 *)
  (exists lp:plist,
   (exists lr:plist, (((llist tl_global1 alloc p1 lp) /\
    (llist tl_global1 alloc r0 lr)) /\ (disjoint lp lr)) /\
    (forall (l:plist),
     ((llist tl_global alloc p0 l) -> (app (rev lr) lp) = (rev l))))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/linked-lists/reverse.c", line 18, characters 14-23: *)
(*Why goal*) Lemma rev_impl_po_5 : 
  forall (p0: (pointer global)),
  forall (alloc: alloc_table),
  forall (tl_global: (memory (pointer global) global)),
  forall (HW_1: (* CADUCEUS_14 *) (is_list tl_global alloc p0)),
  forall (p: (pointer global)),
  forall (r: (pointer global)),
  forall (tl_global0: (memory (pointer global) global)),
  forall (HW_2: (* CADUCEUS_16 *)
                (exists lp:plist,
                 (exists lr:plist, (((llist tl_global0 alloc p lp) /\
                  (llist tl_global0 alloc r lr)) /\ (disjoint lp lr)) /\
                  (forall (l:plist),
                   ((llist tl_global alloc p0 l) ->
                    (app (rev lr) lp) = (rev l)))))),
  forall (HW_3: ~(r = (@null global))),
  forall (HW_4: (valid alloc r)),
  forall (result: (pointer global)),
  forall (HW_5: result = (acc tl_global0 r)),
  forall (r0: (pointer global)),
  forall (HW_6: r0 = result),
  forall (HW_7: (valid alloc r)),
  forall (tl_global1: (memory (pointer global) global)),
  forall (HW_8: tl_global1 = (upd tl_global0 r p)),
  forall (p1: (pointer global)),
  forall (HW_9: p1 = r),
  (length_order
   ((* CADUCEUS_17 *) (length tl_global1 r0)) ((* CADUCEUS_17 *)
                                              (length tl_global0 r))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/linked-lists/reverse.c", line 8, characters 12-76: *)
(*Why goal*) Lemma rev_impl_po_6 : 
  forall (p0: (pointer global)),
  forall (alloc: alloc_table),
  forall (tl_global: (memory (pointer global) global)),
  forall (HW_1: (* CADUCEUS_14 *) (is_list tl_global alloc p0)),
  forall (p: (pointer global)),
  forall (r: (pointer global)),
  forall (tl_global0: (memory (pointer global) global)),
  forall (HW_2: (* CADUCEUS_16 *)
                (exists lp:plist,
                 (exists lr:plist, (((llist tl_global0 alloc p lp) /\
                  (llist tl_global0 alloc r lr)) /\ (disjoint lp lr)) /\
                  (forall (l:plist),
                   ((llist tl_global alloc p0 l) ->
                    (app (rev lr) lp) = (rev l)))))),
  forall (HW_10: r = (@null global)),
  forall (caduceus_return: (pointer global)),
  forall (HW_11: caduceus_return = p),
  forall (l0: plist),
  forall (HW_12: (llist tl_global alloc p0 l0)),
  (* CADUCEUS_15 *) (llist tl_global0 alloc caduceus_return (rev l0)).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

