#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 */
double fatorial(int);
double calcSoma(int n) {
  double s = 1;
  int i, numerador = 0, valFat = 1;
  for (i = 0; i < n; i++) {
    numerador = numerador + 2;
    valFat = valFat + 2;
    s = s + (double)numerador / fatorial(valFat);
  }
  return s;
}


x86 assembly (clang, -O0):
<calcSoma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xedd(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119f <calcSoma+0x8f>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <fatorial@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <calcSoma+0x2d>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcSoma>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    116b <calcSoma+0x5b>
mov    %edi,%ebp
movsd  0xedc(%rip),%xmm0
mov    $0x3,%ebx
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
lea    -0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1030 <fatorial@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x2,%ebx
add    $0xffffffff,%ebp
jne    1130 <calcSoma+0x20>
jmp    1173 <calcSoma+0x63>
movsd  0xe8d(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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