/* Generated by Frama-C */
#include "stddef.h"
#include "stdio.h"
extern int __e_acsl_sound_verdict;

int A[10];
/*@ requires ∀ ℤ i; 0 ≤ i < 9 ⇒ A[i] ≤ A[i + 1];
    
    behavior exists:
      assumes ∃ ℤ j; 0 ≤ j < 10 ∧ A[j] ≡ elt;
      ensures \result ≡ 1;
    
    behavior not_exists:
      assumes ∀ ℤ j; 0 ≤ j < 10 ⇒ A[j] ≢ elt;
      ensures \result ≡ 0;
 */
int __gen_e_acsl_search(int elt);

int search(int elt)
{
  int __retres;
  int k;
  k = 0;
  {
    int __gen_e_acsl_forall;
    int __gen_e_acsl_i;
    int __gen_e_acsl_and;
    __gen_e_acsl_forall = 1;
    __gen_e_acsl_i = 0;
    while (1) {
      if (__gen_e_acsl_i < k) ; else break;
      __e_acsl_assert(__gen_e_acsl_i < 10,"RTE","search",
                      "index_bound: __gen_e_acsl_i < 10",
                      "tests/examples/linear_search.i",18);
      __e_acsl_assert(0 <= __gen_e_acsl_i,"RTE","search",
                      "index_bound: 0 <= __gen_e_acsl_i",
                      "tests/examples/linear_search.i",18);
      if (A[__gen_e_acsl_i] < elt) ;
      else {
        __gen_e_acsl_forall = 0;
        goto e_acsl_end_loop1;
      }
      __gen_e_acsl_i ++;
    }
    e_acsl_end_loop1: ;
    __e_acsl_assert(__gen_e_acsl_forall,"Invariant","search",
                    "\\forall integer i; 0 <= i < k ==> A[i] < elt",
                    "tests/examples/linear_search.i",18);
    if (0 <= k) __gen_e_acsl_and = k <= 10; else __gen_e_acsl_and = 0;
    __e_acsl_assert(__gen_e_acsl_and,"Invariant","search","0 <= k <= 10",
                    "tests/examples/linear_search.i",17);
  }
  /*@ loop invariant 0 ≤ k ≤ 10;
      loop invariant ∀ ℤ i; 0 ≤ i < k ⇒ A[i] < elt;
  */
  while (k < 10) {
    if (A[k] == elt) {
      __retres = 1;
      goto return_label;
    }
    else 
      if (A[k] > elt) {
        __retres = 0;
        goto return_label;
      }
    {
      int __gen_e_acsl_and_2;
      int __gen_e_acsl_forall_2;
      int __gen_e_acsl_i_2;
      k ++;
      if (0 <= k) __gen_e_acsl_and_2 = k <= 10; else __gen_e_acsl_and_2 = 0;
      __e_acsl_assert(__gen_e_acsl_and_2,"Invariant","search","0 <= k <= 10",
                      "tests/examples/linear_search.i",17);
      __gen_e_acsl_forall_2 = 1;
      __gen_e_acsl_i_2 = 0;
      while (1) {
        if (__gen_e_acsl_i_2 < k) ; else break;
        __e_acsl_assert(__gen_e_acsl_i_2 < 10,"RTE","search",
                        "index_bound: __gen_e_acsl_i_2 < 10",
                        "tests/examples/linear_search.i",18);
        __e_acsl_assert(0 <= __gen_e_acsl_i_2,"RTE","search",
                        "index_bound: 0 <= __gen_e_acsl_i_2",
                        "tests/examples/linear_search.i",18);
        if (A[__gen_e_acsl_i_2] < elt) ;
        else {
          __gen_e_acsl_forall_2 = 0;
          goto e_acsl_end_loop2;
        }
        __gen_e_acsl_i_2 ++;
      }
      e_acsl_end_loop2: ;
      __e_acsl_assert(__gen_e_acsl_forall_2,"Invariant","search",
                      "\\forall integer i; 0 <= i < k ==> A[i] < elt",
                      "tests/examples/linear_search.i",18);
    }
  }
  __retres = 0;
  return_label: return __retres;
}

int main(void)
{
  int __retres;
  int found;
  {
    int i = 0;
    while (i < 10) {
      A[i] = i * i;
      i ++;
    }
  }
  found = __gen_e_acsl_search(36);
  __e_acsl_assert(found == 1,"Assertion","main","found == 1",
                  "tests/examples/linear_search.i",31);
  /*@ assert found ≡ 1; */ ;
  found = __gen_e_acsl_search(5);
  __e_acsl_assert(found == 0,"Assertion","main","found == 0",
                  "tests/examples/linear_search.i",34);
  /*@ assert found ≡ 0; */ ;
  __retres = 0;
  return __retres;
}

/*@ requires ∀ ℤ i; 0 ≤ i < 9 ⇒ A[i] ≤ A[i + 1];
    
    behavior exists:
      assumes ∃ ℤ j; 0 ≤ j < 10 ∧ A[j] ≡ elt;
      ensures \result ≡ 1;
    
    behavior not_exists:
      assumes ∀ ℤ j; 0 ≤ j < 10 ⇒ A[j] ≢ elt;
      ensures \result ≡ 0;
 */
