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


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,%edi
call   1030 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11c9 <test_fun+0xb9>
jmp    1176 <test_fun+0x66>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11a6 <test_fun+0x96>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1176 <test_fun+0x66>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1164 <test_fun+0x54>
mov    -0x20(%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,%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   $0x0,(%rax)
mov    (%r14),%edx
test   %edx,%edx
jg     1184 <test_fun+0x74>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%edx
mov    %edx,(%r14)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    (%r14),%edx
test   %edx,%edx
jle    1155 <test_fun+0x45>
mov    (%rbx),%ecx
test   %ecx,%ecx
jle    1170 <test_fun+0x60>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ecx
mov    %ecx,(%rbx)
addl   $0x1,(%rax)
mov    (%rbx),%ecx
test   %ecx,%ecx
jg     1190 <test_fun+0x80>
mov    (%r14),%edx
jmp    1170 <test_fun+0x60>

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

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)
%5 = tail call i32* @alloca(i32 4)
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %2, %21
%9 = phi i32 [ %26, %21 ], [ %6, %2 ]
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8, %12
%13 = phi i32 [ %17, %12 ], [ %10, %8 ]
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %12
%20 = load i32, i32* %3
br label %21
21: ; preds = %19, %8
%22 = phi i32 [ %20, %19 ], [ %9, %8 ]
%23 = add nsw i32 %22, -1
store i32 %23, i32* %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br i1 %27, label %8, label %28
28: ; preds = %21, %2
%29 = phi i32 [ 0, %2 ], [ %25, %21 ]
ret i32 %29
}