#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 */
float exp(float);
int fabs(float);
int factorial(int);
int pow(float, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float x, actual, approx1, approx2, err1, err2;
  printf("Please insert a value for x: ");
  scanf("%f", &x);
  actual = exp(-x);
  approx1 = 1 - x + pow(x, 2) / factorial(2) - pow(x, 3) / factorial(3) +
            pow(x, 4) / factorial(4);
  approx2 = 1 / (1 + x + pow(x, 2) / factorial(2) + pow(x, 3) / factorial(3) +
                 pow(x, 4) / factorial(4));
  err1 = (fabs((approx1 - actual) / actual) * 100);
  err2 = (fabs((approx2 - actual) / actual) * 100);
  printf("\nThe actual value of e^-1 is: %f\n", actual);
  printf("\nMethod 1 gives us a value of: %f\n", approx1);
  printf("This method has a percent error of: %f %\n", err1);
  printf("\nMethod 2 gives us a value of: %f\n", approx2);
  printf("This method has a percent error of: %f %\n\n", err2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1060 <exp@plt>
movss  %xmm0,-0xc(%rbp)
movss  0xe4f(%rip),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %eax,-0x48(%rbp)
mov    $0x2,%edi
call   1030 <factorial@plt>
movss  -0x4c(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x3,%edi
call   1080 <pow@plt>
mov    %eax,-0x40(%rbp)
mov    $0x3,%edi
call   1030 <factorial@plt>
movss  -0x44(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x4,%edi
call   1080 <pow@plt>
mov    %eax,-0x38(%rbp)
mov    $0x4,%edi
call   1030 <factorial@plt>
movss  -0x3c(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xd9b(%rip),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %eax,-0x30(%rbp)
mov    $0x2,%edi
call   1030 <factorial@plt>
movss  -0x34(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x3,%edi
call   1080 <pow@plt>
mov    %eax,-0x28(%rbp)
mov    $0x3,%edi
call   1030 <factorial@plt>
movss  -0x2c(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x4,%edi
call   1080 <pow@plt>
mov    %eax,-0x20(%rbp)
mov    $0x4,%edi
call   1030 <factorial@plt>
movss  -0x24(%rbp),%xmm1
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
addss  %xmm0,%xmm1
movss  0xcec(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x64,%eax,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x64,%eax,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcb8(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcc3(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xccf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xce2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcee(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <scanf@plt>
movss  0x10(%rsp),%xmm0
xorps  0xe6f(%rip),%xmm0
call   1060 <exp@plt>
movss  %xmm0,0x18(%rsp)
movss  0x10(%rsp),%xmm0
movss  0xe66(%rip),%xmm1
movss  %xmm1,0x14(%rsp)
subss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0x8(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x10(%rsp),%xmm0
mov    $0x3,%edi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    $0x3,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x10(%rsp),%xmm0
mov    $0x4,%edi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    $0x4,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0x8(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x10(%rsp),%xmm0
movaps %xmm0,%xmm1
addss  0xda5(%rip),%xmm1
movss  %xmm1,0xc(%rsp)
mov    $0x2,%edi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm0
mov    $0x3,%edi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    $0x3,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm0
mov    $0x4,%edi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    $0x4,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0xc(%rsp),%xmm0
movss  0x14(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x14(%rsp)
movss  0x8(%rsp),%xmm0
movss  0x18(%rsp),%xmm1
subss  %xmm1,%xmm0
divss  %xmm1,%xmm0
call   1050 <fabs@plt>
imul   $0x64,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x1c(%rsp)
movss  0x14(%rsp),%xmm0
movss  0x18(%rsp),%xmm1
subss  %xmm1,%xmm0
divss  %xmm1,%xmm0
call   1050 <fabs@plt>
imul   $0x64,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x18(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcbb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcc5(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x1c(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcd0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x14(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xce2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xced(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Please insert a value for x: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [34 x i8] c"\0AThe actual value of e^-1 is: %f\0A\00"
@.str.3 = [35 x i8] c"\0AMethod 1 gives us a value of: %f\0A\00"
@.str.4 = [42 x i8] c"This method has a percent error of: %f %\0A\00"
@.str.5 = [35 x i8] c"\0AMethod 2 gives us a value of: %f\0A\00"
@.str.6 = [43 x i8] c"This method has a percent error of: %f %\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%10 = load float, float* %2
%11 = fneg float %10
%12 = call float @exp(float %11)
store float %12, float* %3
%13 = load float, float* %2
%14 = fsub float 1.000000e+00, %13
%15 = load float, float* %2
%16 = call i32 @pow(float %15, i32 2)
%17 = call i32 @factorial(i32 2)
%18 = sdiv i32 %16, %17
%19 = sitofp i32 %18 to float
%20 = fadd float %14, %19
%21 = load float, float* %2
%22 = call i32 @pow(float %21, i32 3)
%23 = call i32 @factorial(i32 3)
%24 = sdiv i32 %22, %23
%25 = sitofp i32 %24 to float
%26 = fsub float %20, %25
%27 = load float, float* %2
%28 = call i32 @pow(float %27, i32 4)
%29 = call i32 @factorial(i32 4)
%30 = sdiv i32 %28, %29
%31 = sitofp i32 %30 to float
%32 = fadd float %26, %31
store float %32, float* %4
%33 = load float, float* %2
%34 = fadd float 1.000000e+00, %33
%35 = load float, float* %2
%36 = call i32 @pow(float %35, i32 2)
%37 = call i32 @factorial(i32 2)
%38 = sdiv i32 %36, %37
%39 = sitofp i32 %38 to float
%40 = fadd float %34, %39
%41 = load float, float* %2
%42 = call i32 @pow(float %41, i32 3)
%43 = call i32 @factorial(i32 3)
%44 = sdiv i32 %42, %43
%45 = sitofp i32 %44 to float
%46 = fadd float %40, %45
%47 = load float, float* %2
%48 = call i32 @pow(float %47, i32 4)
%49 = call i32 @factorial(i32 4)
%50 = sdiv i32 %48, %49
%51 = sitofp i32 %50 to float
%52 = fadd float %46, %51
%53 = fdiv float 1.000000e+00, %52
store float %53, float* %5
%54 = load float, float* %4
%55 = load float, float* %3
%56 = fsub float %54, %55
%57 = load float, float* %3
%58 = fdiv float %56, %57
%59 = call i32 @fabs(float %58)
%60 = mul nsw i32 %59, 100
%61 = sitofp i32 %60 to float
store float %61, float* %6
%62 = load float, float* %5
%63 = load float, float* %3
%64 = fsub float %62, %63
%65 = load float, float* %3
%66 = fdiv float %64, %65
%67 = call i32 @fabs(float %66)
%68 = mul nsw i32 %67, 100
%69 = sitofp i32 %68 to float
store float %69, float* %7
%70 = load float, float* %3
%71 = fpext float %70 to double
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), double %71)
%73 = load float, float* %4
%74 = fpext float %73 to double
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), double %74)
%76 = load float, float* %6
%77 = fpext float %76 to double
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), double %77)
%79 = load float, float* %5
%80 = fpext float %79 to double
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), double %80)
%82 = load float, float* %7
%83 = fpext float %82 to double
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), double %83)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Please insert a value for x: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [34 x i8] c"\0AThe actual value of e^-1 is: %f\0A\00"
@.str.3 = [35 x i8] c"\0AMethod 1 gives us a value of: %f\0A\00"
@.str.4 = [42 x i8] c"This method has a percent error of: %f %\0A\00"
@.str.5 = [35 x i8] c"\0AMethod 2 gives us a value of: %f\0A\00"
@.str.6 = [43 x i8] c"This method has a percent error of: %f %\0A\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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), float* %1)
%5 = load float, float* %1
%6 = fneg float %5
%7 = call float @exp(float %6)
%8 = load float, float* %1
%9 = fsub float 1.000000e+00, %8
%10 = call i32 @pow(float %8, i32 2)
%11 = call i32 @factorial(i32 2)
%12 = sdiv i32 %10, %11
%13 = sitofp i32 %12 to float
%14 = fadd float %9, %13
%15 = load float, float* %1
%16 = call i32 @pow(float %15, i32 3)
%17 = call i32 @factorial(i32 3)
%18 = sdiv i32 %16, %17
%19 = sitofp i32 %18 to float
%20 = fsub float %14, %19
%21 = load float, float* %1
%22 = call i32 @pow(float %21, i32 4)
%23 = call i32 @factorial(i32 4)
%24 = sdiv i32 %22, %23
%25 = sitofp i32 %24 to float
%26 = fadd float %20, %25
%27 = load float, float* %1
%28 = fadd float %27, 1.000000e+00
%29 = call i32 @pow(float %27, i32 2)
%30 = call i32 @factorial(i32 2)
%31 = sdiv i32 %29, %30
%32 = sitofp i32 %31 to float
%33 = fadd float %28, %32
%34 = load float, float* %1
%35 = call i32 @pow(float %34, i32 3)
%36 = call i32 @factorial(i32 3)
%37 = sdiv i32 %35, %36
%38 = sitofp i32 %37 to float
%39 = fadd float %33, %38
%40 = load float, float* %1
%41 = call i32 @pow(float %40, i32 4)
%42 = call i32 @factorial(i32 4)
%43 = sdiv i32 %41, %42
%44 = sitofp i32 %43 to float
%45 = fadd float %39, %44
%46 = fdiv float 1.000000e+00, %45
%47 = fsub float %26, %7
%48 = fdiv float %47, %7
%49 = call i32 @fabs(float %48)
%50 = mul nsw i32 %49, 100
%51 = sitofp i32 %50 to float
%52 = fsub float %46, %7
%53 = fdiv float %52, %7
%54 = call i32 @fabs(float %53)
%55 = mul nsw i32 %54, 100
%56 = sitofp i32 %55 to float
%57 = fpext float %7 to double
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), double %57)
%59 = fpext float %26 to double
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), double %59)
%61 = fpext float %51 to double
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), double %61)
%63 = fpext float %46 to double
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), double %63)
%65 = fpext float %56 to double
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), double %65)
ret i32 0
}