/* Generated by Frama-C */
#include "stddef.h"
#include "stdio.h"
void simple_loop(void)
{
  int sum = 0;
  {
    int i = 0;
    {
      int __gen_e_acsl_and;
      if (0 <= i) __gen_e_acsl_and = i <= 10; else __gen_e_acsl_and = 0;
      __e_acsl_assert(__gen_e_acsl_and,"Invariant","simple_loop",
                      "0 <= i <= 10","tests/constructs/loop.i",8);
    }
    /*@ loop invariant 0 ≤ i ≤ 10; */
    while (i < 10) {
      sum += i;
      {
        int __gen_e_acsl_and_2;
        i ++;
        if (0 <= i) __gen_e_acsl_and_2 = i <= 10;
        else __gen_e_acsl_and_2 = 0;
        __e_acsl_assert(__gen_e_acsl_and_2,"Invariant","simple_loop",
                        "0 <= i <= 10","tests/constructs/loop.i",8);
      }
    }
  }
  return;
}

void nested_loops(void)
{
  int t[10][15];
  int i = 0;
  {
    int __gen_e_acsl_and;
    if (0 <= i) __gen_e_acsl_and = i <= 10; else __gen_e_acsl_and = 0;
    __e_acsl_assert(__gen_e_acsl_and,"Invariant","nested_loops",
                    "0 <= i <= 10","tests/constructs/loop.i",15);
  }
  /*@ loop invariant 0 ≤ i ≤ 10; */
  while (i < 10) {
    {
      int j = 0;
      {
        int __gen_e_acsl_forall;
        int __gen_e_acsl_k;
        int __gen_e_acsl_l;
        int __gen_e_acsl_and_2;
        __gen_e_acsl_forall = 1;
        __gen_e_acsl_k = 0;
        while (1) {
          if (__gen_e_acsl_k < i) ; else break;
          __gen_e_acsl_l = 0;
          while (1) {
            if (__gen_e_acsl_l < j) ; else break;
            __e_acsl_assert(__gen_e_acsl_l < 15,"RTE","nested_loops",
                            "index_bound: __gen_e_acsl_l < 15",
                            "tests/constructs/loop.i",19);
            __e_acsl_assert(0 <= __gen_e_acsl_l,"RTE","nested_loops",
                            "index_bound: 0 <= __gen_e_acsl_l",
                            "tests/constructs/loop.i",19);
            __e_acsl_assert(__gen_e_acsl_k < 10,"RTE","nested_loops",
                            "index_bound: __gen_e_acsl_k < 10",
                            "tests/constructs/loop.i",19);
            __e_acsl_assert(0 <= __gen_e_acsl_k,"RTE","nested_loops",
                            "index_bound: 0 <= __gen_e_acsl_k",
                            "tests/constructs/loop.i",19);
            if ((long)t[__gen_e_acsl_k][__gen_e_acsl_l] == __gen_e_acsl_k * (long)__gen_e_acsl_l) 
              ;
            else {
              __gen_e_acsl_forall = 0;
              goto e_acsl_end_loop1;
            }
            __gen_e_acsl_l ++;
          }
          __gen_e_acsl_k ++;
        }
        e_acsl_end_loop1: ;
        __e_acsl_assert(__gen_e_acsl_forall,"Invariant","nested_loops",
                        "\\forall integer k, integer l; 0 <= k < i && 0 <= l < j ==> t[k][l] == k * l",
                        "tests/constructs/loop.i",19);
        if (0 <= j) __gen_e_acsl_and_2 = j <= 15;
        else __gen_e_acsl_and_2 = 0;
        __e_acsl_assert(__gen_e_acsl_and_2,"Invariant","nested_loops",
                        "0 <= j <= 15","tests/constructs/loop.i",17);
      }
      /*@ loop invariant 0 ≤ j ≤ 15;
          loop invariant
            ∀ ℤ k, ℤ l;
              0 ≤ k < i ∧ 0 ≤ l < j ⇒ t[k][l] ≡ k * l;
      */
      while (j < 15) {
        t[i][j] = i * j;
        {
          int __gen_e_acsl_and_3;
          int __gen_e_acsl_forall_2;
          int __gen_e_acsl_k_2;
          int __gen_e_acsl_l_2;
          j ++;
          if (0 <= j) __gen_e_acsl_and_3 = j <= 15;
          else __gen_e_acsl_and_3 = 0;
          __e_acsl_assert(__gen_e_acsl_and_3,"Invariant","nested_loops",
                          "0 <= j <= 15","tests/constructs/loop.i",17);
          __gen_e_acsl_forall_2 = 1;
          __gen_e_acsl_k_2 = 0;
          while (1) {
            if (__gen_e_acsl_k_2 < i) ; else break;
            __gen_e_acsl_l_2 = 0;
            while (1) {
              if (__gen_e_acsl_l_2 < j) ; else break;
              __e_acsl_assert(__gen_e_acsl_l_2 < 15,"RTE","nested_loops",
                              "index_bound: __gen_e_acsl_l_2 < 15",
                              "tests/constructs/loop.i",19);
              __e_acsl_assert(0 <= __gen_e_acsl_l_2,"RTE","nested_loops",
                              "index_bound: 0 <= __gen_e_acsl_l_2",
                              "tests/constructs/loop.i",19);
              __e_acsl_assert(__gen_e_acsl_k_2 < 10,"RTE","nested_loops",
                              "index_bound: __gen_e_acsl_k_2 < 10",
                              "tests/constructs/loop.i",19);
              __e_acsl_assert(0 <= __gen_e_acsl_k_2,"RTE","nested_loops",
                              "index_bound: 0 <= __gen_e_acsl_k_2",
                              "tests/constructs/loop.i",19);
              /*@ assert
                  Eva: initialization:
                    \initialized(&t[__gen_e_acsl_k_2][__gen_e_acsl_l_2]);
              */
              if ((long)t[__gen_e_acsl_k_2][__gen_e_acsl_l_2] == __gen_e_acsl_k_2 * (long)__gen_e_acsl_l_2) 
                ;
              else {
                __gen_e_acsl_forall_2 = 0;
                goto e_acsl_end_loop2;
              }
              __gen_e_acsl_l_2 ++;
            }
            __gen_e_acsl_k_2 ++;
          }
          e_acsl_end_loop2: ;
          __e_acsl_assert(__gen_e_acsl_forall_2,"Invariant","nested_loops",
                          "\\forall integer k, integer l; 0 <= k < i && 0 <= l < j ==> t[k][l] == k * l",
                          "tests/constructs/loop.i",19);
        }
      }
    }
    {
      int __gen_e_acsl_and_4;
      i ++;
      if (0 <= i) __gen_e_acsl_and_4 = i <= 10; else __gen_e_acsl_and_4 = 0;
      __e_acsl_assert(__gen_e_acsl_and_4,"Invariant","nested_loops",
                      "0 <= i <= 10","tests/constructs/loop.i",15);
    }
  }
  return;
}

void unnatural_loop(void)
{
  int x = 0;
  {
    int i = 0;
    {
      int __gen_e_acsl_and;
      if (0 <= i) __gen_e_acsl_and = i <= 6; else __gen_e_acsl_and = 0;
      __e_acsl_assert(__gen_e_acsl_and,"Invariant","unnatural_loop",
                      "0 <= i <= 6","tests/constructs/loop.i",26);
    }
    /*@ loop invariant 0 ≤ i ≤ 6; */
    while (i < 10) {
      if (x == 5) break;
      x = i;
      {
        int __gen_e_acsl_and_2;
        i ++;
        if (0 <= i) __gen_e_acsl_and_2 = i <= 6; else __gen_e_acsl_and_2 = 0;
        __e_acsl_assert(__gen_e_acsl_and_2,"Invariant","unnatural_loop",
                        "0 <= i <= 6","tests/constructs/loop.i",26);
      }
    }
  }
  return;
}

int main(void)
{
  int __retres;
  simple_loop();
  nested_loops();
  unnatural_loop();
  __retres = 0;
  return __retres;
}


