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

/*@ behavior exists:
      assumes ∃ ℤ i; 0 ≤ i < (int)n ∧ (int)*((char *)buf + i) ≡ c;
      ensures
        ∀ int j;
          0 ≤ j < (int)\offset((char *)\result) ⇒
          (int)*((char *)\old(buf) + j) ≢ \old(c);
    
    behavior not_exists:
      assumes ∀ ℤ k; 0 ≤ k < (int)n ⇒ (int)*((char *)buf + k) ≢ c;
      ensures \result ≡ (void *)0;
 */
void *__gen_e_acsl_memchr(void const *buf, int c, size_t n);

void *memchr(void const *buf, int c, size_t n)
{
  void *__retres;
  int i;
  __e_acsl_store_block((void *)(& __retres),(size_t)8);
  __e_acsl_store_block((void *)(& buf),(size_t)8);
  char *s = (char *)buf;
  __e_acsl_store_block((void *)(& s),(size_t)8);
  __e_acsl_full_init((void *)(& s));
  i = 0;
  while ((size_t)i < n) {
    if ((int)*s == c) {
      __e_acsl_full_init((void *)(& __retres));
      __retres = (void *)s;
      goto return_label;
    }
    __e_acsl_full_init((void *)(& s));
    s ++;
    i ++;
  }
  __e_acsl_full_init((void *)(& __retres));
  __retres = (void *)0;
  return_label:
  {
    __e_acsl_delete_block((void *)(& buf));
    __e_acsl_delete_block((void *)(& s));
    __e_acsl_delete_block((void *)(& __retres));
    return __retres;
  }
}

/*@ behavior exists:
      assumes ∃ ℤ i; 0 ≤ i < (int)n ∧ (int)*((char *)buf + i) ≡ c;
      ensures
        ∀ int j;
          0 ≤ j < (int)\offset((char *)\result) ⇒
          (int)*((char *)\old(buf) + j) ≢ \old(c);
    
    behavior not_exists:
      assumes ∀ ℤ k; 0 ≤ k < (int)n ⇒ (int)*((char *)buf + k) ≢ c;
      ensures \result ≡ (void *)0;
 */
