#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 */
scalar_t__ fact(int);
int /*<<< orphan*/ printf(char *, float);
int main() {
  float diff = 2, sum = 2;
  int n = 2;
  while (diff > 0.00001) {
    diff = 1 / (float)fact(n - 1) - 1 / (float)fact(n);
    sum += 1 / (float)fact(n++);
  }
  printf("ANS: %f \n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xec9(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xebc(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e3 <main+0xc3>
mov    -0x10(%rbp),%edi
sub    $0x1,%edi
call   1040 <fact@plt>
cvtsi2ss %rax,%xmm1
movss  0xe81(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <fact@plt>
movss  -0x14(%rbp),%xmm0
cvtsi2ss %rax,%xmm2
movss  0xe5e(%rip),%xmm1
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x10(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
call   1040 <fact@plt>
cvtsi2ss %rax,%xmm1
movss  0xe34(%rip),%xmm0
divss  %xmm1,%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1150 <main+0x30>
movss  -0xc(%rbp),%xmm0
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movss  0xed0(%rip),%xmm0
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movss  %xmm0,0xc(%rsp)
lea    -0x1(%rbx),%edi
call   1040 <fact@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1040 <fact@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
unpcklps %xmm1,%xmm0
movaps 0xe9e(%rip),%xmm1
divps  %xmm0,%xmm1
movaps %xmm1,%xmm0
shufps $0x55,%xmm1,%xmm0
subss  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
lea    0x1(%rbx),%ebp
mov    %ebx,%edi
call   1040 <fact@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0xe65(%rip),%xmm1
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xc(%rsp),%xmm0
movaps 0x10(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
ucomisd 0xe56(%rip),%xmm1
mov    %ebp,%ebx
ja     1140 <main+0x20>
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"ANS: %f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i32
store i32 0, i32* %1
store float 2.000000e+00, float* %2
store float 2.000000e+00, float* %3
store i32 2, i32* %4
br label %5
5: ; preds = %9, %0
%6 = load float, float* %2
%7 = fpext float %6 to double
%8 = fcmp ogt double %7, 1.000000e-05
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = call i64 @fact(i32 %11)
%13 = sitofp i64 %12 to float
%14 = fdiv float 1.000000e+00, %13
%15 = load i32, i32* %4
%16 = call i64 @fact(i32 %15)
%17 = sitofp i64 %16 to float
%18 = fdiv float 1.000000e+00, %17
%19 = fsub float %14, %18
store float %19, float* %2
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = call i64 @fact(i32 %20)
%23 = sitofp i64 %22 to float
%24 = fdiv float 1.000000e+00, %23
%25 = load float, float* %3
%26 = fadd float %25, %24
store float %26, float* %3
br label %5
27: ; preds = %5
%28 = load float, float* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"ANS: %f \0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 2, %0 ], [ %14, %1 ]
%3 = phi float [ 2.000000e+00, %0 ], [ %18, %1 ]
%4 = add nsw i32 %2, -1
%5 = tail call i64 @fact(i32 %4)
%6 = tail call i64 @fact(i32 %2)
%7 = insertelement <2 x i64> poison, i64 %5, i64 0
%8 = insertelement <2 x i64> %7, i64 %6, i64 1
%9 = sitofp <2 x i64> %8 to <2 x float>
%10 = fdiv <2 x float> <float 1.000000e+00, float 1.000000e+00>, %9
%11 = shufflevector <2 x float> %10, <2 x float> poison, <2 x i32> <i32 1, i32 undef>
%12 = fsub <2 x float> %10, %11
%13 = extractelement <2 x float> %12, i64 0
%14 = add nuw nsw i32 %2, 1
%15 = tail call i64 @fact(i32 %2)
%16 = sitofp i64 %15 to float
%17 = fdiv float 1.000000e+00, %16
%18 = fadd float %3, %17
%19 = fpext float %13 to double
%20 = fcmp ogt double %19, 1.000000e-05
br i1 %20, label %1, label %21
21: ; preds = %1
%22 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %18)
ret i32 0
}