#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 /*<<< orphan*/ printf(char *, int *, int);
int fibonacci(int n) {
  printf("local variable n at %p has value %d\n", &n, n);
  if (n <= 1) {
    return n;
  } else {
    int a = fibonacci(n - 1);
    int b = fibonacci(n - 2);
    return a + b;
  }
}


x86 assembly (clang, -O0):
<fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edx
lea    0xecb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jg     1153 <fibonacci+0x33>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <fibonacci+0x58>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fibonacci@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1040 <fibonacci@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%edx
mov    %edi,0xc(%rsp)
lea    0xece(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jl     115f <fibonacci+0x3f>
add    $0xffffffff,%eax
mov    %eax,%edi
call   1040 <fibonacci@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
add    $0xfffffffe,%edi
call   1040 <fibonacci@plt>
add    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"local variable n at %p has value %d\0A\00"
define i32 @fibonacci(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32* %3, i32 %6)
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %3
store i32 %11, i32* %2
br label %22
12: ; preds = %1
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 1
%15 = call i32 @fibonacci(i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 2
%18 = call i32 @fibonacci(i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
store i32 %21, i32* %2
br label %22
22: ; preds = %12, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [37 x i8] c"local variable n at %p has value %d\0A\00"
define i32 @fibonacci(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32* %2, i32 %0)
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 2
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = add nsw i32 %4, -1
%8 = call i32 @fibonacci(i32 %7)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -2
%11 = call i32 @fibonacci(i32 %10)
%12 = add nsw i32 %11, %8
br label %13
13: ; preds = %1, %6
%14 = phi i32 [ %12, %6 ], [ %4, %1 ]
ret i32 %14
}