#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 fibonacci(int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  int fibonacciElement = 10;
  if (argc > 1) {
    if (sscanf(argv[1], "%i", (int *)&fibonacciElement) != 1) {
      printf("input arg error - not an integer");
      return -1;
    }
    if (fibonacciElement < 1) {
      printf("Needs to be greater than 0 \n");
      return -1;
    }
  }
  int answer = fibonacci(fibonacciElement);
  printf("Number %d in the fibonacci series is %d \n", fibonacciElement,
         answer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11bb <main+0x8b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1192 <main+0x62>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <main+0xaa>
cmpl   $0x1,-0x14(%rbp)
jge    11b6 <main+0x86>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <main+0xaa>
jmp    11bb <main+0x8b>
mov    -0x14(%rbp),%edi
call   1040 <fibonacci@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%eax
movl   $0xa,0xc(%rsp)
mov    $0xa,%edi
cmp    $0x2,%eax
jl     117b <main+0x3b>
mov    0x8(%rsi),%rdi
lea    0xe9c(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1198 <main+0x58>
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    11a8 <main+0x68>
call   1050 <fibonacci@plt>
mov    0xc(%rsp),%esi
lea    0xe99(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b9 <main+0x79>
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b4 <main+0x74>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [33 x i8] c"input arg error - not an integer\00"
@.str.2 = [29 x i8] c"Needs to be greater than 0 \0A\00"
@.str.3 = [42 x i8] c"Number %d in the fibonacci series is %d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
18: ; preds = %10
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
23: ; preds = %18
br label %24
24: ; preds = %23, %2
%25 = load i32, i32* %6
%26 = call i32 @fibonacci(i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28)
br label %30
30: ; preds = %24, %21, %16
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@.str.1 = [33 x i8] c"input arg error - not an integer\00"
@.str.3 = [42 x i8] c"Number %d in the fibonacci series is %d \0A\00"
@str = [28 x i8] c"Needs to be greater than 0 \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 10, i32* %3
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %23
13: ; preds = %6
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %23
18: ; preds = %13, %2
%19 = phi i32 [ %14, %13 ], [ 10, %2 ]
%20 = call i32 @fibonacci(i32 %19)
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %20)
br label %23
23: ; preds = %18, %16, %11
%24 = phi i32 [ -1, %11 ], [ -1, %16 ], [ 0, %18 ]
ret i32 %24
}