#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 *, ...);
long recursiveFactorial(long);
int /*<<< orphan*/ scanf(char *, long *);
int main() {
  long int number, result;
  printf("Factorial of a number: \n");
  printf("\n");
  printf("Enter a Whole Number (max. 12): \n");
  scanf("%ld", &number);
  printf("\n");
  if (number > 12) {
    printf("Number > 12 \n");
    printf("\n");
    return 1;
  }
  result = recursiveFactorial(number);
  if (result == -1) {
    printf("Invalid Input \n");
  } else {
    printf("(%ld)! = %ld \n", number, result);
  }
  printf("\n");
  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    0xef7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0xc,-0x10(%rbp)
jle    11ba <main+0x8a>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1210 <main+0xe0>
mov    -0x10(%rbp),%rdi
call   1040 <recursiveFactorial@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11e5 <main+0xb5>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fb <main+0xcb>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xe82(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
cmp    $0xd,%rdi
jl     11b0 <main+0x60>
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    11e3 <main+0x93>
call   1060 <recursiveFactorial@plt>
cmp    $0xffffffffffffffff,%rax
je     11d5 <main+0x85>
mov    0x8(%rsp),%rsi
lea    0xe3d(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e3 <main+0x93>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Factorial of a number: \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [34 x i8] c"Enter a Whole Number (max. 12): \0A\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [14 x i8] c"Number > 12 \0A\00"
@.str.5 = [16 x i8] c"Invalid Input \0A\00"
@.str.6 = [15 x i8] c"(%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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = load i64, i64* %2
%10 = icmp sgt i64 %9, 12
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %27
14: ; preds = %0
%15 = load i64, i64* %2
%16 = call i64 @recursiveFactorial(i64 %15)
store i64 %16, i64* %3
%17 = load i64, i64* %3
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %25
21: ; preds = %14
%22 = load i64, i64* %2
%23 = load i64, i64* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 %22, i64 %23)
br label %25
25: ; preds = %21, %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %27
27: ; preds = %25, %11
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str.3 = [4 x i8] c"%ld\00"
@.str.6 = [15 x i8] c"(%ld)! = %ld \0A\00"
@str = [24 x i8] c"Factorial of a number: \00"
@str.7 = [33 x i8] c"Enter a Whole Number (max. 12): \00"
@str.8 = [15 x i8] c"Invalid Input \00"
@str.9 = [13 x i8] c"Number > 12 \00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @putchar(i32 10)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%7 = call i32 @putchar(i32 10)
%8 = load i64, i64* %1
%9 = icmp sgt i64 %8, 12
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
br label %20
12: ; preds = %0
%13 = call i64 @recursiveFactorial(i64 %8)
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = load i64, i64* %1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 %18, i64 %13)
br label %20
20: ; preds = %15, %17, %10
%21 = phi i32 [ 1, %10 ], [ 0, %17 ], [ 0, %15 ]
%22 = call i32 @putchar(i32 10)
ret i32 %21
}