#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 */
unsigned long FactorialLoop(unsigned long);
unsigned long FactorialRecur(unsigned long);
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char str[20] = {'\0'};
  unsigned long num = 0;
  unsigned long result = 0;
  do {
    printf("\nEnter a positive integer less than 21 :");
    scanf("%s", str);
  } while (atoi(str) < 0 || atoi(str) > 20);
  num = (unsigned long)atoi(str);
  if ((result = FactorialLoop(num)) == FactorialRecur(num))
    printf("\nFactorial is %lu\n", result);
  else
    printf("\nSome error occured.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
jl     11d8 <main+0x78>
lea    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
cmp    $0x14,%eax
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    118f <main+0x2f>
lea    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <FactorialLoop@plt>
mov    %rax,-0x40(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <FactorialRecur@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    1233 <main+0xd3>
mov    -0x30(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1241 <main+0xe1>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe81(%rip),%r14
lea    0xea3(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1080 <atoi@plt>
cmp    $0x14,%eax
ja     1190 <main+0x30>
mov    %eax,%ebx
mov    %rbx,%rdi
call   1060 <FactorialLoop@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <FactorialRecur@plt>
cmp    %rax,%r14
jne    11df <main+0x7f>
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11eb <main+0x8b>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"\0AEnter a positive integer less than 21 :\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"\0AFactorial is %lu\0A\00"
@.str.3 = [22 x i8] c"\0ASome error occured.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
%5 = bitcast [20 x i8]* %2 to i8*
store i64 0, i64* %3
store i64 0, i64* %4
br label %6
6: ; preds = %18, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %6
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%12 = call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%16 = call i32 @atoi(i8* %15)
%17 = icmp sgt i32 %16, 20
br label %18
18: ; preds = %14, %10
%19 = phi i1 [ true, %10 ], [ %17, %14 ]
br i1 %19, label %6, label %20
20: ; preds = %18
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
%23 = sext i32 %22 to i64
store i64 %23, i64* %3
%24 = load i64, i64* %3
%25 = call i64 @FactorialLoop(i64 %24)
store i64 %25, i64* %4
%26 = load i64, i64* %3
%27 = call i64 @FactorialRecur(i64 %26)
%28 = icmp eq i64 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i64, i64* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %30)
br label %34
32: ; preds = %20
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"\0AEnter a positive integer less than 21 :\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"\0AFactorial is %lu\0A\00"
@str = [21 x i8] c"\0ASome error occured.\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = call i32 @atoi(i8* %2)
%7 = icmp ugt i32 %6, 20
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = zext i32 %6 to i64
%10 = call i64 @FactorialLoop(i64 %9)
%11 = call i64 @FactorialRecur(i64 %9)
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %10)
br label %17
15: ; preds = %8
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
ret i32 0
}