#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);
double log1p(int /*<<< orphan*/);
double logaddexp(double x, double y) {
  double diff;
  if (x != x || y != y) {
    return NAN;
  }
  if (x == y) {
    return x + 0.693147180559945309417232121458;
  }
  diff = x - y;
  if (diff > 0.0) {
    return x + log1p(exp(-diff));
  }
  return y + log1p(exp(diff));
}


x86 assembly (clang, -O0):
<logaddexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1163 <logaddexp+0x43>
jp     1163 <logaddexp+0x43>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1163 <logaddexp+0x43>
jp     1163 <logaddexp+0x43>
jmp    1178 <logaddexp+0x58>
mov    0x2e8e(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    123a <logaddexp+0x11a>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    11a5 <logaddexp+0x85>
jp     11a5 <logaddexp+0x85>
movsd  0xe6a(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    123a <logaddexp+0x11a>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120e <logaddexp+0xee>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
mov    %eax,%edi
call   1040 <log1p@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    123a <logaddexp+0x11a>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <exp@plt>
mov    %eax,%edi
call   1040 <log1p@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logaddexp>:
push   %rax
ucomisd %xmm1,%xmm0
jp     118f <logaddexp+0x6f>
movapd %xmm0,%xmm2
jne    1139 <logaddexp+0x19>
jp     1139 <logaddexp+0x19>
addsd  0xed9(%rip),%xmm2
jmp    1189 <logaddexp+0x69>
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jbe    116f <logaddexp+0x4f>
xorpd  0xead(%rip),%xmm0
movsd  %xmm2,(%rsp)
call   1030 <exp@plt>
mov    %eax,%edi
call   1040 <log1p@plt>
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
jmp    1189 <logaddexp+0x69>
movsd  %xmm1,(%rsp)
call   1030 <exp@plt>
mov    %eax,%edi
call   1040 <log1p@plt>
movapd %xmm0,%xmm2
addsd  (%rsp),%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret
mov    0x2e62(%rip),%rax
movsd  (%rax),%xmm2
jmp    1189 <logaddexp+0x69>

LLVM IR (-O0):
@NAN = global double 0.000000e+00
define double @logaddexp(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %4
%8 = load double, double* %4
%9 = fcmp une double %7, %8
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load double, double* %5
%12 = load double, double* %5
%13 = fcmp une double %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10, %2
%15 = load double, double* @NAN
store double %15, double* %3
br label %42
16: ; preds = %10
%17 = load double, double* %4
%18 = load double, double* %5
%19 = fcmp oeq double %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load double, double* %4
%22 = fadd double %21, 0x3FE62E42FEFA39EF
store double %22, double* %3
br label %42
23: ; preds = %16
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fsub double %24, %25
store double %26, double* %6
%27 = load double, double* %6
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load double, double* %4
%31 = load double, double* %6
%32 = fneg double %31
%33 = call i32 @exp(double %32)
%34 = call double @log1p(i32 %33)
%35 = fadd double %30, %34
store double %35, double* %3
br label %42
36: ; preds = %23
%37 = load double, double* %5
%38 = load double, double* %6
%39 = call i32 @exp(double %38)
%40 = call double @log1p(i32 %39)
%41 = fadd double %37, %40
store double %41, double* %3
br label %42
42: ; preds = %36, %29, %20, %14
%43 = load double, double* %3
ret double %43
}

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