#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 */
typedef int clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int clock();
unsigned int factorial1(int);
unsigned int factorial2(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  unsigned int answer;
  double duration;
  clock_t start;
  int n;
  printf("Enter the required term number:\n");
  scanf("%d", &n);
  start = clock();
  answer = factorial2(n);
  duration = (double)((clock() - start) / CLOCKS_PER_SEC);
  printf("factorial-2 operation took time: %f sec\n", duration);
  printf("%d th term of factorial term is %d\n", n, answer);
  printf("=====================================\n");
  start = clock();
  answer = factorial1(n);
  duration = (double)((clock() - start) / CLOCKS_PER_SEC);
  printf("factorial-1 operation took time: %f sec\n", duration);
  printf("%d th term of factorial term is %d\n", n, answer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <factorial2@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x14(%rbp),%eax
mov    0x2e45(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe69(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <factorial1@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x14(%rbp),%eax
mov    0x2dde(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe86(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1050 <factorial2@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <clock@plt>
sub    %ebx,%eax
mov    0x2e40(%rip),%r15
cltd
idivl  (%r15)
cvtsi2sd %eax,%xmm0
lea    0xe4c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe63(%rip),%r14
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%edi
call   1080 <factorial1@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <clock@plt>
sub    %ebp,%eax
cltd
idivl  (%r15)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe40(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Enter the required term number:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@CLOCKS_PER_SEC = global i32 0
@.str.2 = [41 x i8] c"factorial-2 operation took time: %f sec\0A\00"
@.str.3 = [36 x i8] c"%d th term of factorial term is %d\0A\00"
@.str.4 = [39 x i8] c"=====================================\0A\00"
@.str.5 = [41 x i8] c"factorial-1 operation took time: %f sec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%8 = call i32 (...) @clock()
store i32 %8, i32* %4
%9 = load i32, i32* %5
%10 = call i32 @factorial2(i32 %9)
store i32 %10, i32* %2
%11 = call i32 (...) @clock()
%12 = load i32, i32* %4
%13 = sub nsw i32 %11, %12
%14 = load i32, i32* @CLOCKS_PER_SEC
%15 = sdiv i32 %13, %14
%16 = sitofp i32 %15 to double
store double %16, double* %3
%17 = load double, double* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 (...) @clock()
store i32 %23, i32* %4
%24 = load i32, i32* %5
%25 = call i32 @factorial1(i32 %24)
store i32 %25, i32* %2
%26 = call i32 (...) @clock()
%27 = load i32, i32* %4
%28 = sub nsw i32 %26, %27
%29 = load i32, i32* @CLOCKS_PER_SEC
%30 = sdiv i32 %28, %29
%31 = sitofp i32 %30 to double
store double %31, double* %3
%32 = load double, double* %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), double %32)
%34 = load i32, i32* %5
%35 = load i32, i32* %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@CLOCKS_PER_SEC = global i32 0
@.str.2 = [41 x i8] c"factorial-2 operation took time: %f sec\0A\00"
@.str.3 = [36 x i8] c"%d th term of factorial term is %d\0A\00"
@.str.5 = [41 x i8] c"factorial-1 operation took time: %f sec\0A\00"
@str = [32 x i8] c"Enter the required term number:\00"
@str.6 = [38 x i8] c"=====================================\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = call i32 (...) @clock()
%6 = load i32, i32* %1
%7 = call i32 @factorial2(i32 %6)
%8 = call i32 (...) @clock()
%9 = sub nsw i32 %8, %5
%10 = load i32, i32* @CLOCKS_PER_SEC
%11 = sdiv i32 %9, %10
%12 = sitofp i32 %11 to double
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), double %12)
%14 = load i32, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %7)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
%17 = call i32 (...) @clock()
%18 = load i32, i32* %1
%19 = call i32 @factorial1(i32 %18)
%20 = call i32 (...) @clock()
%21 = sub nsw i32 %20, %17
%22 = load i32, i32* @CLOCKS_PER_SEC
%23 = sdiv i32 %21, %22
%24 = sitofp i32 %23 to double
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), double %24)
%26 = load i32, i32* %1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %19)
ret i32 0
}