#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 *alloca(int);
int test_fun(int x, int y, int z) {
  int *x_ref = alloca(sizeof(int));
  int *y_ref = alloca(sizeof(int));
  int *z_ref = alloca(sizeof(int));
  int *c = alloca(sizeof(int));
  *x_ref = x;
  *y_ref = y;
  *z_ref = z;
  *c = 0;
  while (*x_ref > *y_ref + *z_ref) {
    *y_ref = *y_ref + 1;
    *z_ref = *z_ref + 1;
    *c = *c + 1;
  }
  return *c;
}


x86 assembly (clang, -O0):
<test_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x28(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    -0x28(%rbp),%rdx
add    (%rdx),%ecx
cmp    %ecx,%eax
jle    11ca <test_fun+0xba>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
jmp    117e <test_fun+0x6e>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fun>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r13d
mov    %edi,%ebp
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%r15
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %ebp,(%r14)
mov    %r13d,(%r15)
mov    %r12d,(%rbx)
movl   $0x0,(%rax)
mov    (%r15),%edx
mov    (%rbx),%esi
add    %edx,%esi
xor    %ecx,%ecx
cmp    %esi,(%r14)
jle    119c <test_fun+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%edx
mov    %edx,(%r15)
addl   $0x1,(%rbx)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    (%r15),%edx
mov    (%rbx),%esi
add    %edx,%esi
cmp    %esi,(%r14)
jg     1180 <test_fun+0x70>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_fun(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = call i32* @alloca(i32 4)
store i32* %11, i32** %7
%12 = call i32* @alloca(i32 4)
store i32* %12, i32** %8
%13 = call i32* @alloca(i32 4)
store i32* %13, i32** %9
%14 = call i32* @alloca(i32 4)
store i32* %14, i32** %10
%15 = load i32, i32* %4
%16 = load i32*, i32** %7
store i32 %15, i32* %16
%17 = load i32, i32* %5
%18 = load i32*, i32** %8
store i32 %17, i32* %18
%19 = load i32, i32* %6
%20 = load i32*, i32** %9
store i32 %19, i32* %20
%21 = load i32*, i32** %10
store i32 0, i32* %21
br label %22
22: ; preds = %31, %3
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = load i32*, i32** %8
%26 = load i32, i32* %25
%27 = load i32*, i32** %9
%28 = load i32, i32* %27
%29 = add nsw i32 %26, %28
%30 = icmp sgt i32 %24, %29
br i1 %30, label %31, label %44
31: ; preds = %22
%32 = load i32*, i32** %8
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
%35 = load i32*, i32** %8
store i32 %34, i32* %35
%36 = load i32*, i32** %9
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
%39 = load i32*, i32** %9
store i32 %38, i32* %39
%40 = load i32*, i32** %10
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
%43 = load i32*, i32** %10
store i32 %42, i32* %43
br label %22
44: ; preds = %22
%45 = load i32*, i32** %10
%46 = load i32, i32* %45
ret i32 %46
}

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