#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) {
    *x_ref = *x_ref + 1;
    *y_ref = 1;
    while (*x_ref > *y_ref) {
      *y_ref = *y_ref + 1;
      *c = *c + 1;
    }
    *x_ref = *x_ref - 2;
  }
  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)
jl     11d3 <test_fun+0xc3>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    11bf <test_fun+0xaf>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $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    118a <test_fun+0x7a>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    $0x2,%ecx
mov    -0x10(%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),%ecx
test   %ecx,%ecx
js     119e <test_fun+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ecx
mov    %ecx,(%r14)
movl   $0x1,(%rbx)
mov    (%r14),%ecx
cmp    $0x2,%ecx
jl     11a2 <test_fun+0x92>
mov    $0x1,%ecx
nopl   0x0(%rax)
add    $0x1,%ecx
mov    %ecx,(%rbx)
addl   $0x1,(%rax)
mov    (%r14),%edx
mov    (%rbx),%ecx
cmp    %ecx,%edx
jg     1180 <test_fun+0x70>
lea    -0x2(%rdx),%ecx
mov    %ecx,(%r14)
cmp    $0x1,%edx
jg     1160 <test_fun+0x50>
jmp    11a8 <test_fun+0x98>
xor    %eax,%eax
jmp    11aa <test_fun+0x9a>
add    $0xfffffffe,%ecx
mov    %ecx,(%r14)
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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 = %41, %2
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %16
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
%24 = load i32*, i32** %5
store i32 %23, i32* %24
%25 = load i32*, i32** %6
store i32 1, i32* %25
br label %26
26: ; preds = %32, %20
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = icmp sgt i32 %28, %30
br i1 %31, label %32, label %41
32: ; preds = %26
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
%36 = load i32*, i32** %6
store i32 %35, i32* %36
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = add nsw i32 %38, 1
%40 = load i32*, i32** %7
store i32 %39, i32* %40
br label %26
41: ; preds = %26
%42 = load i32*, i32** %5
%43 = load i32, i32* %42
%44 = sub nsw i32 %43, 2
%45 = load i32*, i32** %5
store i32 %44, i32* %45
br label %16
46: ; preds = %16
%47 = load i32*, i32** %7
%48 = load i32, i32* %47
ret i32 %48
}

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