#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 fib(int n) {
  static int i = 0, j = 1, sum = 0;
  if (n > 0) {
    sum = i + j;
    printf("%d\t", sum);
    i = j;
    j = sum;
    fib(n - 1);
  }
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    117c <fib+0x5c>
mov    0x2efd(%rip),%eax
add    0x2eef(%rip),%eax
mov    %eax,0x2ef5(%rip)
mov    0x2eef(%rip),%esi
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ed1(%rip),%eax
mov    %eax,0x2ed3(%rip)
mov    0x2ed1(%rip),%eax
mov    %eax,0x2ebf(%rip)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fib@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1160 <fib+0x50>
mov    %edi,%ebx
mov    0x2f10(%rip),%eax
mov    0x2f02(%rip),%esi
add    $0x1,%ebx
lea    0xed0(%rip),%r14
add    %eax,%esi
mov    %esi,0x2efc(%rip)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    0x2ee2(%rip),%eax
mov    %eax,0x2ee4(%rip)
mov    0x2ee2(%rip),%esi
mov    %esi,0x2ed0(%rip)
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1130 <fib+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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