#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*/ exp(double const);
double log1p(int /*<<< orphan*/);
double logaddexp(double x, double y) {
  const double tmp = x - y;
  if (tmp > 0) {
    return x + log1p(exp(-tmp));
  } else if (tmp <= 0) {
    return y + log1p(exp(tmp));
  } else {
    return x + y;
  }
}


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
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <logaddexp+0x7b>
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    11e9 <logaddexp+0xc9>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11da <logaddexp+0xba>
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)
jmp    11e9 <logaddexp+0xc9>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logaddexp>:
push   %rax
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jbe    1142 <logaddexp+0x22>
xorpd  0xec5(%rip),%xmm0
movsd  %xmm2,(%rsp)
jmp    1157 <logaddexp+0x37>
ucomisd %xmm0,%xmm3
jae    1152 <logaddexp+0x32>
addsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret
movsd  %xmm1,(%rsp)
call   1030 <exp@plt>
mov    %eax,%edi
call   1040 <log1p@plt>
addsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
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* %5
%9 = fsub double %7, %8
store double %9, double* %6
%10 = load double, double* %6
%11 = fcmp ogt double %10, 0.000000e+00
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load double, double* %4
%14 = load double, double* %6
%15 = fneg double %14
%16 = call i32 @exp(double %15)
%17 = call double @log1p(i32 %16)
%18 = fadd double %13, %17
store double %18, double* %3
br label %32
19: ; preds = %2
%20 = load double, double* %6
%21 = fcmp ole double %20, 0.000000e+00
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load double, double* %5
%24 = load double, double* %6
%25 = call i32 @exp(double %24)
%26 = call double @log1p(i32 %25)
%27 = fadd double %23, %26
store double %27, double* %3
br label %32
28: ; preds = %19
%29 = load double, double* %4
%30 = load double, double* %5
%31 = fadd double %29, %30
store double %31, double* %3
br label %32
32: ; preds = %28, %22, %12
%33 = load double, double* %3
ret double %33
}

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