void *__gen_e_acsl_memchr(void const *buf, int c, size_t n)
{
  int __gen_e_acsl_at_2;
  void const *__gen_e_acsl_at;
  __e_acsl_contract_t *__gen_e_acsl_contract;
  void *__retres;
  __e_acsl_store_block((void *)(& __retres),(size_t)8);
  {
    int __gen_e_acsl_exists;
    unsigned int __gen_e_acsl_i;
    int __gen_e_acsl_forall;
    unsigned int __gen_e_acsl_k;
    __e_acsl_store_block((void *)(& buf),(size_t)8);
    __gen_e_acsl_contract = __e_acsl_contract_init((size_t)2);
    __gen_e_acsl_exists = 0;
    __gen_e_acsl_i = 0U;
    while (1) {
      if (__gen_e_acsl_i < (unsigned int)((int)((unsigned int)n))) ;
      else break;
      {
        int __gen_e_acsl_valid_read;
        __gen_e_acsl_valid_read = __e_acsl_valid_read((void *)((char *)buf + __gen_e_acsl_i),
                                                      sizeof(char),
                                                      (void *)buf,
                                                      (void *)(& buf));
        __e_acsl_assert(__gen_e_acsl_valid_read,"RTE","memchr",
                        "mem_access: \\valid_read((char *)buf + __gen_e_acsl_i)",
                        "tests/bts/bts1390.c",8);
        if (! ((int)*((char *)buf + __gen_e_acsl_i) == c)) ;
        else {
          __gen_e_acsl_exists = 1;
          goto e_acsl_end_loop1;
        }
      }
      __gen_e_acsl_i ++;
    }
    e_acsl_end_loop1: ;
    __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_k = 0U;
    while (1) {
      if (__gen_e_acsl_k < (unsigned int)((int)((unsigned int)n))) ;
      else break;
      {
        int __gen_e_acsl_valid_read_2;
        __gen_e_acsl_valid_read_2 = __e_acsl_valid_read((void *)((char *)buf + __gen_e_acsl_k),
                                                        sizeof(char),
                                                        (void *)buf,
                                                        (void *)(& buf));
        __e_acsl_assert(__gen_e_acsl_valid_read_2,"RTE","memchr",
                        "mem_access: \\valid_read((char *)buf + __gen_e_acsl_k)",
                        "tests/bts/bts1390.c",11);
        if ((int)*((char *)buf + __gen_e_acsl_k) != c) ;
        else {
          __gen_e_acsl_forall = 0;
          goto e_acsl_end_loop2;
        }
      }
      __gen_e_acsl_k ++;
    }
    e_acsl_end_loop2: ;
    __e_acsl_contract_set_behavior_assumes(__gen_e_acsl_contract,(size_t)1,
                                           __gen_e_acsl_forall);
  }
  __gen_e_acsl_at_2 = c;
  __gen_e_acsl_at = buf;
  __retres = memchr(buf,c,n);
  {
    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) {
      int __gen_e_acsl_forall_2;
      unsigned int __gen_e_acsl_j;
      __gen_e_acsl_forall_2 = 1;
      __gen_e_acsl_j = 0;
      while (1) {
        {
          unsigned long __gen_e_acsl_offset;
          __gen_e_acsl_offset = __e_acsl_offset(__retres);
          if (__gen_e_acsl_j < (unsigned int)((int)((unsigned int)__gen_e_acsl_offset))) 
            ;
          else break;
        }
        {
          int __gen_e_acsl_valid_read_3;
          __gen_e_acsl_valid_read_3 = __e_acsl_valid_read((void *)((char *)__gen_e_acsl_at + __gen_e_acsl_j),
                                                          sizeof(char),
                                                          (void *)__gen_e_acsl_at,
                                                          (void *)(& __gen_e_acsl_at));
          __e_acsl_assert(__gen_e_acsl_valid_read_3,"RTE","memchr",
                          "mem_access: \\valid_read((char *)__gen_e_acsl_at + __gen_e_acsl_j)",
                          "tests/bts/bts1390.c",9);
          if ((int)*((char *)__gen_e_acsl_at + __gen_e_acsl_j) != __gen_e_acsl_at_2) 
            ;
          else {
            __gen_e_acsl_forall_2 = 0;
            goto e_acsl_end_loop3;
          }
        }
        __gen_e_acsl_j ++;
      }
      e_acsl_end_loop3: ;
      __e_acsl_assert(__gen_e_acsl_forall_2,"Postcondition","memchr",
                      "exists:\n  \\forall int j;\n    0 <= j < (int)\\offset((char *)\\result) ==>\n    (int)*((char *)\\old(buf) + j) != \\old(c)",
                      "tests/bts/bts1390.c",9);
    }
    __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 == (void *)0,
                                                    "Postcondition","memchr",
                                                    "not_exists: \\result == (void *)0",
                                                    "tests/bts/bts1390.c",12);
    __e_acsl_contract_clean(__gen_e_acsl_contract);
    __e_acsl_delete_block((void *)(& buf));
    __e_acsl_delete_block((void *)(& __retres));
    return __retres;
  }
}

void __e_acsl_globals_init(void)
{
  static char __e_acsl_already_run = 0;
  if (! __e_acsl_already_run) {
    __e_acsl_already_run = 1;
    __gen_e_acsl_literal_string = "toto";
    __e_acsl_store_block((void *)__gen_e_acsl_literal_string,sizeof("toto"));
    __e_acsl_full_init((void *)__gen_e_acsl_literal_string);
    __e_acsl_mark_readonly((void *)__gen_e_acsl_literal_string);
    __gen_e_acsl_literal_string_2 = "tata";
    __e_acsl_store_block((void *)__gen_e_acsl_literal_string_2,
                         sizeof("tata"));
    __e_acsl_full_init((void *)__gen_e_acsl_literal_string_2);
    __e_acsl_mark_readonly((void *)__gen_e_acsl_literal_string_2);
  }
  return;
}

int main(void)
{
  int __retres;
  __e_acsl_memory_init((int *)0,(char ***)0,(size_t)8);
  __e_acsl_globals_init();
  __gen_e_acsl_memchr((void const *)__gen_e_acsl_literal_string,'o',
                      (unsigned long)4);
  __gen_e_acsl_memchr((void const *)__gen_e_acsl_literal_string_2,'o',
                      (unsigned long)4);
  __retres = 0;
  __e_acsl_memory_clean();
  return __retres;
}


