#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 exp(double);
double log(double);
double log_add(double logx, double logy) {
  double swap, diff, minLogExp, z;
  if (logx < logy) {
    swap = logx;
    logx = logy;
    logy = swap;
  }
  diff = logy - logx;
  minLogExp = -log(-(-1.0e+10));
  if (diff < minLogExp)
    return ((logx < (-0.5e+10)) ? (-1.0e+10) : logx);
  else {
    z = exp(diff);
    return (logx + log(1.0 + z));
  }
}


x86 assembly (clang, -O0):
<log_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1164 <log_add+0x44>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe85(%rip),%xmm0
call   1040 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ee <log_add+0xce>
movsd  0xe58(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d5 <log_add+0xb5>
movsd  0xe4d(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11df <log_add+0xbf>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122a <log_add+0x10a>
movsd  -0x28(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdf9(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_add>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
minsd  %xmm1,%xmm0
maxsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  0xec4(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    1168 <log_add+0x48>
movapd %xmm1,%xmm0
cmpltsd 0xec1(%rip),%xmm0
movsd  0xec1(%rip),%xmm2
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
add    $0x18,%rsp
ret
movapd %xmm1,(%rsp)
call   1030 <exp@plt>
addsd  0xe8e(%rip),%xmm0
call   1040 <log@plt>
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @log_add(double %0, double %1) {
%3 = fcmp olt double %0, %1
%4 = select i1 %3, double %0, double %1
%5 = select i1 %3, double %1, double %0
%6 = fsub double %4, %5
%7 = fcmp olt double %6, 0xC037069E2AA2AA5B
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = fcmp olt double %5, -5.000000e+09
%10 = select i1 %9, double -1.000000e+10, double %5
br label %16
11: ; preds = %2
%12 = tail call double @exp(double %6)
%13 = fadd double %12, 1.000000e+00
%14 = tail call double @log(double %13)
%15 = fadd double %5, %14
br label %16
16: ; preds = %11, %8
%17 = phi double [ %10, %8 ], [ %15, %11 ]
ret double %17
}