#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 __VERIFIER_nondet_int();
int *alloca(int);
int test_fun(int x, int tmp) {
  int *x_ref = alloca(sizeof(int));
  int *tmp_ref = alloca(sizeof(int));
  *x_ref = x;
  *tmp_ref = tmp;
  *tmp_ref = __VERIFIER_nondet_int();
  while ((*x_ref > 0) && (x == 2 * (*tmp_ref))) {
    *x_ref = *x_ref - 1;
    *tmp_ref = __VERIFIER_nondet_int();
  }
  return *x_ref;
}


x86 assembly (clang, -O0):
<test_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <__VERIFIER_nondet_int@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,(%rcx)
mov    %al,-0x19(%rbp)
jle    1191 <test_fun+0x71>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a1 <test_fun+0x81>
jmp    11c4 <test_fun+0xa4>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <__VERIFIER_nondet_int@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    116b <test_fun+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fun>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbp
mov    %r14d,(%rbx)
mov    %r15d,(%rax)
nopl   (%rax)
xor    %eax,%eax
call   1040 <__VERIFIER_nondet_int@plt>
mov    %eax,%ecx
mov    %eax,0x0(%rbp)
mov    (%rbx),%eax
test   %eax,%eax
jle    1170 <test_fun+0x50>
add    %ecx,%ecx
cmp    %r14d,%ecx
jne    1170 <test_fun+0x50>
add    $0xffffffff,%eax
mov    %eax,(%rbx)
jmp    1150 <test_fun+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_fun(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i32* @alloca(i32 4)
store i32* %7, i32** %5
%8 = call i32* @alloca(i32 4)
store i32* %8, i32** %6
%9 = load i32, i32* %3
%10 = load i32*, i32** %5
store i32 %9, i32* %10
%11 = load i32, i32* %4
%12 = load i32*, i32** %6
store i32 %11, i32* %12
%13 = call i32 (...) @__VERIFIER_nondet_int()
%14 = load i32*, i32** %6
store i32 %13, i32* %14
br label %15
15: ; preds = %27, %2
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i32, i32* %3
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = mul nsw i32 2, %22
%24 = icmp eq i32 %20, %23
br label %25
25: ; preds = %19, %15
%26 = phi i1 [ false, %15 ], [ %24, %19 ]
br i1 %26, label %27, label %34
27: ; preds = %25
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, 1
%31 = load i32*, i32** %5
store i32 %30, i32* %31
%32 = call i32 (...) @__VERIFIER_nondet_int()
%33 = load i32*, i32** %6
store i32 %32, i32* %33
br label %15
34: ; preds = %25
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
ret i32 %36
}

LLVM IR (-O2):
define i32 @test_fun(i32 %0, i32 %1) {
%3 = tail call i32* @alloca(i32 4)
%4 = tail call i32* @alloca(i32 4)
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = tail call i32 (...) @__VERIFIER_nondet_int()
store i32 %5, i32* %4
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 0
%8 = shl nsw i32 %5, 1
%9 = icmp eq i32 %8, %0
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %20
11: ; preds = %2, %11
%12 = phi i32 [ %15, %11 ], [ %6, %2 ]
%13 = add nsw i32 %12, -1
store i32 %13, i32* %3
%14 = tail call i32 (...) @__VERIFIER_nondet_int()
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
%17 = shl nsw i32 %14, 1
%18 = icmp eq i32 %17, %0
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %11, label %20
20: ; preds = %11, %2
%21 = phi i32 [ %6, %2 ], [ %15, %11 ]
ret i32 %21
}