#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 *, ...);
void fibonacci(int n) {
  int i, a = 1, b = 1, c;
  if (n >= 1)
    printf("1 ");
  if (n >= 2)
    printf("1 ");
  for (i = 3; i <= n; i++) {
    c = a + b;
    printf("%d ", c);
    a = b;
    b = c;
  }
}


x86 assembly (clang, -O0):
<fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     1141 <fibonacci+0x31>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x4(%rbp)
jl     1159 <fibonacci+0x49>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11a0 <fibonacci+0x90>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <fibonacci+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    117b <fibonacci+0x6b>
mov    %edi,%ebx
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x1,%ebx
je     117b <fibonacci+0x6b>
lea    0xec9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x3,%ebx
jb     117b <fibonacci+0x6b>
add    $0xfffffffe,%ebx
mov    $0x1,%eax
lea    0xeb1(%rip),%r14
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
mov    %eax,%r15d
add    %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
mov    %r15d,%ebp
add    $0xffffffff,%ebx
jne    1160 <fibonacci+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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