#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 */
long long INT_MAX;
long long fibonacci_rec(int n) {
  if (n == 0)
    return 0;
  else if (n == 1)
    return 1;
  else {
    long long int fibo;
    fibo = (fibonacci_rec(n - 1) + fibonacci_rec(n - 2));
    if (fibonacci_rec(n - 1) > INT_MAX && fibo < fibonacci_rec(n - 1)) {
      return -1;
    } else {
      return fibo;
    }
  }
}


x86 assembly (clang, -O0):
<fibonacci_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1132 <fibonacci_rec+0x22>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <fibonacci_rec+0xb4>
cmpl   $0x1,-0xc(%rbp)
jne    1149 <fibonacci_rec+0x39>
movq   $0x1,-0x8(%rbp)
jmp    11c4 <fibonacci_rec+0xb4>
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1030 <fibonacci_rec@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x2,%edi
call   1030 <fibonacci_rec@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1030 <fibonacci_rec@plt>
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jle    11bc <fibonacci_rec+0xac>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1030 <fibonacci_rec@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    11bc <fibonacci_rec+0xac>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c4 <fibonacci_rec+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci_rec>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1126 <fibonacci_rec+0x16>
mov    %edi,%ebx
cmp    $0x1,%edi
jne    112a <fibonacci_rec+0x1a>
mov    $0x1,%eax
jmp    115f <fibonacci_rec+0x4f>
xor    %eax,%eax
jmp    115f <fibonacci_rec+0x4f>
lea    -0x1(%rbx),%edi
call   1030 <fibonacci_rec@plt>
mov    %rax,%r14
add    $0xfffffffe,%ebx
mov    %ebx,%edi
call   1030 <fibonacci_rec@plt>
lea    (%rax,%r14,1),%rcx
mov    0x2e9e(%rip),%rdx
test   %rax,%rax
mov    $0xffffffffffffffff,%rax
cmovns %rcx,%rax
cmp    (%rdx),%r14
cmovle %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i64 @fibonacci_rec(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 0, i64* %2
br label %34
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %8
store i64 1, i64* %2
br label %34
12: ; preds = %8
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 1
%15 = call i64 @fibonacci_rec(i32 %14)
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 2
%18 = call i64 @fibonacci_rec(i32 %17)
%19 = add nsw i64 %15, %18
store i64 %19, i64* %4
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = call i64 @fibonacci_rec(i32 %21)
%23 = load i64, i64* @INT_MAX
%24 = icmp sgt i64 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %12
%26 = load i64, i64* %4
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1
%29 = call i64 @fibonacci_rec(i32 %28)
%30 = icmp slt i64 %26, %29
br i1 %30, label %31, label %32
31: ; preds = %25
store i64 -1, i64* %2
br label %34
32: ; preds = %25, %12
%33 = load i64, i64* %4
store i64 %33, i64* %2
br label %34
34: ; preds = %32, %31, %11, %7
%35 = load i64, i64* %2
ret i64 %35
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i64 @fibonacci_rec(i32 %0) {
switch i32 %0, label %5 [
i32 0, label %3
i32 1, label %2
]
2: ; preds = %1
br label %3
3: ; preds = %2, %1, %5
%4 = phi i64 [ %15, %5 ], [ 1, %2 ], [ 0, %1 ]
ret i64 %4
5: ; preds = %1
%6 = add nsw i32 %0, -1
%7 = tail call i64 @fibonacci_rec(i32 %6)
%8 = add nsw i32 %0, -2
%9 = tail call i64 @fibonacci_rec(i32 %8)
%10 = add nsw i64 %9, %7
%11 = load i64, i64* @INT_MAX
%12 = icmp sgt i64 %7, %11
%13 = icmp slt i64 %9, 0
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i64 -1, i64 %10
br label %3
}