#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__ factorial(int);
float calculateEX(int n) {
  int x = 2;
  int numerator = n;
  float result = 1 + numerator / 1.0;
  while (x <= n) {
    numerator *= n;
    result += ((float)numerator / (float)(factorial(x)));
    x++;
  }
  return result;
}


x86 assembly (clang, -O0):
<calculateEX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xecb(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xebf(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     119c <calculateEX+0x8c>
mov    -0x4(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
movss  -0x14(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114e <calculateEX+0x3e>
movss  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateEX>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cvtsi2sd %edi,%xmm0
addsd  0xedd(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
cmp    $0x2,%edi
jl     118b <calculateEX+0x7b>
mov    %edi,%r15d
mov    %edi,%r14d
neg    %r14d
mov    $0x2,%ebx
mov    %edi,%ebp
nopl   0x0(%rax)
movss  %xmm0,0x4(%rsp)
imul   %r15d,%ebp
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movss  %xmm0,(%rsp)
mov    %ebx,%edi
call   1030 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  (%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0x4(%rsp),%xmm0
addss  %xmm1,%xmm0
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1140 <calculateEX+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @calculateEX(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
store i32 %0, i32* %2
store i32 2, i32* %3
%6 = load i32, i32* %2
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = sitofp i32 %7 to double
%9 = fdiv double %8, 1.000000e+00
%10 = fadd double 1.000000e+00, %9
%11 = fptrunc double %10 to float
store float %11, float* %5
br label %12
12: ; preds = %16, %1
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, %17
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = sitofp i32 %20 to float
%22 = load i32, i32* %3
%23 = call i64 @factorial(i32 %22)
%24 = sitofp i64 %23 to float
%25 = fdiv float %21, %24
%26 = load float, float* %5
%27 = fadd float %26, %25
store float %27, float* %5
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %12
30: ; preds = %12
%31 = load float, float* %5
ret float %31
}

LLVM IR (-O2):
define float @calculateEX(i32 %0) {
%2 = sitofp i32 %0 to double
%3 = fadd double %2, 1.000000e+00
%4 = fptrunc double %3 to float
%5 = icmp slt i32 %0, 2
br i1 %5, label %18, label %6
6: ; preds = %1, %6
%7 = phi float [ %15, %6 ], [ %4, %1 ]
%8 = phi i32 [ %10, %6 ], [ %0, %1 ]
%9 = phi i32 [ %16, %6 ], [ 2, %1 ]
%10 = mul nsw i32 %8, %0
%11 = sitofp i32 %10 to float
%12 = tail call i64 @factorial(i32 %9)
%13 = sitofp i64 %12 to float
%14 = fdiv float %11, %13
%15 = fadd float %7, %14
%16 = add nuw i32 %9, 1
%17 = icmp eq i32 %9, %0
br i1 %17, label %18, label %6
18: ; preds = %6, %1
%19 = phi float [ %4, %1 ], [ %15, %6 ]
ret float %19
}