#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
uint32_t fib_rec(uint8_t n) {
  if (n > 46) {
    fprintf(stderr, "I cannot compute fib(%d). I need more bits", n);
    exit(-1);
  } else if (n == 0) {
    return 0;
  } else if (n == 1) {
    return 1;
  } else {
    return fib_rec(n - 1) + fib_rec(n - 2);
  }
}


x86 assembly (clang, -O0):
<fib_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2e,-0x8(%rbp)
jle    1167 <fib_rec+0x37>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    117d <fib_rec+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <fib_rec+0x86>
cmpl   $0x1,-0x8(%rbp)
jne    1193 <fib_rec+0x63>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <fib_rec+0x86>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <fib_rec@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1030 <fib_rec@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib_rec>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x2e,%edi
jg     116d <fib_rec+0x3d>
xor    %ebp,%ebp
cmp    $0x2,%ebx
jb     1162 <fib_rec+0x32>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%edi
call   1030 <fib_rec@plt>
add    %eax,%ebp
add    $0xfffffffe,%ebx
cmp    $0x2,%ebx
jae    1150 <fib_rec+0x20>
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"I cannot compute fib(%d). I need more bits\00"
define i32 @fib_rec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sgt i32 %4, 46
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* %3
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 0, i32* %2
br label %27
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %2
br label %27
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = call i32 @fib_rec(i32 %21)
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 2
%25 = call i32 @fib_rec(i32 %24)
%26 = add nsw i32 %22, %25
store i32 %26, i32* %2
br label %27
27: ; preds = %19, %18, %14
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"I cannot compute fib(%d). I need more bits\00"
define i32 @fib_rec(i32 %0) {
%2 = icmp sgt i32 %0, 46
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %1, %11
%8 = phi i32 [ %14, %11 ], [ %0, %1 ]
%9 = phi i32 [ %15, %11 ], [ 0, %1 ]
%10 = icmp ult i32 %8, 2
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = add nsw i32 %8, -1
%13 = tail call i32 @fib_rec(i32 %12)
%14 = add nsw i32 %8, -2
%15 = add nsw i32 %13, %9
br label %7
16: ; preds = %7
%17 = add nsw i32 %8, %9
ret i32 %17
}