#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) {
    if (*x_ref < *z_ref) {
      *x_ref = *x_ref + 1;
    } else {
      *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
cmp    (%rcx),%eax
jge    11d9 <test_fun+0xc9>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jge    11b6 <test_fun+0xa6>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11c5 <test_fun+0xb5>
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,%r15
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %ebp,(%r15)
mov    %r13d,(%r14)
mov    %r12d,(%rbx)
movl   $0x0,(%rax)
mov    (%r15),%edx
xor    %ecx,%ecx
cmp    (%r14),%edx
jge    1192 <test_fun+0x82>
nopl   (%rax)
mov    (%rbx),%ecx
cmp    %ecx,%edx
cmovl  %edx,%ecx
mov    %rbx,%rdx
cmovl  %r15,%rdx
add    $0x1,%ecx
mov    %ecx,(%rdx)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    (%r15),%edx
cmp    (%r14),%edx
jl     1170 <test_fun+0x60>
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 = %44, %3
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = load i32*, i32** %8
%26 = load i32, i32* %25
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %49
28: ; preds = %22
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = load i32*, i32** %9
%32 = load i32, i32* %31
%33 = icmp slt i32 %30, %32
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i32*, i32** %7
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
%38 = load i32*, i32** %7
store i32 %37, i32* %38
br label %44
39: ; preds = %28
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
%43 = load i32*, i32** %9
store i32 %42, i32* %43
br label %44
44: ; preds = %39, %34
%45 = load i32*, i32** %10
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1
%48 = load i32*, i32** %10
store i32 %47, i32* %48
br label %22
49: ; preds = %22
%50 = load i32*, i32** %10
%51 = load i32, i32* %50
ret i32 %51
}

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 = icmp slt i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %3, %11
%12 = phi i32 [ %20, %11 ], [ %8, %3 ]
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
%15 = select i1 %14, i32 %12, i32 %13
%16 = select i1 %14, i32* %4, i32* %6
%17 = add nsw i32 %15, 1
store i32 %17, i32* %16
%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 = icmp slt i32 %20, %21
br i1 %22, label %11, label %23
23: ; preds = %11, %3
%24 = phi i32 [ 0, %3 ], [ %19, %11 ]
ret i32 %24
}