#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 factorial_norecursive(int);
unsigned long factorial_recursive(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int num;
  unsigned long fac;
  printf("input num = ");
  scanf("%d", &num);
  printf("recursive solution : ");
  fac = factorial_recursive(num);
  printf("%ld\n", fac);
  printf("no-recursive solution : ");
  fac = factorial_norecursive(num);
  printf("%ld\n", fac);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <factorial_recursive@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <factorial_norecursive@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edi
call   1050 <factorial_recursive@plt>
lea    0xe8e(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edi
call   1060 <factorial_norecursive@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"input num = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"recursive solution : \00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@.str.4 = [25 x i8] c"no-recursive solution : \00"
define void @main() {
%1 = alloca i32
%2 = alloca i64
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 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 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* %1
%7 = call i64 @factorial_recursive(i32 %6)
store i64 %7, i64* %2
%8 = load i64, i64* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = call i64 @factorial_norecursive(i32 %11)
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %13)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"input num = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"recursive solution : \00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@.str.4 = [25 x i8] c"no-recursive solution : \00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* %1
%7 = call i64 @factorial_recursive(i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = call i64 @factorial_norecursive(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %11)
ret void
}