#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 calc_factorial(int);
int /*<<< orphan*/ printf(char *, float);
int main(void) {
  int terms = 20;
  float eular = 0;
  int counter = 0;
  for (counter = 0; counter < terms; counter++) {
    eular = eular + 1. / calc_factorial(counter);
  }
  printf("Eular constant is equal to:%f\n", eular);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119e <main+0x7e>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <calc_factorial@plt>
movsd  -0x18(%rbp),%xmm0
cvtsi2sd %eax,%xmm2
movsd  0xe81(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114c <main+0x2c>
movss  -0xc(%rbp),%xmm0
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1040 <calc_factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xeb0(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
add    $0x1,%ebx
cmp    $0x14,%ebx
jne    1130 <main+0x10>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Eular constant is equal to:%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
store i32 0, i32* %1
store i32 20, i32* %2
store float 0.000000e+00, float* %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %5
5: ; preds = %18, %0
%6 = load i32, i32* %4
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load float, float* %3
%11 = fpext float %10 to double
%12 = load i32, i32* %4
%13 = call i32 @calc_factorial(i32 %12)
%14 = sitofp i32 %13 to double
%15 = fdiv double 1.000000e+00, %14
%16 = fadd double %11, %15
%17 = fptrunc double %16 to float
store float %17, float* %3
br label %18
18: ; preds = %9
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %5
21: ; preds = %5
%22 = load float, float* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), float %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Eular constant is equal to:%f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %10, %1 ]
%3 = phi float [ 0.000000e+00, %0 ], [ %9, %1 ]
%4 = fpext float %3 to double
%5 = tail call i32 @calc_factorial(i32 %2)
%6 = sitofp i32 %5 to double
%7 = fdiv double 1.000000e+00, %6
%8 = fadd double %7, %4
%9 = fptrunc double %8 to float
%10 = add nuw nsw i32 %2, 1
%11 = icmp eq i32 %10, 20
br i1 %11, label %12, label %1
12: ; preds = %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), float %9)
ret i32 0
}