int __gen_e_acsl_search(int elt)
{
  __e_acsl_contract_t *__gen_e_acsl_contract;
  int __retres;
  {
    int __gen_e_acsl_exists;
    int __gen_e_acsl_j;
    int __gen_e_acsl_forall;
    int __gen_e_acsl_j_2;
    int __gen_e_acsl_forall_2;
    int __gen_e_acsl_i;
    __gen_e_acsl_contract = __e_acsl_contract_init((size_t)2);
    __gen_e_acsl_exists = 0;
    __gen_e_acsl_j = 0;
    while (1) {
      if (__gen_e_acsl_j < 10) ; else break;
      __e_acsl_assert(__gen_e_acsl_j < 10,"RTE","search",
                      "index_bound: __gen_e_acsl_j < 10",
                      "tests/examples/linear_search.i",9);
      __e_acsl_assert(0 <= __gen_e_acsl_j,"RTE","search",
                      "index_bound: 0 <= __gen_e_acsl_j",
                      "tests/examples/linear_search.i",9);
      if (! (A[__gen_e_acsl_j] == elt)) ;
      else {
        __gen_e_acsl_exists = 1;
        goto e_acsl_end_loop3;
      }
      __gen_e_acsl_j ++;
    }
    e_acsl_end_loop3: ;
    __e_acsl_contract_set_behavior_assumes(__gen_e_acsl_contract,(size_t)0,
                                           __gen_e_acsl_exists);
    __gen_e_acsl_forall = 1;
    __gen_e_acsl_j_2 = 0;
    while (1) {
      if (__gen_e_acsl_j_2 < 10) ; else break;
      __e_acsl_assert(__gen_e_acsl_j_2 < 10,"RTE","search",
                      "index_bound: __gen_e_acsl_j_2 < 10",
                      "tests/examples/linear_search.i",12);
      __e_acsl_assert(0 <= __gen_e_acsl_j_2,"RTE","search",
                      "index_bound: 0 <= __gen_e_acsl_j_2",
                      "tests/examples/linear_search.i",12);
      if (A[__gen_e_acsl_j_2] != elt) ;
      else {
        __gen_e_acsl_forall = 0;
        goto e_acsl_end_loop4;
      }
      __gen_e_acsl_j_2 ++;
    }
    e_acsl_end_loop4: ;
    __e_acsl_contract_set_behavior_assumes(__gen_e_acsl_contract,(size_t)1,
                                           __gen_e_acsl_forall);
    __gen_e_acsl_forall_2 = 1;
    __gen_e_acsl_i = 0;
    while (1) {
      if (__gen_e_acsl_i < 9) ; else break;
      __e_acsl_assert((int)(__gen_e_acsl_i + 1L) < 10,"RTE","search",
                      "index_bound: (int)(__gen_e_acsl_i + 1) < 10",
                      "tests/examples/linear_search.i",7);
      __e_acsl_assert(0 <= (int)(__gen_e_acsl_i + 1L),"RTE","search",
                      "index_bound: 0 <= (int)(__gen_e_acsl_i + 1)",
                      "tests/examples/linear_search.i",7);
      __e_acsl_assert(__gen_e_acsl_i < 10,"RTE","search",
                      "index_bound: __gen_e_acsl_i < 10",
                      "tests/examples/linear_search.i",7);
      __e_acsl_assert(0 <= __gen_e_acsl_i,"RTE","search",
                      "index_bound: 0 <= __gen_e_acsl_i",
                      "tests/examples/linear_search.i",7);
      if (A[__gen_e_acsl_i] <= A[__gen_e_acsl_i + 1]) ;
      else {
        __gen_e_acsl_forall_2 = 0;
        goto e_acsl_end_loop5;
      }
      __gen_e_acsl_i ++;
    }
    e_acsl_end_loop5: ;
    __e_acsl_assert(__gen_e_acsl_forall_2,"Precondition","search",
                    "\\forall integer i; 0 <= i < 9 ==> A[i] <= A[i + 1]",
                    "tests/examples/linear_search.i",7);
  }
  __retres = search(elt);
  {
    int __gen_e_acsl_assumes_value;
    __gen_e_acsl_assumes_value = __e_acsl_contract_get_behavior_assumes
    ((__e_acsl_contract_t const *)__gen_e_acsl_contract,(size_t)0);
    if (__gen_e_acsl_assumes_value) __e_acsl_assert(__retres == 1,
                                                    "Postcondition","search",
                                                    "exists: \\result == 1",
                                                    "tests/examples/linear_search.i",
                                                    10);
    __gen_e_acsl_assumes_value = __e_acsl_contract_get_behavior_assumes
    ((__e_acsl_contract_t const *)__gen_e_acsl_contract,(size_t)1);
    if (__gen_e_acsl_assumes_value) __e_acsl_assert(__retres == 0,
                                                    "Postcondition","search",
                                                    "not_exists: \\result == 0",
                                                    "tests/examples/linear_search.i",
                                                    13);
    __e_acsl_contract_clean(__gen_e_acsl_contract);
    return __retres;
  }
}


