#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 */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main(void) {
  double accuracy = -1;
  double eVal = 1;
  double fact = 1;
  long nextFact = 0;
  int numbTerms = 1;
  bool loopChecker = true;
  while (accuracy < 0) {
    printf("Please enter a positive decimal number (to represent how precise "
           "you want e to be approximated): \n");
    scanf("%lf", &accuracy);
  }
  while ((1 / fact >= accuracy) && (loopChecker == true)) {
    nextFact = nextFact + 1;
    fact = fact * nextFact;
    eVal = eVal + (1 / fact);
    numbTerms++;
    if (1 / (fact * (nextFact + 1)) < accuracy) {
      loopChecker = false;
    }
  }
  printf("this is the value of e: %.15lf \n", eVal);
  printf("Number of terms required to read this value: %d \n", numbTerms);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeaf(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119d <main+0x7d>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
jmp    116c <main+0x4c>
jmp    11a2 <main+0x82>
movsd  0xe56(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
xor    %eax,%eax
ucomisd -0x10(%rbp),%xmm0
mov    %al,-0x31(%rbp)
jb     11c9 <main+0xa9>
cmpl   $0x1,-0x30(%rbp)
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11d9 <main+0xb9>
jmp    125a <main+0x13a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xdfa(%rip),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdc5(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1255 <main+0x135>
movl   $0x0,-0x30(%rbp)
jmp    11a2 <main+0x82>
movsd  -0x18(%rbp),%xmm0
lea    0xe11(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movabs $0xbff0000000000000,%rax
mov    %rax,0x8(%rsp)
lea    0xf18(%rip),%r14
lea    0xeba(%rip),%r15
lea    0x8(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
ja     1160 <main+0x30>
mov    $0x1,%ebx
movsd  0xe70(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11f0 <main+0xc0>
movsd  0xe62(%rip),%xmm2
mov    $0x1,%ebx
movapd %xmm2,%xmm3
movapd %xmm2,%xmm0
nopl   0x0(%rax,%rax,1)
movapd %xmm3,%xmm4
xorps  %xmm3,%xmm3
cvtsi2sd %rbx,%xmm3
mulsd  %xmm4,%xmm3
movapd %xmm2,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm4,%xmm0
add    $0x1,%rbx
ucomisd %xmm1,%xmm4
jb     11f0 <main+0xc0>
xorps  %xmm4,%xmm4
cvtsi2sd %rbx,%xmm4
mulsd  %xmm3,%xmm4
movapd %xmm2,%xmm5
divsd  %xmm4,%xmm5
ucomisd %xmm5,%xmm1
jbe    11b0 <main+0x80>
lea    0xe1d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [99 x i8] c"Please enter a positive decimal number (to represent how precise you want e to be approximated): \0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [33 x i8] c"this is the value of e: %.15lf \0A\00"
@.str.3 = [50 x i8] c"Number of terms required to read this value: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store double -1.000000e+00, double* %2
store double 1.000000e+00, double* %3
store double 1.000000e+00, double* %4
store i64 0, i64* %5
store i32 1, i32* %6
store i32 1, i32* %7
br label %8
8: ; preds = %11, %0
%9 = load double, double* %2
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
br label %8
14: ; preds = %8
br label %15
15: ; preds = %47, %14
%16 = load double, double* %4
%17 = fdiv double 1.000000e+00, %16
%18 = load double, double* %2
%19 = fcmp oge double %17, %18
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 1
br label %23
23: ; preds = %20, %15
%24 = phi i1 [ false, %15 ], [ %22, %20 ]
br i1 %24, label %25, label %48
25: ; preds = %23
%26 = load i64, i64* %5
%27 = add nsw i64 %26, 1
store i64 %27, i64* %5
%28 = load double, double* %4
%29 = load i64, i64* %5
%30 = sitofp i64 %29 to double
%31 = fmul double %28, %30
store double %31, double* %4
%32 = load double, double* %3
%33 = load double, double* %4
%34 = fdiv double 1.000000e+00, %33
%35 = fadd double %32, %34
store double %35, double* %3
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
%38 = load double, double* %4
%39 = load i64, i64* %5
%40 = add nsw i64 %39, 1
%41 = sitofp i64 %40 to double
%42 = fmul double %38, %41
%43 = fdiv double 1.000000e+00, %42
%44 = load double, double* %2
%45 = fcmp olt double %43, %44
br i1 %45, label %46, label %47
46: ; preds = %25
store i32 0, i32* %7
br label %47
47: ; preds = %46, %25
br label %15
48: ; preds = %23
%49 = load double, double* %3
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), double %49)
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [33 x i8] c"this is the value of e: %.15lf \0A\00"
@.str.3 = [50 x i8] c"Number of terms required to read this value: %d \0A\00"
@str = [98 x i8] c"Please enter a positive decimal number (to represent how precise you want e to be approximated): \00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store double -1.000000e+00, double* %1
br label %5
3: ; preds = %5
%4 = fcmp ugt double %8, 1.000000e+00
br i1 %4, label %28, label %10
5: ; preds = %0, %5
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%8 = load double, double* %1
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %5, label %3
10: ; preds = %3, %10
%11 = phi i32 [ %20, %10 ], [ 1, %3 ]
%12 = phi i64 [ %15, %10 ], [ 0, %3 ]
%13 = phi double [ %17, %10 ], [ 1.000000e+00, %3 ]
%14 = phi double [ %19, %10 ], [ 1.000000e+00, %3 ]
%15 = add nuw nsw i64 %12, 1
%16 = sitofp i64 %15 to double
%17 = fmul double %13, %16
%18 = fdiv double 1.000000e+00, %17
%19 = fadd double %14, %18
%20 = add nuw nsw i32 %11, 1
%21 = add nuw nsw i64 %12, 2
%22 = sitofp i64 %21 to double
%23 = fmul double %17, %22
%24 = fdiv double 1.000000e+00, %23
%25 = fcmp uge double %24, %8
%26 = fcmp oge double %18, %8
%27 = and i1 %26, %25
br i1 %27, label %10, label %28
28: ; preds = %10, %3
%29 = phi double [ 1.000000e+00, %3 ], [ %19, %10 ]
%30 = phi i32 [ 1, %3 ], [ %20, %10 ]
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), double %29)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %30)
ret i32 0
}