#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 r) {
  int *x_ref = alloca(sizeof(int));
  int *y_ref = alloca(sizeof(int));
  int *r_ref = alloca(sizeof(int));
  r = 1;
  *x_ref = x;
  *y_ref = y;
  *r_ref = r;
  while (*y_ref > 0) {
    *r_ref = (*r_ref) * (*x_ref);
    *y_ref = *y_ref - 1;
  }
  return *r_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)
movl   $0x1,-0xc(%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    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11a1 <test_fun+0x91>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
imul   (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    116d <test_fun+0x5d>
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   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebp
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,(%r14)
mov    %r15d,(%rbx)
movl   $0x1,(%rax)
cmpl   $0x0,(%rbx)
jle    1176 <test_fun+0x66>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
imul   (%r14),%ecx
mov    %ecx,(%rax)
mov    (%rbx),%edx
lea    -0x1(%rdx),%ecx
mov    %ecx,(%rbx)
mov    (%rax),%ecx
cmp    $0x1,%edx
jg     1160 <test_fun+0x50>
jmp    117b <test_fun+0x6b>
mov    $0x1,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
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
store i32 1, i32* %6
%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 = %23, %3
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32*, i32** %9
%25 = load i32, i32* %24
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = mul nsw i32 %25, %27
%29 = load i32*, i32** %9
store i32 %28, i32* %29
%30 = load i32*, i32** %8
%31 = load i32, i32* %30
%32 = sub nsw i32 %31, 1
%33 = load i32*, i32** %8
store i32 %32, i32* %33
br label %19
34: ; preds = %19
%35 = load i32*, i32** %9
%36 = load i32, i32* %35
ret i32 %36
}

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