#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 INFINITY;
double log1pexp(double);
double log_add(double a, double b) {
  if (a == -INFINITY)
    return b;
  if (b == -INFINITY)
    return a;
  return a > b ? a + log1pexp(b - a) : b + log1pexp(a - b);
}


x86 assembly (clang, -O0):
<log_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    0x2eba(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    1168 <log_add+0x58>
jp     1168 <log_add+0x58>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1221 <log_add+0x111>
movsd  -0x18(%rbp),%xmm0
mov    0x2e74(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    11ae <log_add+0x9e>
jp     11ae <log_add+0x9e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1221 <log_add+0x111>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11ed <log_add+0xdd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1030 <log1pexp@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1217 <log_add+0x107>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <log1pexp@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_add>:
push   %rax
mov    0x2ed0(%rip),%rax
movsd  (%rax),%xmm2
xorpd  0xedc(%rip),%xmm2
ucomisd %xmm0,%xmm2
jne    112c <log_add+0x1c>
jnp    117a <log_add+0x6a>
ucomisd %xmm1,%xmm2
jne    113a <log_add+0x2a>
jp     113a <log_add+0x2a>
movapd %xmm0,%xmm1
jmp    117a <log_add+0x6a>
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm0,%xmm4
movapd %xmm0,%xmm3
subsd  %xmm1,%xmm3
movapd %xmm1,%xmm0
cmpltsd %xmm4,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm3,%xmm0
orpd   %xmm2,%xmm0
maxsd  %xmm1,%xmm4
movsd  %xmm4,(%rsp)
call   1030 <log1pexp@plt>
movapd %xmm0,%xmm1
addsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

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

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
define double @log_add(double %0, double %1) {
%3 = load double, double* @INFINITY
%4 = fneg double %3
%5 = fcmp oeq double %4, %0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = fcmp oeq double %4, %1
br i1 %7, label %16, label %8
8: ; preds = %6
%9 = fcmp ogt double %0, %1
%10 = fsub double %1, %0
%11 = fsub double %0, %1
%12 = select i1 %9, double %10, double %11
%13 = select i1 %9, double %0, double %1
%14 = tail call double @log1pexp(double %12)
%15 = fadd double %14, %13
br label %16
16: ; preds = %8, %6, %2
%17 = phi double [ %1, %2 ], [ %0, %6 ], [ %15, %8 ]
ret double %17
}