#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 fibrec(int n) {
  printf("fib(%d)\n", n);
  if ((n == 1) || (n == 0)) {
    return 1;
  } else {
    return fibrec(n - 1) + fibrec(n - 2);
  }
}


x86 assembly (clang, -O0):
<fibrec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
je     114e <fibrec+0x2e>
cmpl   $0x0,-0x8(%rbp)
jne    115a <fibrec+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    117d <fibrec+0x5d>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fibrec@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1040 <fibrec@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):
<fibrec>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xed3(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%ebp
cmp    $0x2,%ebx
jb     116f <fibrec+0x4f>
xor    %ebp,%ebp
lea    0xeb9(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%edi
call   1040 <fibrec@plt>
add    $0xfffffffe,%ebx
add    %eax,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
cmp    $0x1,%ebx
ja     1150 <fibrec+0x30>
add    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"fib(%d)\0A\00"
define i32 @fibrec(i32 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp ult i32 %0, 2
br i1 %3, label %15, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %9, %4 ], [ %0, %1 ]
%6 = phi i32 [ %10, %4 ], [ 0, %1 ]
%7 = add nsw i32 %5, -1
%8 = tail call i32 @fibrec(i32 %7)
%9 = add nsw i32 %5, -2
%10 = add nsw i32 %8, %6
%11 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
%12 = icmp ult i32 %9, 2
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = add i32 %10, 1
br label %15
15: ; preds = %13, %1
%16 = phi i32 [ 1, %1 ], [ %14, %13 ]
ret i32 %16
}