#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 tmp) {
  int *x_ref = alloca(sizeof(int));
  int *y_ref = alloca(sizeof(int));
  int *tmp_ref = alloca(sizeof(int));
  *x_ref = x;
  *y_ref = y;
  *tmp_ref = tmp;
  while (*x_ref > *y_ref) {
    *tmp_ref = *x_ref;
    *x_ref = *y_ref;
    *y_ref = *tmp_ref;
  }
  return *tmp_ref;
}


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(%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    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jle    11a1 <test_fun+0x91>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1166 <test_fun+0x56>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fun>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r12d
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    %r12d,(%r14)
mov    %r15d,(%rbx)
mov    %ebp,(%rax)
mov    (%r14),%ecx
cmp    (%rbx),%ecx
jle    1174 <test_fun+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,(%rax)
mov    (%rbx),%ecx
mov    %ecx,(%r14)
mov    (%rax),%edx
mov    %edx,(%rbx)
mov    (%r14),%ecx
cmp    %edx,%ecx
jg     1160 <test_fun+0x50>
mov    (%rax),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
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*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = call i32* @alloca(i32 4)
store i32* %10, i32** %7
%11 = call i32* @alloca(i32 4)
store i32* %11, i32** %8
%12 = call i32* @alloca(i32 4)
store i32* %12, i32** %9
%13 = load i32, i32* %4
%14 = load i32*, i32** %7
store i32 %13, i32* %14
%15 = load i32, i32* %5
%16 = load i32*, i32** %8
store i32 %15, i32* %16
%17 = load i32, i32* %6
%18 = load i32*, i32** %9
store i32 %17, i32* %18
br label %19
19: ; preds = %25, %3
%20 = load i32*, i32** %7
%21 = load i32, i32* %20
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = icmp sgt i32 %21, %23
br i1 %24, label %25, label %35
25: ; preds = %19
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = load i32*, i32** %9
store i32 %27, i32* %28
%29 = load i32*, i32** %8
%30 = load i32, i32* %29
%31 = load i32*, i32** %7
store i32 %30, i32* %31
%32 = load i32*, i32** %9
%33 = load i32, i32* %32
%34 = load i32*, i32** %8
store i32 %33, i32* %34
br label %19
35: ; preds = %19
%36 = load i32*, i32** %9
%37 = load i32, i32* %36
ret i32 %37
}

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)
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = icmp sgt i32 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %3, %10
%11 = phi i32 [ %14, %10 ], [ %7, %3 ]
store i32 %11, i32* %6
%12 = load i32, i32* %5
store i32 %12, i32* %4
%13 = load i32, i32* %6
store i32 %13, i32* %5
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, %13
br i1 %15, label %10, label %16
16: ; preds = %10
%17 = load i32, i32* %6
br label %18
18: ; preds = %16, %3
%19 = phi i32 [ %17, %16 ], [ %2, %3 ]
ret i32 %19
}