#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 DBL_EPSILON;
int exp(double);
double fabs(double);
double log1p(double);
double expm1(double x) {
  double y, a = fabs(x);
  if (a < DBL_EPSILON)
    return x;
  if (a > 0.697)
    return exp(x) - 1;
  if (a > 1e-8)
    y = exp(x) - 1;
  else
    y = (x / 2 + 1) * x;
  y -= (1 + y) * (log1p(y) - x);
  return y;
}


x86 assembly (clang, -O0):
<expm1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xec7(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
mov    0x2e9a(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    116b <expm1+0x4b>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1252 <expm1+0x132>
movsd  -0x20(%rbp),%xmm0
movsd  0xe98(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119d <expm1+0x7d>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1252 <expm1+0x132>
movsd  -0x20(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cf <expm1+0xaf>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11f6 <expm1+0xd6>
movsd  -0x10(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe38(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe22(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log1p@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expm1>:
sub    $0x28,%rsp
movapd 0xed4(%rip),%xmm2
andpd  %xmm0,%xmm2
mov    0x2eb1(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm2,%xmm1
ja     11d5 <expm1+0xb5>
ucomisd 0xec3(%rip),%xmm2
jbe    1163 <expm1+0x43>
call   1030 <exp@plt>
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x28,%rsp
ret
ucomisd 0xead(%rip),%xmm2
movapd %xmm0,0x10(%rsp)
jbe    1184 <expm1+0x64>
call   1030 <exp@plt>
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
jmp    119c <expm1+0x7c>
movsd  0xe94(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe90(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xe7f(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
call   1040 <log1p@plt>
subsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@DBL_EPSILON = global double 0.000000e+00
define double @expm1(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = call double @llvm.fabs.f64(double %6)
store double %7, double* %5
%8 = load double, double* %5
%9 = load double, double* @DBL_EPSILON
%10 = fcmp olt double %8, %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load double, double* %3
store double %12, double* %2
br label %46
13: ; preds = %1
%14 = load double, double* %5
%15 = fcmp ogt double %14, 6.970000e-01
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load double, double* %3
%18 = call i32 @exp(double %17)
%19 = sub nsw i32 %18, 1
%20 = sitofp i32 %19 to double
store double %20, double* %2
br label %46
21: ; preds = %13
%22 = load double, double* %5
%23 = fcmp ogt double %22, 1.000000e-08
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load double, double* %3
%26 = call i32 @exp(double %25)
%27 = sub nsw i32 %26, 1
%28 = sitofp i32 %27 to double
store double %28, double* %4
br label %35
29: ; preds = %21
%30 = load double, double* %3
%31 = fdiv double %30, 2.000000e+00
%32 = fadd double %31, 1.000000e+00
%33 = load double, double* %3
%34 = fmul double %32, %33
store double %34, double* %4
br label %35
35: ; preds = %29, %24
%36 = load double, double* %4
%37 = fadd double 1.000000e+00, %36
%38 = load double, double* %4
%39 = call double @log1p(double %38)
%40 = load double, double* %3
%41 = fsub double %39, %40
%42 = load double, double* %4
%43 = fneg double %37
%44 = call double @llvm.fmuladd.f64(double %43, double %41, double %42)
store double %44, double* %4
%45 = load double, double* %4
store double %45, double* %2
br label %46
46: ; preds = %35, %16, %11
%47 = load double, double* %2
ret double %47
}

LLVM IR (-O2):
@DBL_EPSILON = global double 0.000000e+00
define double @expm1(double %0) {
%2 = tail call double @llvm.fabs.f64(double %0)
%3 = load double, double* @DBL_EPSILON
%4 = fcmp olt double %2, %3
br i1 %4, label %28, label %5
5: ; preds = %1
%6 = fcmp ogt double %2, 6.970000e-01
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = tail call i32 @exp(double %0)
%9 = add nsw i32 %8, -1
%10 = sitofp i32 %9 to double
br label %28
11: ; preds = %5
%12 = fcmp ogt double %2, 1.000000e-08
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = tail call i32 @exp(double %0)
%15 = add nsw i32 %14, -1
%16 = sitofp i32 %15 to double
br label %21
17: ; preds = %11
%18 = fmul double %0, 5.000000e-01
%19 = fadd double %18, 1.000000e+00
%20 = fmul double %19, %0
br label %21
21: ; preds = %17, %13
%22 = phi double [ %16, %13 ], [ %20, %17 ]
%23 = fadd double %22, 1.000000e+00
%24 = tail call double @log1p(double %22)
%25 = fsub double %24, %0
%26 = fneg double %23
%27 = tail call double @llvm.fmuladd.f64(double %26, double %25, double %22)
br label %28
28: ; preds = %1, %21, %7
%29 = phi double [ %10, %7 ], [ %27, %21 ], [ %0, %1 ]
ret double %29
}