#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 foo(int, int);
int main(int level) {
  int i;
  int fval[4];
  for (i = 3; i >= 0; i--)
    fval[i] = foo(level - 1, level * 4 + i + 1);
  for (i = 0; i < 4; ++i)
    foo(0, fval[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1162 <main+0x52>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
shl    $0x2,%esi
add    -0xc(%rbp),%esi
add    $0x1,%esi
call   1030 <foo@plt>
mov    %eax,%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <main+0x19>
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    1190 <main+0x80>
movslq -0xc(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
xor    %edi,%edi
call   1030 <foo@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <main+0x59>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
mov    %edi,%ebp
add    $0xffffffff,%ebp
lea    0x1(,%rbx,4),%r15d
lea    0x4(,%rbx,4),%esi
mov    %ebp,%edi
call   1030 <foo@plt>
mov    %eax,%r14d
lea    0x3(,%rbx,4),%esi
mov    %ebp,%edi
call   1030 <foo@plt>
mov    %eax,%r12d
lea    0x2(,%rbx,4),%esi
mov    %ebp,%edi
call   1030 <foo@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15d,%esi
call   1030 <foo@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1030 <foo@plt>
xor    %edi,%edi
mov    %ebx,%esi
call   1030 <foo@plt>
xor    %edi,%edi
mov    %r12d,%esi
call   1030 <foo@plt>
xor    %edi,%edi
mov    %r14d,%esi
call   1030 <foo@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x i32]
store i32 0, i32* %2
store i32 %0, i32* %3
store i32 3, i32* %4
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 1
%12 = load i32, i32* %3
%13 = mul nsw i32 %12, 4
%14 = load i32, i32* %4
%15 = add nsw i32 %13, %14
%16 = add nsw i32 %15, 1
%17 = call i32 @foo(i32 %11, i32 %16)
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %9
%22 = load i32, i32* %4
%23 = add nsw i32 %22, -1
store i32 %23, i32* %4
br label %6
24: ; preds = %6
store i32 0, i32* %4
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = call i32 @foo(i32 0, i32 %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %25
37: ; preds = %25
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0) {
%2 = add nsw i32 %0, -1
%3 = shl nsw i32 %0, 2
%4 = or i32 %3, 1
%5 = add i32 %3, 4
%6 = tail call i32 @foo(i32 %2, i32 %5)
%7 = or i32 %3, 3
%8 = tail call i32 @foo(i32 %2, i32 %7)
%9 = or i32 %3, 2
%10 = tail call i32 @foo(i32 %2, i32 %9)
%11 = tail call i32 @foo(i32 %2, i32 %4)
%12 = tail call i32 @foo(i32 0, i32 %11)
%13 = tail call i32 @foo(i32 0, i32 %10)
%14 = tail call i32 @foo(i32 0, i32 %8)
%15 = tail call i32 @foo(i32 0, i32 %6)
ret i32 0
}