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

/*@ requires valid_nstring_src: valid_read_nstring(src, n);
    requires room_nstring: \valid(dest + (0 .. n - 1));
    requires separation: \separated(dest + (0 .. n - 1), src + (0 .. n - 1));
    ensures result_ptr: \result ≡ \old(dest);
    ensures initialization: \initialized(\old(dest) + (0 .. \old(n) - 1));
    assigns *(dest + (0 .. n - 1)), \result;
    assigns *(dest + (0 .. n - 1)) \from *(src + (0 .. n - 1));
    assigns \result \from dest;
    
    behavior complete:
      assumes src_fits: strlen(src) < n;
      ensures equal_after_copy: strcmp(\old(dest), \old(src)) ≡ 0;
    
    behavior partial:
      assumes src_too_long: n ≤ strlen(src);
      ensures
        equal_prefix:
          memcmp{Post, Post}(\old(dest), \old(src), \old(n)) ≡ 0;
 */
char *__gen_e_acsl_strncpy(char * __restrict dest,
                           char const * __restrict src, size_t n);

/*@ requires valid_nstring_src: valid_read_nstring(src, n);
    requires room_nstring: \valid(dest + (0 .. n - 1));
    requires separation: \separated(dest + (0 .. n - 1), src + (0 .. n - 1));
    ensures result_ptr: \result ≡ \old(dest);
    ensures initialization: \initialized(\old(dest) + (0 .. \old(n) - 1));
    assigns *(dest + (0 .. n - 1)), \result;
    assigns *(dest + (0 .. n - 1)) \from *(src + (0 .. n - 1));
    assigns \result \from dest;
    
    behavior complete:
      assumes src_fits: strlen(src) < n;
      ensures equal_after_copy: strcmp(\old(dest), \old(src)) ≡ 0;
    
    behavior partial:
      assumes src_too_long: n ≤ strlen(src);
      ensures
        equal_prefix:
          memcmp{Post, Post}(\old(dest), \old(src), \old(n)) ≡ 0;
 */
