#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 factorial(unsigned int);
double pow(int, unsigned int);
double exponencial(int x, float tol) {
  double result = 0, term;
  unsigned i = 0;
  do {
    term = pow(x, i) / factorial(i);
    result += term;
    i++;
  } while (term >= tol);
  return result;
}


x86 assembly (clang, -O0):
<exponencial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    113f <exponencial+0x1f>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exponencial>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebp,%ebp
xorps  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <factorial@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%ebp
ucomisd (%rsp),%xmm1
jae    1140 <exponencial+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @exponencial(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 %0, i32* %3
store float %1, float* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %7
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %3
%10 = load i32, i32* %7
%11 = call double @pow(i32 %9, i32 %10)
%12 = load i32, i32* %7
%13 = call double @factorial(i32 %12)
%14 = fdiv double %11, %13
store double %14, double* %6
%15 = load double, double* %6
%16 = load double, double* %5
%17 = fadd double %16, %15
store double %17, double* %5
%18 = load i32, i32* %7
%19 = add i32 %18, 1
store i32 %19, i32* %7
br label %20
20: ; preds = %8
%21 = load double, double* %6
%22 = load float, float* %4
%23 = fpext float %22 to double
%24 = fcmp oge double %21, %23
br i1 %24, label %8, label %25
25: ; preds = %20
%26 = load double, double* %5
ret double %26
}

LLVM IR (-O2):
define double @exponencial(i32 %0, float %1) {
%3 = fpext float %1 to double
br label %4
4: ; preds = %4, %2
%5 = phi double [ 0.000000e+00, %2 ], [ %10, %4 ]
%6 = phi i32 [ 0, %2 ], [ %11, %4 ]
%7 = tail call double @pow(i32 %0, i32 %6)
%8 = tail call double @factorial(i32 %6)
%9 = fdiv double %7, %8
%10 = fadd double %5, %9
%11 = add i32 %6, 1
%12 = fcmp ult double %9, %3
br i1 %12, label %13, label %4
13: ; preds = %4
ret double %10
}