#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 */
double calculateEX(int);
double estimateE(int);
int factorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num;
  printf("Enter a number and I will tell you its factorial\n");
  printf("and use it to estimate e, and calculate\n");
  printf("the value of e to the power of x: ");
  scanf("%d", &num);
  if (num < 1) {
    printf("Error - number must be 1 or greater\n");
    return 0;
  }
  printf("Factorial       =  %d\n", factorial(num));
  printf("Estimation of e =  %f\n", estimateE(num));
  printf("Value of e to the power of x = %f\n", calculateEX(num));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeee(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jge    11bd <main+0x6d>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1208 <main+0xb8>
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,%esi
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <estimateE@plt>
lea    0xed9(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <calculateEX@plt>
lea    0xeda(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf0f(%rip),%rdi
call   1030 <puts@plt>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11e5 <main+0x85>
call   1040 <factorial@plt>
lea    0xe7a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1060 <estimateE@plt>
lea    0xe78(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <calculateEX@plt>
lea    0xe78(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    11f1 <main+0x91>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Enter a number and I will tell you its factorial\0A\00"
@.str.1 = [41 x i8] c"and use it to estimate e, and calculate\0A\00"
@.str.2 = [35 x i8] c"the value of e to the power of x: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [37 x i8] c"Error - number must be 1 or greater\0A\00"
@.str.5 = [23 x i8] c"Factorial = %d\0A\00"
@.str.6 = [23 x i8] c"Estimation of e = %f\0A\00"
@.str.7 = [35 x i8] c"Value of e to the power of x = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %21
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @factorial(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = call double @estimateE(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), double %16)
%18 = load i32, i32* %2
%19 = call double @calculateEX(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), double %19)
store i32 0, i32* %1
br label %21
21: ; preds = %11, %9
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str.2 = [35 x i8] c"the value of e to the power of x: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [23 x i8] c"Factorial = %d\0A\00"
@.str.6 = [23 x i8] c"Estimation of e = %f\0A\00"
@.str.7 = [35 x i8] c"Value of e to the power of x = %f\0A\00"
@str = [49 x i8] c"Enter a number and I will tell you its factorial\00"
@str.8 = [40 x i8] c"and use it to estimate e, and calculate\00"
@str.9 = [36 x i8] c"Error - number must be 1 or greater\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %20
11: ; preds = %0
%12 = call i32 @factorial(i32 %7)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %1
%15 = call double @estimateE(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), double %15)
%17 = load i32, i32* %1
%18 = call double @calculateEX(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), double %18)
br label %20
20: ; preds = %11, %9
ret i32 0
}