#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(float);
float exp(float x) {
  float result = 1.0;
  unsigned n = 1;
  float power = 1.0;
  float factorial = 1.0;
  float old = 0.0;
  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
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xedb(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movss  0xec7(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xeba(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c5 <exp+0xb5>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2ss %rax,%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
divss  -0x14(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <exp+0x43>
movss  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exp>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,(%rsp)
movss  0xede(%rip),%xmm0
call   1030 <fabs@plt>
ucomisd 0xed9(%rip),%xmm0
jbe    11aa <exp+0x9a>
mov    $0x1,%ebx
movss  0xec6(%rip),%xmm2
movaps %xmm2,%xmm3
movaps %xmm2,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mulss  (%rsp),%xmm3
movss  %xmm3,0x8(%rsp)
mov    %ebx,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
mulss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
divss  %xmm2,%xmm3
addss  %xmm0,%xmm3
movss  %xmm3,0x4(%rsp)
add    $0x1,%ebx
subss  %xmm3,%xmm0
call   1030 <fabs@plt>
movss  0x4(%rsp),%xmm1
movss  0x8(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
ucomisd 0xe65(%rip),%xmm0
movaps %xmm1,%xmm0
ja     1150 <exp+0x40>
jmp    11b2 <exp+0xa2>
movss  0xe52(%rip),%xmm1
movaps %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

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