#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 fabs(double);
double exp(double x) {
  double result = 1.0;
  unsigned n = 1;
  double power = 1.0;
  double factorial = 1.0;
  double old = 0.0f;
  while (fabs(old - result) > 0.000001) {
    old = result;
    power *= x;
    factorial *= n;
    result += (power / factorial);
    n++;
  }
  return result;
}


x86 assembly (clang, -O0):
<exp>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  0xeef(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xec0(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xeac(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b7 <exp+0xb7>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <exp+0x3f>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<exp>:
mov    $0x1,%eax
movsd  0xef3(%rip),%xmm2
movapd 0xefb(%rip),%xmm3
movsd  0xeeb(%rip),%xmm4
movapd %xmm2,%xmm5
movapd %xmm2,%xmm1
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm1,%xmm6
mulsd  %xmm0,%xmm5
mov    %eax,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %rcx,%xmm1
mulsd  %xmm1,%xmm2
movapd %xmm5,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm6,%xmm1
add    $0x1,%eax
subsd  %xmm1,%xmm6
andpd  %xmm3,%xmm6
ucomisd %xmm4,%xmm6
ja     1130 <exp+0x30>
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @exp(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %2
store double 1.000000e+00, double* %3
store i32 1, i32* %4
store double 1.000000e+00, double* %5
store double 1.000000e+00, double* %6
store double 0.000000e+00, double* %7
br label %8
8: ; preds = %14, %1
%9 = load double, double* %7
%10 = load double, double* %3
%11 = fsub double %9, %10
%12 = call double @llvm.fabs.f64(double %11)
%13 = fcmp ogt double %12, 0x3EB0C6F7A0B5ED8D
br i1 %13, label %14, label %30
14: ; preds = %8
%15 = load double, double* %3
store double %15, double* %7
%16 = load double, double* %2
%17 = load double, double* %5
%18 = fmul double %17, %16
store double %18, double* %5
%19 = load i32, i32* %4
%20 = uitofp i32 %19 to double
%21 = load double, double* %6
%22 = fmul double %21, %20
store double %22, double* %6
%23 = load double, double* %5
%24 = load double, double* %6
%25 = fdiv double %23, %24
%26 = load double, double* %3
%27 = fadd double %26, %25
store double %27, double* %3
%28 = load i32, i32* %4
%29 = add i32 %28, 1
store i32 %29, i32* %4
br label %8
30: ; preds = %8
%31 = load double, double* %3
ret double %31
}

LLVM IR (-O2):
define double @exp(double %0) {
br label %2
2: ; preds = %1, %2
%3 = phi double [ 1.000000e+00, %1 ], [ %9, %2 ]
%4 = phi double [ 1.000000e+00, %1 ], [ %7, %2 ]
%5 = phi i32 [ 1, %1 ], [ %12, %2 ]
%6 = phi double [ 1.000000e+00, %1 ], [ %11, %2 ]
%7 = fmul double %4, %0
%8 = uitofp i32 %5 to double
%9 = fmul double %3, %8
%10 = fdiv double %7, %9
%11 = fadd double %6, %10
%12 = add i32 %5, 1
%13 = fsub double %6, %11
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fcmp ogt double %14, 0x3EB0C6F7A0B5ED8D
br i1 %15, label %2, label %16
16: ; preds = %2
ret double %11
}