#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 x) {
  int a = 0, b = 1, c = 0;
  if (x <= 0) {
    return;
  }
  if (x == 1) {
    printf("%d\n", a);
    return;
  } else if (x == 2) {
    printf("%d %d\n", a, b);
    return;
  }
  printf("%d %d ", a, b);
  for (int i = 3; i <= x; i++) {
    c = a + b;
    printf("%d ", c);
    a = b;
    b = c;
  }
  printf("\n");
}


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)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     113f <fib+0x2f>
jmp    11f0 <fib+0xe0>
cmpl   $0x1,-0x4(%rbp)
jne    115f <fib+0x4f>
mov    -0x8(%rbp),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <fib+0xe0>
cmpl   $0x2,-0x4(%rbp)
jne    1182 <fib+0x72>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <fib+0xe0>
jmp    1187 <fib+0x77>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11e2 <fib+0xd2>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe49(%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    11a2 <fib+0x92>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    1152 <fib+0x32>
mov    %edi,%r15d
cmp    $0x2,%edi
je     115b <fib+0x3b>
cmp    $0x1,%r15d
jne    1178 <fib+0x58>
lea    0xec2(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9e(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe88(%rip),%rdi
mov    $0x1,%ebx
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xfffffffe,%r15d
lea    0xe6d(%rip),%r14
xor    %ebp,%ebp
nop
mov    %ebx,%r12d
add    %ebx,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ebx
mov    %r12d,%ebp
add    $0xffffffff,%r15d
jne    11a0 <fib+0x80>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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