double myexp(double x) {
  int n = 0;
  double psum, sum = 1.0, item = 1.0;
  do {
    psum = sum;
    sum += item = item * (x < 0 ? -x : x) / ++n;
  } while (sum != psum);
  return x < 0 ? 1 / sum : sum;
}


x86 assembly (clang, -O0):
<myexp>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movsd  0xee8(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1172 <myexp+0x72>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    117c <myexp+0x7c>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    112a <myexp+0x2a>
jp     112a <myexp+0x2a>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11e5 <myexp+0xe5>
movsd  0xe2a(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11ef <myexp+0xef>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<myexp>:
movapd 0xef8(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm3,%xmm3
movapd %xmm0,%xmm2
cmpltsd %xmm3,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movsd  0xee3(%rip),%xmm1
mov    $0x1,%eax
movapd %xmm1,%xmm3
cs nopw 0x0(%rax,%rax,1)
movapd %xmm1,%xmm4
mulsd  %xmm2,%xmm3
xorps  %xmm5,%xmm5
cvtsi2sd %eax,%xmm5
divsd  %xmm5,%xmm3
addsd  %xmm3,%xmm1
add    $0x1,%eax
ucomisd %xmm4,%xmm1
jne    1140 <myexp+0x40>
jp     1140 <myexp+0x40>
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jbe    117c <myexp+0x7c>
movsd  0xe9c(%rip),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @myexp(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %2
store i32 0, i32* %3
store double 1.000000e+00, double* %5
store double 1.000000e+00, double* %6
br label %7
7: ; preds = %26, %1
%8 = load double, double* %5
store double %8, double* %4
%9 = load double, double* %6
%10 = load double, double* %2
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load double, double* %2
%14 = fneg double %13
br label %17
15: ; preds = %7
%16 = load double, double* %2
br label %17
17: ; preds = %15, %12
%18 = phi double [ %14, %12 ], [ %16, %15 ]
%19 = fmul double %9, %18
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
%22 = sitofp i32 %21 to double
%23 = fdiv double %19, %22
store double %23, double* %6
%24 = load double, double* %5
%25 = fadd double %24, %23
store double %25, double* %5
br label %26
26: ; preds = %17
%27 = load double, double* %5
%28 = load double, double* %4
%29 = fcmp une double %27, %28
br i1 %29, label %7, label %30
30: ; preds = %26
%31 = load double, double* %2
%32 = fcmp olt double %31, 0.000000e+00
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load double, double* %5
%35 = fdiv double 1.000000e+00, %34
br label %38
36: ; preds = %30
%37 = load double, double* %5
br label %38
38: ; preds = %36, %33
%39 = phi double [ %35, %33 ], [ %37, %36 ]
ret double %39
}

LLVM IR (-O2):
define double @myexp(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %10, %5 ]
%7 = phi double [ 1.000000e+00, %1 ], [ %13, %5 ]
%8 = phi double [ 1.000000e+00, %1 ], [ %12, %5 ]
%9 = fmul double %4, %8
%10 = add nuw nsw i32 %6, 1
%11 = sitofp i32 %10 to double
%12 = fdiv double %9, %11
%13 = fadd double %7, %12
%14 = fcmp une double %13, %7
br i1 %14, label %5, label %15
15: ; preds = %5
%16 = fdiv double 1.000000e+00, %13
%17 = select i1 %2, double %16, double %13
ret double %17
}