#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 fib(int n) {
  if (n == 1) {
    printf("0\n");
  } else if (n == 2) {
    printf("0\n1\n");
  } else {
    printf("0\n1\n");
    long s = 0;
    long p = 1;
    int i;
    for (i = 3; i <= n; i++) {
      long q = s + p;
      printf("%ld\n", q);
      s = p;
      p = q;
    }
  }
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1138 <fib+0x28>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cc <fib+0xbc>
cmpl   $0x2,-0x4(%rbp)
jne    1155 <fib+0x45>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c7 <fib+0xb7>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11c2 <fib+0xb2>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <fib+0x6a>
jmp    11c7 <fib+0xb7>
jmp    11cc <fib+0xbc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
je     118a <fib+0x6a>
mov    %edi,%r15d
lea    0xecf(%rip),%rdi
cmp    $0x2,%r15d
je     1191 <fib+0x71>
call   1030 <puts@plt>
cmp    $0x3,%r15d
jl     117f <fib+0x5f>
add    $0xfffffffe,%r15d
mov    $0x1,%ebp
lea    0xea9(%rip),%r14
xor    %eax,%eax
nopl   0x0(%rax)
mov    %rax,%rbx
add    %rbp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
mov    %rbx,%rbp
add    $0xffffffff,%r15d
jne    1160 <fib+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe78(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

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