#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);
long factorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i = 0, c;
  int num;
  long f;
  printf("Enter an integer to find factorial\n");
  scanf("%d", &num);
  if (num < 0)
    printf("Negative integers are not allowed.\n");
  else {
    f = factorial(num);
    printf("%d! = %ld\n", num, f);
  }
  printf("Give a number to calcuate Fibonacci Series : ");
  scanf("%d", &n);
  printf("\nFibonacci series\n");
  for (c = 1; c <= n; c++) {
    printf("%d\n", Fibonacci(i));
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
jge    1191 <main+0x51>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b2 <main+0x72>
mov    -0x14(%rbp),%edi
call   1030 <factorial@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1220 <main+0xe0>
mov    -0xc(%rbp),%edi
call   1040 <Fibonacci@plt>
mov    %eax,%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e5 <main+0xa5>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%edi
test   %edi,%edi
js     1190 <main+0x40>
call   1040 <factorial@plt>
mov    (%rsp),%esi
lea    0xe7f(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    119c <main+0x4c>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x4(%rsp)
jle    11fc <main+0xac>
lea    0xe67(%rip),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <Fibonacci@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     11e0 <main+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter an integer to find factorial\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [36 x i8] c"Negative integers are not allowed.\0A\00"
@.str.3 = [11 x i8] c"%d! = %ld\0A\00"
@.str.4 = [46 x i8] c"Give a number to calcuate Fibonacci Series : \00"
@.str.5 = [19 x i8] c"\0AFibonacci series\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 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* %5)
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %19
13: ; preds = %0
%14 = load i32, i32* %5
%15 = call i64 @factorial(i32 %14)
store i64 %15, i64* %6
%16 = load i32, i32* %5
%17 = load i64, i64* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %16, i64 %17)
br label %19
19: ; preds = %13, %11
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %4
br label %23
23: ; preds = %33, %19
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i32, i32* %3
%29 = call i32 @Fibonacci(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %27
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %23
36: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"%d! = %ld\0A\00"
@.str.4 = [46 x i8] c"Give a number to calcuate Fibonacci Series : \00"
@.str.6 = [4 x i8] c"%d\0A\00"
@str = [35 x i8] c"Enter an integer to find factorial\00"
@str.7 = [18 x i8] c"\0AFibonacci series\00"
@str.8 = [35 x i8] c"Negative integers are not allowed.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
br label %15
11: ; preds = %0
%12 = call i64 @factorial(i32 %7)
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %13, i64 %12)
br label %15
15: ; preds = %11, %9
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%19 = load i32, i32* %1
%20 = icmp slt i32 %19, 1
br i1 %20, label %30, label %21
21: ; preds = %15, %21
%22 = phi i32 [ %26, %21 ], [ 0, %15 ]
%23 = phi i32 [ %27, %21 ], [ 1, %15 ]
%24 = call i32 @Fibonacci(i32 %22)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i32 %22, 1
%27 = add nuw nsw i32 %23, 1
%28 = load i32, i32* %1
%29 = icmp slt i32 %23, %28
br i1 %29, label %21, label %30
30: ; preds = %21, %15
ret i32 0
}