#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;
int /*<<< orphan*/ exp(double);
int /*<<< orphan*/ expm1(double);
double log(int /*<<< orphan*/);
double log1p(int /*<<< orphan*/);
double log1mexp(double x) {
  if (x != x) {
    return NAN;
  }
  if (x < 0.0) {
    x = -x;
  }
  if (x > 0.0 && x <= 0.693147180559945309417232121458) {
    return log(-expm1(-x));
  }
  return log1p(-exp(-x));
}


x86 assembly (clang, -O0):
<log1mexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1168 <log1mexp+0x28>
jp     1168 <log1mexp+0x28>
jmp    117d <log1mexp+0x3d>
mov    0x2e89(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1234 <log1mexp+0xf4>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ac <log1mexp+0x6c>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1205 <log1mexp+0xc5>
movsd  0xe3a(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1205 <log1mexp+0xc5>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <expm1@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1040 <log@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1234 <log1mexp+0xf4>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1060 <log1p@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log1mexp>:
push   %rax
ucomisd %xmm0,%xmm0
jp     11aa <log1mexp+0x6a>
movapd %xmm0,%xmm1
movapd 0xead(%rip),%xmm0
movapd %xmm1,%xmm3
xorpd  %xmm0,%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm1,%xmm2
cmpltsd %xmm4,%xmm2
andpd  %xmm2,%xmm3
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
ucomisd %xmm4,%xmm2
xorpd  %xmm2,%xmm0
jbe    119b <log1mexp+0x5b>
movsd  0xe8a(%rip),%xmm1
ucomisd %xmm2,%xmm1
jb     119b <log1mexp+0x5b>
call   1050 <expm1@plt>
neg    %eax
mov    %eax,%edi
pop    %rax
jmp    1040 <log@plt>
call   1030 <exp@plt>
neg    %eax
mov    %eax,%edi
pop    %rax
jmp    1060 <log1p@plt>
mov    0x2e47(%rip),%rax
movsd  (%rax),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@NAN = global double 0.000000e+00
define double @log1mexp(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 olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %3
%14 = fneg double %13
store double %14, double* %3
br label %15
15: ; preds = %12, %9
%16 = load double, double* %3
%17 = fcmp ogt double %16, 0.000000e+00
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load double, double* %3
%20 = fcmp ole double %19, 0x3FE62E42FEFA39EF
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load double, double* %3
%23 = fneg double %22
%24 = call i32 @expm1(double %23)
%25 = sub nsw i32 0, %24
%26 = call double @log(i32 %25)
store double %26, double* %2
br label %33
27: ; preds = %18, %15
%28 = load double, double* %3
%29 = fneg double %28
%30 = call i32 @exp(double %29)
%31 = sub nsw i32 0, %30
%32 = call double @log1p(i32 %31)
store double %32, double* %2
br label %33
33: ; preds = %27, %21, %7
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
define double @log1mexp(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 %21
5: ; preds = %1
%6 = fcmp olt double %0, 0.000000e+00
%7 = fneg double %0
%8 = select i1 %6, double %7, double %0
%9 = fcmp ogt double %8, 0.000000e+00
%10 = fcmp ole double %8, 0x3FE62E42FEFA39EF
%11 = and i1 %9, %10
%12 = fneg double %8
br i1 %11, label %13, label %17
13: ; preds = %5
%14 = tail call i32 @expm1(double %12)
%15 = sub nsw i32 0, %14
%16 = tail call double @log(i32 %15)
br label %21
17: ; preds = %5
%18 = tail call i32 @exp(double %12)
%19 = sub nsw i32 0, %18
%20 = tail call double @log1p(i32 %19)
br label %21
21: ; preds = %17, %13, %3
%22 = phi double [ %4, %3 ], [ %16, %13 ], [ %20, %17 ]
ret double %22
}