#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 print_fibonacci(int index) {
  if (index <= 0) {
    return;
  }
  int resultA, resultB;
  resultA = 0;
  printf("%d", resultA);
  if (index <= 1) {
    return;
  }
  resultB = 1;
  printf(" ,%d", resultB);
  if (index <= 2) {
    return;
  }
  for (int i = 3; i <= index; i++) {
    int current = resultA + resultB;
    printf(" ,%d", current);
    resultA = resultB;
    resultB = current;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     112a <print_fibonacci+0x1a>
jmp    11cd <print_fibonacci+0xbd>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
jg     1151 <print_fibonacci+0x41>
jmp    11cd <print_fibonacci+0xbd>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x4(%rbp)
jg     1178 <print_fibonacci+0x68>
jmp    11cd <print_fibonacci+0xbd>
movl   $0x3,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11bf <print_fibonacci+0xaf>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117f <print_fibonacci+0x6f>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_fibonacci>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1162 <print_fibonacci+0x42>
mov    %edi,%r15d
lea    0xecd(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r15d
je     1162 <print_fibonacci+0x42>
lea    0xeb5(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%r15d
jae    116d <print_fibonacci+0x4d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xfffffffe,%r15d
lea    0xe88(%rip),%r14
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebp
add    %ebx,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
mov    %ebp,%ebx
add    $0xffffffff,%r15d
jne    1180 <print_fibonacci+0x60>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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