#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 NAN;
double exp(double);
double log1p(double);
double log1pexp(double x) {
  if (x != x) {
    return NAN;
  }
  if (x <= -37.0) {
    return exp(x);
  }
  if (x <= 18.0) {
    return log1p(exp(x));
  }
  if (x <= 33.3) {
    return x + exp(-x);
  }
  return x;
}


x86 assembly (clang, -O0):
<log1pexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1148 <log1pexp+0x28>
jp     1148 <log1pexp+0x28>
jmp    115d <log1pexp+0x3d>
mov    0x2ea9(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120e <log1pexp+0xee>
movsd  0xe9b(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1184 <log1pexp+0x64>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    120e <log1pexp+0xee>
movsd  0xe7c(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11b0 <log1pexp+0x90>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
call   1040 <log1p@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    120e <log1pexp+0xee>
movsd  0xe58(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1204 <log1pexp+0xe4>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120e <log1pexp+0xee>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log1pexp>:
sub    $0x18,%rsp
ucomisd %xmm0,%xmm0
jp     119f <log1pexp+0x7f>
movapd %xmm0,%xmm1
movsd  0xeca(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    1180 <log1pexp+0x60>
movsd  0xec4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    118d <log1pexp+0x6d>
movsd  0xebe(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1177 <log1pexp+0x57>
movapd 0xec0(%rip),%xmm0
xorpd  %xmm1,%xmm0
movapd %xmm1,(%rsp)
call   1030 <exp@plt>
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret
movapd %xmm1,%xmm0
add    $0x18,%rsp
jmp    1030 <exp@plt>
movapd %xmm1,%xmm0
call   1030 <exp@plt>
add    $0x18,%rsp
jmp    1040 <log1p@plt>
mov    0x2e52(%rip),%rax
movsd  (%rax),%xmm1
jmp    1177 <log1pexp+0x57>

LLVM IR (-O0):
@NAN = global double 0.000000e+00
define double @log1pexp(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = load double, double* %3
%6 = fcmp une double %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load double, double* @NAN
store double %8, double* %2
br label %33
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp ole double %10, -3.700000e+01
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %3
%14 = call double @exp(double %13)
store double %14, double* %2
br label %33
15: ; preds = %9
%16 = load double, double* %3
%17 = fcmp ole double %16, 1.800000e+01
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load double, double* %3
%20 = call double @exp(double %19)
%21 = call double @log1p(double %20)
store double %21, double* %2
br label %33
22: ; preds = %15
%23 = load double, double* %3
%24 = fcmp ole double %23, 3.330000e+01
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load double, double* %3
%27 = load double, double* %3
%28 = fneg double %27
%29 = call double @exp(double %28)
%30 = fadd double %26, %29
store double %30, double* %2
br label %33
31: ; preds = %22
%32 = load double, double* %3
store double %32, double* %2
br label %33
33: ; preds = %31, %25, %18, %12, %7
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
define double @log1pexp(double %0) {
%2 = fcmp uno double %0, 0.000000e+00
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = load double, double* @NAN
br label %20
5: ; preds = %1
%6 = fcmp ugt double %0, -3.700000e+01
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call double @exp(double %0)
br label %20
9: ; preds = %5
%10 = fcmp ugt double %0, 1.800000e+01
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = tail call double @exp(double %0)
%13 = tail call double @log1p(double %12)
br label %20
14: ; preds = %9
%15 = fcmp ugt double %0, 3.330000e+01
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = fneg double %0
%18 = tail call double @exp(double %17)
%19 = fadd double %18, %0
br label %20
20: ; preds = %14, %16, %11, %7, %3
%21 = phi double [ %4, %3 ], [ %8, %7 ], [ %13, %11 ], [ %19, %16 ], [ %0, %14 ]
ret double %21
}