#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 FLT_EPSILON;
double exp(float);
float pow(float, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  int i;
  float x, sum, fact, term;
  printf(
      "\nYou have this series : 1+x/1!+x^2/2!+ x^3/3! + x^4/4!+……………….x^n/n!");
  printf("\n\nEnter the value for X : ");
  scanf("%f", &x);
  sum = 0;
  term = 1;
  fact = 1;
  for (i = 1; term >= FLT_EPSILON; i++) {
    fact = fact * i;
    sum = sum + term;
    term = pow(x, i) / fact;
  }
  printf("\n\nThe Calculated value of e^% .3f = %f", x, sum);
  printf("\n\nThe Library Function Value of e^%.3f = %f", x, exp(x));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf22(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xe75(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xe68(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x1,-0x8(%rbp)
movss  -0x18(%rbp),%xmm0
mov    0x2e30(%rip),%rax
ucomiss (%rax),%xmm0
jb     1200 <main+0xc0>
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%edi
call   1060 <pow@plt>
divss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <main+0x64>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe57(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
lea    0xe50(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf2a(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e65(%rip),%r14
xorps  %xmm1,%xmm1
movss  0xe7a(%rip),%xmm0
ucomiss (%r14),%xmm0
jb     11e8 <main+0xa8>
mov    $0x1,%ebx
xorps  %xmm2,%xmm2
movaps %xmm0,%xmm3
nopw   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
addss  %xmm0,%xmm2
movss  %xmm2,0x8(%rsp)
mulss  %xmm1,%xmm3
movss  %xmm3,0x14(%rsp)
movss  0x4(%rsp),%xmm0
mov    %ebx,%edi
call   1060 <pow@plt>
movss  0x14(%rsp),%xmm3
movss  0x8(%rsp),%xmm2
divss  %xmm3,%xmm0
add    $0x1,%ebx
ucomiss (%r14),%xmm0
jae    11a0 <main+0x60>
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe77(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  0x4(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <exp@plt>
movaps %xmm0,%xmm1
lea    0xe75(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [81 x i8] c"\0AYou have this series : 1+x/1!+x^2/2!+ x^3/3! + x^4/4!+\E2\80\A6\E2\80\A6\E2\80\A6\E2\80\A6\E2\80\A6\E2\80\A6.x^n/n!\00"
@.str.1 = [27 x i8] c"\0A\0AEnter the value for X : \00"
@.str.2 = [3 x i8] c"%f\00"
@FLT_EPSILON = global float 0.000000e+00
@.str.3 = [39 x i8] c"\0A\0AThe Calculated value of e^% .3f = %f\00"
@.str.4 = [44 x i8] c"\0A\0AThe Library Function Value of e^%.3f = %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
store float 0.000000e+00, float* %4
store float 1.000000e+00, float* %6
store float 1.000000e+00, float* %5
store i32 1, i32* %2
br label %10
10: ; preds = %27, %0
%11 = load float, float* %6
%12 = load float, float* @FLT_EPSILON
%13 = fcmp oge float %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load float, float* %5
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to float
%18 = fmul float %15, %17
store float %18, float* %5
%19 = load float, float* %4
%20 = load float, float* %6
%21 = fadd float %19, %20
store float %21, float* %4
%22 = load float, float* %3
%23 = load i32, i32* %2
%24 = call float @pow(float %22, i32 %23)
%25 = load float, float* %5
%26 = fdiv float %24, %25
store float %26, float* %6
br label %27
27: ; preds = %14
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %10
30: ; preds = %10
%31 = load float, float* %3
%32 = fpext float %31 to double
%33 = load float, float* %4
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %32, double %34)
%36 = load float, float* %3
%37 = fpext float %36 to double
%38 = load float, float* %3
%39 = call double @exp(float %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), double %37, double %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [81 x i8] c"\0AYou have this series : 1+x/1!+x^2/2!+ x^3/3! + x^4/4!+\E2\80\A6\E2\80\A6\E2\80\A6\E2\80\A6\E2\80\A6\E2\80\A6.x^n/n!\00"
@.str.1 = [27 x i8] c"\0A\0AEnter the value for X : \00"
@.str.2 = [3 x i8] c"%f\00"
@FLT_EPSILON = global float 0.000000e+00
@.str.3 = [39 x i8] c"\0A\0AThe Calculated value of e^% .3f = %f\00"
@.str.4 = [44 x i8] c"\0A\0AThe Library Function Value of e^%.3f = %f\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%6 = load float, float* @FLT_EPSILON
%7 = fcmp ugt float %6, 1.000000e+00
br i1 %7, label %24, label %8
8: ; preds = %0, %8
%9 = phi float [ %18, %8 ], [ 1.000000e+00, %0 ]
%10 = phi float [ %14, %8 ], [ 1.000000e+00, %0 ]
%11 = phi float [ %15, %8 ], [ 0.000000e+00, %0 ]
%12 = phi i32 [ %19, %8 ], [ 1, %0 ]
%13 = sitofp i32 %12 to float
%14 = fmul float %10, %13
%15 = fadd float %11, %9
%16 = load float, float* %1
%17 = call float @pow(float %16, i32 %12)
%18 = fdiv float %17, %14
%19 = add nuw nsw i32 %12, 1
%20 = load float, float* @FLT_EPSILON
%21 = fcmp ult float %18, %20
br i1 %21, label %22, label %8
22: ; preds = %8
%23 = fpext float %15 to double
br label %24
24: ; preds = %22, %0
%25 = phi double [ 0.000000e+00, %0 ], [ %23, %22 ]
%26 = load float, float* %1
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %27, double %25)
%29 = load float, float* %1
%30 = fpext float %29 to double
%31 = call double @exp(float %29)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), double %30, double %31)
ret i32 0
}