char *__gen_e_acsl_strncpy(char * __restrict dest,
                           char const * __restrict src, size_t n)
{
  __e_acsl_mpz_t __gen_e_acsl_at_3;
  char *__gen_e_acsl_at_2;
  char *__gen_e_acsl_at;
  __e_acsl_contract_t *__gen_e_acsl_contract;
  char *__retres;
  {
    unsigned long __gen_e_acsl_size;
    __e_acsl_mpz_t __gen_e_acsl_n;
    __e_acsl_mpz_t __gen_e_acsl_;
    __e_acsl_mpz_t __gen_e_acsl_sub;
    __e_acsl_mpz_t __gen_e_acsl__2;
    __e_acsl_mpz_t __gen_e_acsl_sub_2;
    __e_acsl_mpz_t __gen_e_acsl_add;
    unsigned long __gen_e_acsl__3;
    unsigned long __gen_e_acsl_if;
    int __gen_e_acsl_valid;
    unsigned long __gen_e_acsl_size_2;
    unsigned long __gen_e_acsl__4;
    unsigned long __gen_e_acsl_if_2;
    int __gen_e_acsl_valid_read;
    unsigned long __gen_e_acsl_size_3;
    unsigned long __gen_e_acsl__5;
    unsigned long __gen_e_acsl_if_3;
    int __gen_e_acsl_valid_read_2;
    unsigned long __gen_e_acsl_size_4;
    unsigned long __gen_e_acsl__6;
    unsigned long __gen_e_acsl_if_4;
    unsigned long __gen_e_acsl_size_5;
    unsigned long __gen_e_acsl__7;
    unsigned long __gen_e_acsl_if_5;
    int __gen_e_acsl_separated;
    __e_acsl_store_block((void *)(& src),(size_t)8);
    __e_acsl_store_block((void *)(& dest),(size_t)8);
    __gen_e_acsl_contract = __e_acsl_contract_init((size_t)2);
    __gmpz_init_set_ui(__gen_e_acsl_n,n);
    __gmpz_init_set_si(__gen_e_acsl_,1L);
    __gmpz_init(__gen_e_acsl_sub);
    __gmpz_sub(__gen_e_acsl_sub,
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_n),
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_));
    __gmpz_init_set_si(__gen_e_acsl__2,0L);
    __gmpz_init(__gen_e_acsl_sub_2);
    __gmpz_sub(__gen_e_acsl_sub_2,
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_sub),
               (__e_acsl_mpz_struct const *)(__gen_e_acsl__2));
    __gmpz_init(__gen_e_acsl_add);
    __gmpz_add(__gen_e_acsl_add,
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_sub_2),
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_));
    __gen_e_acsl__3 = __gmpz_get_ui((__e_acsl_mpz_struct const *)(__gen_e_acsl_add));
    __gen_e_acsl_size = 1UL * __gen_e_acsl__3;
    if (__gen_e_acsl_size <= 0UL) __gen_e_acsl_if = 0UL;
    else __gen_e_acsl_if = __gen_e_acsl_size;
    __gen_e_acsl_valid = __e_acsl_valid((void *)(dest + 1 * 0),
                                        __gen_e_acsl_if,(void *)dest,
                                        (void *)(& dest));
    __e_acsl_assert(__gen_e_acsl_valid,"Precondition","strncpy",
                    "\\valid(dest + (0 .. n - 1))",
                    "FRAMAC_SHARE/libc/string.h",364);
    __gen_e_acsl__4 = __gmpz_get_ui((__e_acsl_mpz_struct const *)(__gen_e_acsl_add));
    __gen_e_acsl_size_2 = 1UL * __gen_e_acsl__4;
    if (__gen_e_acsl_size_2 <= 0UL) __gen_e_acsl_if_2 = 0UL;
    else __gen_e_acsl_if_2 = __gen_e_acsl_size_2;
    __gen_e_acsl_valid_read = __e_acsl_valid_read((void *)(dest + 1 * 0),
                                                  __gen_e_acsl_if_2,
                                                  (void *)dest,
                                                  (void *)(& dest));
    /*@ assert E_ACSL: separated_guard: \valid_read(dest + (0 .. n - 1)); */
    __e_acsl_assert(__gen_e_acsl_valid_read,"RTE","strncpy",
                    "separated_guard: \\valid_read(dest + (0 .. n - 1))",
                    "FRAMAC_SHARE/libc/string.h",366);
    __gen_e_acsl__5 = __gmpz_get_ui((__e_acsl_mpz_struct const *)(__gen_e_acsl_add));
    __gen_e_acsl_size_3 = 1UL * __gen_e_acsl__5;
    if (__gen_e_acsl_size_3 <= 0UL) __gen_e_acsl_if_3 = 0UL;
    else __gen_e_acsl_if_3 = __gen_e_acsl_size_3;
    __gen_e_acsl_valid_read_2 = __e_acsl_valid_read((void *)(src + 1 * 0),
                                                    __gen_e_acsl_if_3,
                                                    (void *)src,
                                                    (void *)(& src));
    /*@ assert E_ACSL: separated_guard: \valid_read(src + (0 .. n - 1)); */
    __e_acsl_assert(__gen_e_acsl_valid_read_2,"RTE","strncpy",
                    "separated_guard: \\valid_read(src + (0 .. n - 1))",
                    "FRAMAC_SHARE/libc/string.h",366);
    __gen_e_acsl__6 = __gmpz_get_ui((__e_acsl_mpz_struct const *)(__gen_e_acsl_add));
    __gen_e_acsl_size_4 = 1UL * __gen_e_acsl__6;
    if (__gen_e_acsl_size_4 <= 0UL) __gen_e_acsl_if_4 = 0UL;
    else __gen_e_acsl_if_4 = __gen_e_acsl_size_4;
    __gen_e_acsl__7 = __gmpz_get_ui((__e_acsl_mpz_struct const *)(__gen_e_acsl_add));
    __gen_e_acsl_size_5 = 1UL * __gen_e_acsl__7;
    if (__gen_e_acsl_size_5 <= 0UL) __gen_e_acsl_if_5 = 0UL;
    else __gen_e_acsl_if_5 = __gen_e_acsl_size_5;
    __gen_e_acsl_separated = __e_acsl_separated((size_t)2,dest + 1 * 0,
                                                __gen_e_acsl_if_4,
                                                src + 1 * 0,
                                                __gen_e_acsl_if_5);
    __e_acsl_assert(__gen_e_acsl_separated,"Precondition","strncpy",
                    "\\separated(dest + (0 .. n - 1), src + (0 .. n - 1))",
                    "FRAMAC_SHARE/libc/string.h",366);
    __gmpz_clear(__gen_e_acsl_n);
    __gmpz_clear(__gen_e_acsl_);
    __gmpz_clear(__gen_e_acsl_sub);
    __gmpz_clear(__gen_e_acsl__2);
    __gmpz_clear(__gen_e_acsl_sub_2);
    __gmpz_clear(__gen_e_acsl_add);
  }
  {
    __e_acsl_mpz_t __gen_e_acsl_n_2;
    __gmpz_init_set_ui(__gen_e_acsl_n_2,n);
    __gmpz_init_set(__gen_e_acsl_at_3,
                    (__e_acsl_mpz_struct const *)(__gen_e_acsl_n_2));
    __gmpz_clear(__gen_e_acsl_n_2);
  }
  __gen_e_acsl_at_2 = dest;
  __gen_e_acsl_at = dest;
  __retres = strncpy(dest,src,n);
  {
    unsigned long __gen_e_acsl_size_6;
    __e_acsl_mpz_t __gen_e_acsl__8;
    __e_acsl_mpz_t __gen_e_acsl_sub_3;
    __e_acsl_mpz_t __gen_e_acsl__9;
    __e_acsl_mpz_t __gen_e_acsl_sub_4;
    __e_acsl_mpz_t __gen_e_acsl_add_2;
    unsigned long __gen_e_acsl__10;
    unsigned long __gen_e_acsl_if_6;
    int __gen_e_acsl_initialized;
    __e_acsl_assert(__retres == __gen_e_acsl_at,"Postcondition","strncpy",
                    "\\result == \\old(dest)","FRAMAC_SHARE/libc/string.h",
                    369);
    __gmpz_init_set_si(__gen_e_acsl__8,1L);
    __gmpz_init(__gen_e_acsl_sub_3);
    __gmpz_sub(__gen_e_acsl_sub_3,
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_at_3),
               (__e_acsl_mpz_struct const *)(__gen_e_acsl__8));
    __gmpz_init_set_si(__gen_e_acsl__9,0L);
    __gmpz_init(__gen_e_acsl_sub_4);
    __gmpz_sub(__gen_e_acsl_sub_4,
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_sub_3),
               (__e_acsl_mpz_struct const *)(__gen_e_acsl__9));
    __gmpz_init(__gen_e_acsl_add_2);
    __gmpz_add(__gen_e_acsl_add_2,
               (__e_acsl_mpz_struct const *)(__gen_e_acsl_sub_4),
               (__e_acsl_mpz_struct const *)(__gen_e_acsl__8));
    __gen_e_acsl__10 = __gmpz_get_ui((__e_acsl_mpz_struct const *)(__gen_e_acsl_add_2));
    __gen_e_acsl_size_6 = 1UL * __gen_e_acsl__10;
    if (__gen_e_acsl_size_6 <= 0UL) __gen_e_acsl_if_6 = 0UL;
    else __gen_e_acsl_if_6 = __gen_e_acsl_size_6;
    __gen_e_acsl_initialized = __e_acsl_initialized((void *)(__gen_e_acsl_at_2 + 
                                                             1 * 0),
                                                    __gen_e_acsl_if_6);
    __e_acsl_assert(__gen_e_acsl_initialized,"Postcondition","strncpy",
                    "\\initialized(\\old(dest) + (0 .. \\old(n) - 1))",
                    "FRAMAC_SHARE/libc/string.h",370);
    __e_acsl_contract_clean(__gen_e_acsl_contract);
    __e_acsl_delete_block((void *)(& src));
    __e_acsl_delete_block((void *)(& dest));
    __gmpz_clear(__gen_e_acsl__8);
    __gmpz_clear(__gen_e_acsl_sub_3);
    __gmpz_clear(__gen_e_acsl__9);
    __gmpz_clear(__gen_e_acsl_sub_4);
    __gmpz_clear(__gen_e_acsl_add_2);
    __gmpz_clear(__gen_e_acsl_at_3);
    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 = "Test Code";
    __e_acsl_store_block((void *)__gen_e_acsl_literal_string,
                         sizeof("Test Code"));
    __e_acsl_full_init((void *)__gen_e_acsl_literal_string);
    __e_acsl_mark_readonly((void *)__gen_e_acsl_literal_string);
  }
  return;
}

