#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, ...);
void fib(int n) {
  int num1 = 0, num2 = 1, num3, i;
  printf("%d %d ", num1, num2);
  for (i = 3; i <= n; i++) {
    num3 = num1 + num2;
    printf("%d ", num3);
    num1 = num2;
    num2 = num3;
  }
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1184 <fib+0x74>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <fib+0x34>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xee0(%rip),%rdi
mov    $0x1,%r15d
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x3,%ebx
jl     116c <fib+0x5c>
add    $0xfffffffe,%ebx
lea    0xec0(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%ebp
add    %r15d,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15d,%eax
mov    %ebp,%r15d
add    $0xffffffff,%ebx
jne    1150 <fib+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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