#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 fibonacci(int N) {
  int f;
  printf("Entrei em fibonacci(%d)\n", N);
  if (N < 3) {
    printf("Retornando fibonacci(%d) = 1\n", N);
    return 1;
  }
  f = fibonacci(N - 1) + fibonacci(N - 2);
  printf("Retornando fibonacci(%d) = %d\n", N, f);
  return f;
}


x86 assembly (clang, -O0):
<fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jge    1163 <fibonacci+0x43>
mov    -0x8(%rbp),%esi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a0 <fibonacci+0x80>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fibonacci@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1040 <fibonacci@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xed3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebx
jg     1152 <fibonacci+0x32>
lea    0xed7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebp
jmp    117c <fibonacci+0x5c>
lea    -0x1(%rbx),%edi
call   1040 <fibonacci@plt>
mov    %eax,%r14d
lea    -0x2(%rbx),%edi
call   1040 <fibonacci@plt>
mov    %eax,%ebp
add    %r14d,%ebp
lea    0xec6(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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