#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  printf("Fibonacci Series \n");
  printf("\n");
  int i, number;
  int first, second, third;
  printf("Number of Terms (max. 16): ");
  scanf("%d", &number);
  printf("\n");
  number = (number > 16 ? 16 : number);
  if (number < 0) {
    printf("Invalid Input \n");
    printf("\n");
    return 1;
  }
  first = 0;
  second = 1;
  if (number >= 0) {
    printf("fib(0)\t: %d \n", first);
  }
  if (number >= 1) {
    printf("fib(1)\t: %d \n", second);
  }
  for (i = 2; i <= number; i++) {
    third = first + second;
    printf("fib(%d)\t: %d \n", i, third);
    first = second;
    second = third;
  }
  printf("\n");
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x10,-0xc(%rbp)
jle    118e <main+0x6e>
mov    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <main+0x74>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11cc <main+0xac>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x15d>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11f5 <main+0xd5>
mov    -0x10(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0xc(%rbp)
jl     1210 <main+0xf0>
mov    -0x14(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     125a <main+0x13a>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1217 <main+0xf7>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
cmp    $0x10,%eax
mov    $0x10,%ecx
cmovl  %eax,%ecx
mov    %ecx,0xc(%rsp)
test   %ecx,%ecx
js     121d <main+0xdd>
lea    0xe76(%rip),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1211 <main+0xd1>
lea    0xe6a(%rip),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x2,0xc(%rsp)
jl     1211 <main+0xd1>
lea    0xe59(%rip),%r15
mov    $0x1,%eax
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %eax,%r12d
add    $0x1,%ebp
add    %eax,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
mov    %r12d,%ebx
cmp    0xc(%rsp),%ebp
jl     11f0 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    122f <main+0xef>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Fibonacci Series \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [28 x i8] c"Number of Terms (max. 16): \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [16 x i8] c"Invalid Input \0A\00"
@.str.5 = [14 x i8] c"fib(0)\09: %d \0A\00"
@.str.6 = [14 x i8] c"fib(1)\09: %d \0A\00"
@.str.7 = [15 x i8] c"fib(%d)\09: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 16
br i1 %13, label %14, label %15
14: ; preds = %0
br label %17
15: ; preds = %0
%16 = load i32, i32* %3
br label %17
17: ; preds = %15, %14
%18 = phi i32 [ 16, %14 ], [ %16, %15 ]
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %56
24: ; preds = %17
store i32 0, i32* %4
store i32 1, i32* %5
%25 = load i32, i32* %3
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %3
%32 = icmp sge i32 %31, 1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %30
store i32 2, i32* %2
br label %37
37: ; preds = %50, %36
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = icmp sle i32 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i32, i32* %4
%43 = load i32, i32* %5
%44 = add nsw i32 %42, %43
store i32 %44, i32* %6
%45 = load i32, i32* %2
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i32, i32* %5
store i32 %48, i32* %4
%49 = load i32, i32* %6
store i32 %49, i32* %5
br label %50
50: ; preds = %41
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %37
53: ; preds = %37
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %56
56: ; preds = %53, %21
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str.2 = [28 x i8] c"Number of Terms (max. 16): \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [14 x i8] c"fib(0)\09: %d \0A\00"
@.str.6 = [14 x i8] c"fib(1)\09: %d \0A\00"
@.str.7 = [15 x i8] c"fib(%d)\09: %d \0A\00"
@str = [18 x i8] c"Fibonacci Series \00"
@str.8 = [15 x i8] c"Invalid Input \00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @putchar(i32 10)
%4 = bitcast i32* %1 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = call i32 @putchar(i32 10)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 16
%10 = select i1 %9, i32 %8, i32 16
store i32 %10, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %33
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 0)
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 1)
%20 = load i32, i32* %1
%21 = icmp slt i32 %20, 2
br i1 %21, label %31, label %22
22: ; preds = %18, %22
%23 = phi i32 [ %26, %22 ], [ 1, %18 ]
%24 = phi i32 [ %23, %22 ], [ 0, %18 ]
%25 = phi i32 [ %28, %22 ], [ 2, %18 ]
%26 = add nsw i32 %23, %24
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %25, i32 %26)
%28 = add nuw nsw i32 %25, 1
%29 = load i32, i32* %1
%30 = icmp slt i32 %25, %29
br i1 %30, label %22, label %31
31: ; preds = %22, %14, %18
%32 = call i32 @putchar(i32 10)
br label %33
33: ; preds = %31, %12
%34 = phi i32 [ 1, %12 ], [ 0, %31 ]
%35 = call i32 @putchar(i32 10)
ret i32 %34
}