#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 */
int /*<<< orphan*/ ERANGE;
float HUGE_VALF;
int /*<<< orphan*/ errno;
float ldexpf(float, int);
float expf(const float x) {
  int n;
  float xn, g, r, z, y;
  bool sign;
  if (x >= 0.0) {
    y = x;
    sign = 0;
  } else {
    y = -x;
    sign = 1;
  }
  if (y < 1.0E-7)
    return 1.0;
  if (y > 88.72283911) {
    if (sign) {
      errno = ERANGE;
      return HUGE_VALF;
    } else {
      return 0.0;
    }
  }
  z = y * 1.4426950409;
  n = z;
  if (n < 0)
    --n;
  if (z - n >= 0.5)
    ++n;
  xn = n;
  g = ((y - xn * 0.693359375)) - xn * -2.1219444005469058277e-4;
  z = g * g;
  r = ((0.4160288626E-2 * z) + 0.2499999995E+0) * g;
  r = 0.5 + (r / (((0.4998717877E-1 * z) + 0.5000000000E+0) - r));
  n++;
  z = ldexpf(r, n);
  if (sign)
    return 1.0 / z;
  else
    return z;
}


x86 assembly (clang, -O0):
<expf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1149 <expf+0x39>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    1167 <expf+0x57>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe88(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1194 <expf+0x84>
movss  0xec6(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b7 <expf+0x2a7>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe63(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ed <expf+0xdd>
cmpl   $0x0,-0x24(%rbp)
je     11e0 <expf+0xd0>
mov    0x2e20(%rip),%rax
mov    (%rax),%ecx
mov    0x2e07(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e1e(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b7 <expf+0x2a7>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b7 <expf+0x2a7>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe12(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
cvttss2si -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1226 <expf+0x116>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdd8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1253 <expf+0x143>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdb2(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd7a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd39(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd35(%rip),%xmm1
addsd  %xmm1,%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xcf1(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xcdd(%rip),%xmm2
addsd  %xmm2,%xmm0
movss  -0x18(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
subsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xcc0(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movss  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1030 <ldexpf@plt>
movss  %xmm0,-0x1c(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     13ad <expf+0x29d>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xcad(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b7 <expf+0x2a7>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expf>:
sub    $0x18,%rsp
movaps %xmm0,%xmm2
movaps 0xee2(%rip),%xmm0
xorps  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cmpnless %xmm2,%xmm1
andps  %xmm1,%xmm0
andnps %xmm2,%xmm1
orps   %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
movsd  0xed7(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1154 <expf+0x44>
movss  0xec1(%rip),%xmm0
add    $0x18,%rsp
ret
ucomisd 0xec4(%rip),%xmm0
jbe    118c <expf+0x7c>
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jae    126a <expf+0x15a>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    0x2e56(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e6d(%rip),%rax
movss  (%rax),%xmm0
add    $0x18,%rsp
ret
movsd  0xe94(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
cvttss2si %xmm1,%eax
mov    %eax,%edi
sar    $0x1f,%edi
add    %eax,%edi
movaps %xmm2,(%rsp)
xorps  %xmm2,%xmm2
cvtsi2ss %edi,%xmm2
subss  %xmm2,%xmm1
ucomiss 0xe57(%rip),%xmm1
sbb    $0xffffffff,%edi
xorps  %xmm1,%xmm1
cvtsi2ss %edi,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe5d(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  0xe59(%rip),%xmm1
addsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulss  %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3b(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe37(%rip),%xmm2
mulsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtsd2ss %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe28(%rip),%xmm0
movsd  0xe28(%rip),%xmm2
addsd  %xmm2,%xmm0
subsd  %xmm1,%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
add    $0x1,%edi
call   1030 <ldexpf@plt>
xorps  %xmm1,%xmm1
movaps (%rsp),%xmm2
ucomiss %xmm1,%xmm2
jae    126a <expf+0x15a>
movss  0xdad(%rip),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VALF = global float 0.000000e+00
define float @expf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
store float %0, float* %3
%11 = load float, float* %3
%12 = fpext float %11 to double
%13 = fcmp oge double %12, 0.000000e+00
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load float, float* %3
store float %15, float* %9
store i32 0, i32* %10
br label %19
16: ; preds = %1
%17 = load float, float* %3
%18 = fneg float %17
store float %18, float* %9
store i32 1, i32* %10
br label %19
19: ; preds = %16, %14
%20 = load float, float* %9
%21 = fpext float %20 to double
%22 = fcmp olt double %21, 0x3E7AD7F29ABCAF48
br i1 %22, label %23, label %24
23: ; preds = %19
store float 1.000000e+00, float* %2
br label %106
24: ; preds = %19
%25 = load float, float* %9
%26 = fpext float %25 to double
%27 = fcmp ogt double %26, 0x40562E42FEF86E10
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @ERANGE
store i32 %32, i32* @errno
%33 = load float, float* @HUGE_VALF
store float %33, float* %2
br label %106
34: ; preds = %28
store float 0.000000e+00, float* %2
br label %106
35: ; preds = %24
%36 = load float, float* %9
%37 = fpext float %36 to double
%38 = fmul double %37, 0x3FF71547652C4526
%39 = fptrunc double %38 to float
store float %39, float* %8
%40 = load float, float* %8
%41 = fptosi float %40 to i32
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %35
%45 = load i32, i32* %4
%46 = add nsw i32 %45, -1
store i32 %46, i32* %4
br label %47
47: ; preds = %44, %35
%48 = load float, float* %8
%49 = load i32, i32* %4
%50 = sitofp i32 %49 to float
%51 = fsub float %48, %50
%52 = fpext float %51 to double
%53 = fcmp oge double %52, 5.000000e-01
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %57
57: ; preds = %54, %47
%58 = load i32, i32* %4
%59 = sitofp i32 %58 to float
store float %59, float* %5
%60 = load float, float* %9
%61 = fpext float %60 to double
%62 = load float, float* %5
%63 = fpext float %62 to double
%64 = fneg double %63
%65 = call double @llvm.fmuladd.f64(double %64, double 0x3FE6300000000000, double %61)
%66 = load float, float* %5
%67 = fpext float %66 to double
%68 = fneg double %67
%69 = call double @llvm.fmuladd.f64(double %68, double 0xBF2BD0105C610CA8, double %65)
%70 = fptrunc double %69 to float
store float %70, float* %6
%71 = load float, float* %6
%72 = load float, float* %6
%73 = fmul float %71, %72
store float %73, float* %8
%74 = load float, float* %8
%75 = fpext float %74 to double
%76 = call double @llvm.fmuladd.f64(double 0x3F710A60F9730F50, double %75, double 0x3FCFFFFFFEED1F41)
%77 = load float, float* %6
%78 = fpext float %77 to double
%79 = fmul double %76, %78
%80 = fptrunc double %79 to float
store float %80, float* %7
%81 = load float, float* %7
%82 = fpext float %81 to double
%83 = load float, float* %8
%84 = fpext float %83 to double
%85 = call double @llvm.fmuladd.f64(double 0x3FA997EB6412AA4C, double %84, double 5.000000e-01)
%86 = load float, float* %7
%87 = fpext float %86 to double
%88 = fsub double %85, %87
%89 = fdiv double %82, %88
%90 = fadd double 5.000000e-01, %89
%91 = fptrunc double %90 to float
store float %91, float* %7
%92 = load i32, i32* %4
%93 = add nsw i32 %92, 1
store i32 %93, i32* %4
%94 = load float, float* %7
%95 = load i32, i32* %4
%96 = call float @ldexpf(float %94, i32 %95)
store float %96, float* %8
%97 = load i32, i32* %10
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %104
99: ; preds = %57
%100 = load float, float* %8
%101 = fpext float %100 to double
%102 = fdiv double 1.000000e+00, %101
%103 = fptrunc double %102 to float
store float %103, float* %2
br label %106
104: ; preds = %57
%105 = load float, float* %8
store float %105, float* %2
br label %106
106: ; preds = %104, %99, %34, %31, %23
%107 = load float, float* %2
ret float %107
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VALF = global float 0.000000e+00
define float @expf(float %0) {
%2 = fcmp ult float %0, 0.000000e+00
%3 = fneg float %0
%4 = select i1 %2, float %3, float %0
%5 = fpext float %4 to double
%6 = fcmp olt double %5, 0x3E7AD7F29ABCAF48
br i1 %6, label %46, label %7
7: ; preds = %1
%8 = fcmp ogt double %5, 0x40562E42FEF86E10
br i1 %8, label %9, label %13
9: ; preds = %7
br i1 %2, label %10, label %46
10: ; preds = %9
%11 = load i32, i32* @ERANGE
store i32 %11, i32* @errno
%12 = load float, float* @HUGE_VALF
br label %46
13: ; preds = %7
%14 = fmul double %5, 0x3FF71547652C4526
%15 = fptrunc double %14 to float
%16 = fptosi float %15 to i32
%17 = ashr i32 %16, 31
%18 = add nsw i32 %17, %16
%19 = sitofp i32 %18 to float
%20 = fsub float %15, %19
%21 = fcmp oge float %20, 5.000000e-01
%22 = zext i1 %21 to i32
%23 = add nuw nsw i32 %18, %22
%24 = sitofp i32 %23 to float
%25 = fpext float %24 to double
%26 = fneg double %25
%27 = tail call double @llvm.fmuladd.f64(double %26, double 0x3FE6300000000000, double %5)
%28 = tail call double @llvm.fmuladd.f64(double %26, double 0xBF2BD0105C610CA8, double %27)
%29 = fptrunc double %28 to float
%30 = fmul float %29, %29
%31 = fpext float %30 to double
%32 = tail call double @llvm.fmuladd.f64(double %31, double 0x3F710A60F9730F50, double 0x3FCFFFFFFEED1F41)
%33 = fpext float %29 to double
%34 = fmul double %32, %33
%35 = fptrunc double %34 to float
%36 = fpext float %35 to double
%37 = tail call double @llvm.fmuladd.f64(double %31, double 0x3FA997EB6412AA4C, double 5.000000e-01)
%38 = fsub double %37, %36
%39 = fdiv double %36, %38
%40 = fadd double %39, 5.000000e-01
%41 = fptrunc double %40 to float
%42 = add nsw i32 %23, 1
%43 = tail call float @ldexpf(float %41, i32 %42)
br i1 %2, label %44, label %46
44: ; preds = %13
%45 = fdiv float 1.000000e+00, %43
br label %46
46: ; preds = %13, %9, %1, %44, %10
%47 = phi float [ %12, %10 ], [ %45, %44 ], [ 1.000000e+00, %1 ], [ 0.000000e+00, %9 ], [ %43, %13 ]
ret float %47
}