#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 */
long fibonacci(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int main() {
  long result, number;
  printf("Example of Recusive Fibonacci Function\n\n");
  do {
    printf("Enter an integer (-1 to stop): ");
    scanf("%ld", &number);
    if (number == -1L)
      break;
    result = fibonacci(number);
    printf("Fibonacci(%ld) = %ld\n", number, result);
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    117b <main+0x4b>
jmp    11ad <main+0x7d>
mov    -0x18(%rbp),%rdi
call   1040 <fibonacci@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    114d <main+0x1d>
jmp    11ad <main+0x7d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%rdi
cmp    $0xffffffffffffffff,%rdi
je     11d5 <main+0x95>
lea    0xea2(%rip),%r14
lea    0xe77(%rip),%r15
lea    0xe90(%rip),%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1050 <fibonacci@plt>
mov    (%rsp),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%rdi
cmp    $0xffffffffffffffff,%rdi
jne    11a0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Example of Recusive Fibonacci Function\0A\0A\00"
@.str.1 = [32 x i8] c"Enter an integer (-1 to stop): \00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [22 x i8] c"Fibonacci(%ld) = %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %17, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %5
br label %18
11: ; preds = %5
%12 = load i64, i64* %3
%13 = call i64 @fibonacci(i64 %12)
store i64 %13, i64* %2
%14 = load i64, i64* %3
%15 = load i64, i64* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %14, i64 %15)
br label %17
17: ; preds = %11
br i1 true, label %5, label %18
18: ; preds = %17, %10
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"Enter an integer (-1 to stop): \00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [22 x i8] c"Fibonacci(%ld) = %ld\0A\00"
@str = [40 x i8] c"Example of Recusive Fibonacci Function\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, -1
br i1 %7, label %17, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %15, %8 ], [ %6, %0 ]
%10 = call i64 @fibonacci(i64 %9)
%11 = load i64, i64* %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %11, i64 %10)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%15 = load i64, i64* %1
%16 = icmp eq i64 %15, -1
br i1 %16, label %17, label %8
17: ; preds = %8, %0
ret i32 0
}