#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ __ESBMC_assume(int *);
int *malloc(int);
int main() {
  int *a;
  int i, j;
  int k = 2;
  if (k <= 0)
    return -1;
  a = malloc(k * sizeof(int));
  __ESBMC_assume(a);
  for (i = 0; i != k; i++)
    if (a[i] <= 1)
      break;
  i--;
  for (j = 0; j < i; ++j)
    a[j] = a[i];
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     114c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <main+0xcc>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <__ESBMC_assume@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11a5 <main+0x85>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jg     1192 <main+0x72>
jmp    11a5 <main+0x85>
jmp    1197 <main+0x77>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <main+0x4f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e5 <main+0xc5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b5 <main+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <__ESBMC_assume@plt>
cmpl   $0x2,(%rbx)
jl     1146 <main+0x26>
cmpl   $0x2,0x4(%rbx)
jl     1146 <main+0x26>
mov    0x4(%rbx),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %5
%6 = load i32, i32* %5
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %54
9: ; preds = %0
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = call i32 @__ESBMC_assume(i32* %15)
store i32 0, i32* %3
br label %17
17: ; preds = %30, %9
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i32*, i32** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp sle i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %21
br label %33
29: ; preds = %21
br label %30
30: ; preds = %29
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %17
33: ; preds = %28, %17
%34 = load i32, i32* %3
%35 = add nsw i32 %34, -1
store i32 %35, i32* %3
store i32 0, i32* %4
br label %36
36: ; preds = %50, %33
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = load i32*, i32** %2
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = load i32*, i32** %2
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %40
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %36
53: ; preds = %36
store i32 0, i32* %1
br label %54
54: ; preds = %53, %8
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc(i32 8)
%2 = tail call i32 @__ESBMC_assume(i32* %1)
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 2
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = getelementptr inbounds i32, i32* %1, i64 1
%7 = load i32, i32* %6
%8 = icmp slt i32 %7, 2
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = getelementptr inbounds i32, i32* %1, i64 1
%11 = load i32, i32* %10
store i32 %11, i32* %1
br label %12
12: ; preds = %0, %5, %9
ret i32 0
}