#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int number = 0;
  int prev = 1;
  int prev_prev = 1;
  int result = 1;
  while (!scanf("%d", &number)) {
    getchar();
    printf("\nerror!input again!\n");
  }
  int temp = 0;
  for (temp = 3; temp <= number; temp++) {
    result = prev + prev_prev;
    prev_prev = prev;
    prev = result;
  }
  printf("The %dth fibonacci number is %d\n", number, result);
  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   $0x1,-0x14(%rbp)
lea    0xe9e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1180 <main+0x50>
jmp    119a <main+0x6a>
mov    $0x0,%al
call   1040 <getchar@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115b <main+0x2b>
movl   $0x0,-0x18(%rbp)
movl   $0x3,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11d7 <main+0xa7>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a8 <main+0x78>
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
test   %eax,%eax
jne    119e <main+0x5e>
lea    0xeb7(%rip),%r14
lea    0xe8c(%rip),%r15
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
test   %eax,%eax
je     1180 <main+0x40>
mov    0xc(%rsp),%esi
mov    $0x1,%edx
cmp    $0x3,%esi
jl     120d <main+0xcd>
lea    -0x2(%rsi),%edi
lea    -0x3(%rsi),%ecx
mov    %edi,%eax
and    $0x7,%eax
cmp    $0x7,%ecx
jae    11c8 <main+0x88>
mov    $0x1,%edx
mov    $0x1,%ecx
jmp    11f5 <main+0xb5>
and    $0xfffffff8,%edi
mov    $0x1,%edx
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
add    %edx,%ecx
add    %ecx,%edx
add    %edx,%ecx
add    %ecx,%edx
add    %edx,%ecx
add    %ecx,%edx
add    %edx,%ecx
add    %ecx,%edx
add    $0xfffffff8,%edi
jne    11e0 <main+0xa0>
test   %eax,%eax
je     120d <main+0xcd>
nopl   0x0(%rax)
mov    %edx,%edi
mov    %ecx,%edx
add    %edi,%edx
mov    %edi,%ecx
add    $0xffffffff,%eax
jne    1200 <main+0xc0>
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [21 x i8] c"\0Aerror!input again!\0A\00"
@.str.2 = [33 x i8] c"The %dth fibonacci number is %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
store i32 0, i32* %2
store i32 1, i32* %3
store i32 1, i32* %4
store i32 1, i32* %5
br label %7
7: ; preds = %11, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = call i32 (...) @getchar()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %7
14: ; preds = %7
store i32 0, i32* %6
store i32 3, i32* %6
br label %15
15: ; preds = %25, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %2
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = add nsw i32 %20, %21
store i32 %22, i32* %5
%23 = load i32, i32* %3
store i32 %23, i32* %4
%24 = load i32, i32* %5
store i32 %24, i32* %3
br label %25
25: ; preds = %19
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %15
28: ; preds = %15
%29 = load i32, i32* %2
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"The %dth fibonacci number is %d\0A\00"
@str = [20 x i8] c"\0Aerror!input again!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %15, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 3
br i1 %7, label %46, label %8
8: ; preds = %5
%9 = add i32 %6, -2
%10 = add i32 %6, -3
%11 = and i32 %9, 7
%12 = icmp ult i32 %10, 7
br i1 %12, label %34, label %13
13: ; preds = %8
%14 = and i32 %9, -8
br label %20
15: ; preds = %0, %15
%16 = call i32 (...) @getchar()
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %15, label %5
20: ; preds = %20, %13
%21 = phi i32 [ 1, %13 ], [ %31, %20 ]
%22 = phi i32 [ 1, %13 ], [ %30, %20 ]
%23 = phi i32 [ 0, %13 ], [ %32, %20 ]
%24 = add nsw i32 %21, %22
%25 = add nsw i32 %24, %21
%26 = add nsw i32 %25, %24
%27 = add nsw i32 %26, %25
%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 i32 %23, 8
%33 = icmp eq i32 %32, %14
br i1 %33, label %34, label %20
34: ; preds = %20, %8
%35 = phi i32 [ undef, %8 ], [ %31, %20 ]
%36 = phi i32 [ 1, %8 ], [ %31, %20 ]
%37 = phi i32 [ 1, %8 ], [ %30, %20 ]
%38 = icmp eq i32 %11, 0
br i1 %38, label %46, label %39
39: ; preds = %34, %39
%40 = phi i32 [ %43, %39 ], [ %36, %34 ]
%41 = phi i32 [ %40, %39 ], [ %37, %34 ]
%42 = phi i32 [ %44, %39 ], [ 0, %34 ]
%43 = add nsw i32 %40, %41
%44 = add i32 %42, 1
%45 = icmp eq i32 %44, %11
br i1 %45, label %46, label %39
46: ; preds = %34, %39, %5
%47 = phi i32 [ 1, %5 ], [ %35, %34 ], [ %43, %39 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %47)
ret i32 0
}