#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;
double HUGE_VAL;
int /*<<< orphan*/ errno;
int floor(double);
double ldexp(double, int);
double exp(double arg) {
  double fract, temp1, temp2, xsq;
  int ent;
  if (arg == 0)
    return 1;
  if (arg < -10000) {
    errno = ERANGE;
    return 0;
  }
  if (arg > 10000) {
    errno = ERANGE;
    return HUGE_VAL;
  }
  arg *= 1.4426950408889634073599247;
  ent = floor(arg);
  fract = (arg - ent) - 0.5;
  xsq = fract * fract;
  temp1 = ((.6061485330061080841615584556e2 * xsq +
            .3028697169744036299076048876e5) *
               xsq +
           .2080384346694663001443843411e7) *
          fract;
  temp2 = ((xsq + .1749287689093076403844945335e4) * xsq +
           .3277251518082914423057964422e6) *
              xsq +
          .6002720360238832528230907598e7;
  return ldexp(1.4142135623730950488016887 * (temp2 + temp1) / (temp2 - temp1),
               ent);
}


x86 assembly (clang, -O0):
<exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1157 <exp+0x37>
jp     1157 <exp+0x37>
movsd  0xf0b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bd <exp+0x19d>
movsd  0xea1(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1189 <exp+0x69>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e56(%rip),%rax
mov    %ecx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bd <exp+0x19d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c7 <exp+0xa7>
mov    0x2e39(%rip),%rax
mov    (%rax),%ecx
mov    0x2e20(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e2f(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bd <exp+0x19d>
movsd  0xe81(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe4c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe13(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdee(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdd0(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb2(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd95(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  0xd72(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x34(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exp>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1137 <exp+0x17>
jp     1137 <exp+0x17>
movsd  0xecb(%rip),%xmm0
pop    %rax
ret
movsd  0xec9(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    115d <exp+0x3d>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    0x2e7b(%rip),%rcx
mov    %eax,(%rcx)
xorpd  %xmm0,%xmm0
pop    %rax
ret
ucomisd 0xeab(%rip),%xmm0
jbe    1186 <exp+0x66>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    0x2e59(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e68(%rip),%rax
movsd  (%rax),%xmm0
pop    %rax
ret
mulsd  0xe8a(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  0xe70(%rip),%xmm1
movapd %xmm1,%xmm0
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm0
movsd  0xe64(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe60(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe5c(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xe58(%rip),%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe50(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe4c(%rip),%xmm2
movapd %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe44(%rip),%xmm0
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
mov    %eax,%edi
pop    %rax
jmp    1030 <ldexp@plt>

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VAL = global double 0.000000e+00
define double @exp(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double %0, double* %3
%9 = load double, double* %3
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %1
store double 1.000000e+00, double* %2
br label %58
12: ; preds = %1
%13 = load double, double* %3
%14 = fcmp olt double %13, -1.000000e+04
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* @ERANGE
store i32 %16, i32* @errno
store double 0.000000e+00, double* %2
br label %58
17: ; preds = %12
%18 = load double, double* %3
%19 = fcmp ogt double %18, 1.000000e+04
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @ERANGE
store i32 %21, i32* @errno
%22 = load double, double* @HUGE_VAL
store double %22, double* %2
br label %58
23: ; preds = %17
%24 = load double, double* %3
%25 = fmul double %24, 0x3FF71547652B82FE
store double %25, double* %3
%26 = load double, double* %3
%27 = call i32 @floor(double %26)
store i32 %27, i32* %8
%28 = load double, double* %3
%29 = load i32, i32* %8
%30 = sitofp i32 %29 to double
%31 = fsub double %28, %30
%32 = fsub double %31, 5.000000e-01
store double %32, double* %4
%33 = load double, double* %4
%34 = load double, double* %4
%35 = fmul double %33, %34
store double %35, double* %7
%36 = load double, double* %7
%37 = call double @llvm.fmuladd.f64(double 0x404E4EB38350FB05, double %36, double 0x40DD93BE304A75FE)
%38 = load double, double* %7
%39 = call double @llvm.fmuladd.f64(double %37, double %38, double 0x413FBE8058C0FB3F)
%40 = load double, double* %4
%41 = fmul double %39, %40
store double %41, double* %5
%42 = load double, double* %7
%43 = fadd double %42, 0x409B552697F838B7
%44 = load double, double* %7
%45 = call double @llvm.fmuladd.f64(double %43, double %44, double 0x411400B49B73A1FC)
%46 = load double, double* %7
%47 = call double @llvm.fmuladd.f64(double %45, double %46, double 0x4156E608170E272D)
store double %47, double* %6
%48 = load double, double* %6
%49 = load double, double* %5
%50 = fadd double %48, %49
%51 = fmul double 0x3FF6A09E667F3BCD, %50
%52 = load double, double* %6
%53 = load double, double* %5
%54 = fsub double %52, %53
%55 = fdiv double %51, %54
%56 = load i32, i32* %8
%57 = call double @ldexp(double %55, i32 %56)
store double %57, double* %2
br label %58
58: ; preds = %23, %20, %15, %11
%59 = load double, double* %2
ret double %59
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VAL = global double 0.000000e+00
define double @exp(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %30, label %3
3: ; preds = %1
%4 = fcmp olt double %0, -1.000000e+04
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = load i32, i32* @ERANGE
store i32 %6, i32* @errno
br label %30
7: ; preds = %3
%8 = fcmp ogt double %0, 1.000000e+04
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = load i32, i32* @ERANGE
store i32 %10, i32* @errno
%11 = load double, double* @HUGE_VAL
br label %30
12: ; preds = %7
%13 = fmul double %0, 0x3FF71547652B82FE
%14 = tail call i32 @floor(double %13)
%15 = sitofp i32 %14 to double
%16 = fsub double %13, %15
%17 = fadd double %16, -5.000000e-01
%18 = fmul double %17, %17
%19 = tail call double @llvm.fmuladd.f64(double %18, double 0x404E4EB38350FB05, double 0x40DD93BE304A75FE)
%20 = tail call double @llvm.fmuladd.f64(double %19, double %18, double 0x413FBE8058C0FB3F)
%21 = fmul double %17, %20
%22 = fadd double %18, 0x409B552697F838B7
%23 = tail call double @llvm.fmuladd.f64(double %22, double %18, double 0x411400B49B73A1FC)
%24 = tail call double @llvm.fmuladd.f64(double %23, double %18, double 0x4156E608170E272D)
%25 = fadd double %24, %21
%26 = fmul double %25, 0x3FF6A09E667F3BCD
%27 = fsub double %24, %21
%28 = fdiv double %26, %27
%29 = tail call double @ldexp(double %28, i32 %14)
br label %30
30: ; preds = %1, %12, %9, %5
%31 = phi double [ 0.000000e+00, %5 ], [ %11, %9 ], [ %29, %12 ], [ 1.000000e+00, %1 ]
ret double %31
}