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


x86 assembly (clang, -O0):
<fib2_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
cmpl   $0x0,-0x8(%rbp)
jne    115f <fib2_helper+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <fib2_helper+0x85>
cmpl   $0x1,-0x8(%rbp)
jne    1175 <fib2_helper+0x55>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <fib2_helper+0x85>
jmp    117a <fib2_helper+0x5a>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fib2_helper@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fib2_helper@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib2_helper>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ebp,%ebp
lea    0xecb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
addl   $0x1,(%r14)
cmp    $0x2,%ebx
jb     1165 <fib2_helper+0x45>
lea    -0x1(%rbx),%edi
mov    %r14,%rsi
call   1040 <fib2_helper@plt>
add    %eax,%ebp
add    $0xfffffffe,%ebx
jmp    1140 <fib2_helper+0x20>
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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