int main(void)
{
  int __retres;
  int i;
  __e_acsl_memory_init((int *)0,(char ***)0,(size_t)8);
  __e_acsl_globals_init();
  char *srcbuf = (char *)__gen_e_acsl_literal_string;
  __e_acsl_store_block((void *)(& srcbuf),(size_t)8);
  __e_acsl_full_init((void *)(& srcbuf));
  int loc = 1;
  char *destbuf = malloc((unsigned long)10 * sizeof(char));
  __e_acsl_store_block((void *)(& destbuf),(size_t)8);
  __e_acsl_full_init((void *)(& destbuf));
  char ch = (char)'o';
  if (destbuf != (char *)0) {
    i = -1;
    while (i < 0) {
      {
        int __gen_e_acsl_valid_read;
        __gen_e_acsl_valid_read = __e_acsl_valid_read((void *)(srcbuf + i),
                                                      sizeof(char),
                                                      (void *)srcbuf,
                                                      (void *)(& srcbuf));
        __e_acsl_assert(! __gen_e_acsl_valid_read,"Assertion","main",
                        "!\\valid_read(srcbuf + i)","tests/bts/bts2252.c",17);
      }
      /*@ assert ¬\valid_read(srcbuf + i); */ ;
      /*@ assert Eva: mem_access: \valid_read(srcbuf + i); */
      if ((int)*(srcbuf + i) == (int)ch) loc = i;
      i ++;
    }
    __gen_e_acsl_strncpy(destbuf + loc,(char const *)(srcbuf + loc),
                         (unsigned long)1);
    free((void *)destbuf);
  }
  __retres = 0;
  __e_acsl_delete_block((void *)(& destbuf));
  __e_acsl_delete_block((void *)(& srcbuf));
  __e_acsl_memory_clean();
  return __retres;
}


