#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() {
  int number = 0, fibonacciA = 1, fibonacciB = 1, fibonacciC = 0, i = 0;
  printf("Please enter a Fibonacci number: ");
  scanf("%d", &number);
  if (number < 0) {
    printf("Error: Input positive number\n");
  } else if (number == 0) {
    printf("Error: Input larger number than 0\n");
  } else {
    for (i = 3; i <= number; i++) {
      fibonacciC = fibonacciA + fibonacciB;
      fibonacciA = fibonacciB;
      fibonacciB = fibonacciC;
    }
    printf("%d", fibonacciC);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    118d <main+0x6d>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0xd6>
cmpl   $0x0,-0x8(%rbp)
jne    11aa <main+0x8a>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <main+0xd1>
movl   $0x3,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11e0 <main+0xc0>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b1 <main+0x91>
mov    -0x14(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0xd6>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
js     1185 <main+0x55>
je     1193 <main+0x63>
xor    %esi,%esi
cmp    $0x3,%ecx
jb     11dd <main+0xad>
lea    -0x2(%rcx),%edx
add    $0xfffffffd,%ecx
mov    %edx,%eax
and    $0x7,%eax
cmp    $0x7,%ecx
jae    11a1 <main+0x71>
mov    $0x1,%esi
mov    $0x1,%ecx
jmp    11c5 <main+0x95>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
jmp    11eb <main+0xbb>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
jmp    11eb <main+0xbb>
and    $0xfffffff8,%edx
mov    $0x1,%esi
mov    $0x1,%ecx
xchg   %ax,%ax
add    %esi,%ecx
add    %ecx,%esi
add    %esi,%ecx
add    %ecx,%esi
add    %esi,%ecx
add    %ecx,%esi
add    %esi,%ecx
add    %ecx,%esi
add    $0xfffffff8,%edx
jne    11b0 <main+0x80>
test   %eax,%eax
je     11dd <main+0xad>
nopl   0x0(%rax)
mov    %esi,%edx
mov    %ecx,%esi
add    %edx,%esi
mov    %edx,%ecx
add    $0xffffffff,%eax
jne    11d0 <main+0xa0>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Please enter a Fibonacci number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [30 x i8] c"Error: Input positive number\0A\00"
@.str.3 = [35 x i8] c"Error: Input larger number than 0\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
store i32 0, i32* %2
store i32 1, i32* %3
store i32 1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %36
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %35
18: ; preds = %13
store i32 3, i32* %6
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %2
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = add nsw i32 %24, %25
store i32 %26, i32* %5
%27 = load i32, i32* %4
store i32 %27, i32* %3
%28 = load i32, i32* %5
store i32 %28, i32* %4
br label %29
29: ; preds = %23
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %19
32: ; preds = %19
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %16
br label %36
36: ; preds = %35, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Please enter a Fibonacci number: \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [34 x i8] c"Error: Input larger number than 0\00"
@str.4 = [29 x i8] c"Error: Input positive number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
br label %51
9: ; preds = %0
%10 = icmp eq i32 %5, 0
br i1 %10, label %20, label %11
11: ; preds = %9
%12 = icmp ult i32 %5, 3
br i1 %12, label %48, label %13
13: ; preds = %11
%14 = add i32 %5, -2
%15 = add i32 %5, -3
%16 = and i32 %14, 7
%17 = icmp ult i32 %15, 7
br i1 %17, label %36, label %18
18: ; preds = %13
%19 = and i32 %14, -8
br label %22
20: ; preds = %9
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %51
22: ; preds = %22, %18
%23 = phi i32 [ 1, %18 ], [ %33, %22 ]
%24 = phi i32 [ 1, %18 ], [ %32, %22 ]
%25 = phi i32 [ 0, %18 ], [ %34, %22 ]
%26 = add nsw i32 %23, %24
%27 = add nsw i32 %26, %23
%28 = add nsw i32 %27, %26
%29 = add nsw i32 %28, %27
%30 = add nsw i32 %29, %28
%31 = add nsw i32 %30, %29
%32 = add nsw i32 %31, %30
%33 = add nsw i32 %32, %31
%34 = add i32 %25, 8
%35 = icmp eq i32 %34, %19
br i1 %35, label %36, label %22
36: ; preds = %22, %13
%37 = phi i32 [ undef, %13 ], [ %33, %22 ]
%38 = phi i32 [ 1, %13 ], [ %33, %22 ]
%39 = phi i32 [ 1, %13 ], [ %32, %22 ]
%40 = icmp eq i32 %16, 0
br i1 %40, label %48, label %41
41: ; preds = %36, %41
%42 = phi i32 [ %45, %41 ], [ %38, %36 ]
%43 = phi i32 [ %42, %41 ], [ %39, %36 ]
%44 = phi i32 [ %46, %41 ], [ 0, %36 ]
%45 = add nsw i32 %42, %43
%46 = add i32 %44, 1
%47 = icmp eq i32 %46, %16
br i1 %47, label %48, label %41
48: ; preds = %36, %41, %11
%49 = phi i32 [ 0, %11 ], [ %37, %36 ], [ %45, %41 ]
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %20, %48, %7
ret i32 0
}