#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 */
scalar_t__ exp(double);
double log(scalar_t__);
double addlog(double x, double y) {
  double d = x - y;
  if (d > 0) {
    d = -d;
    y = x;
  }
  if (d < -44)
    return y;
  return y + log(1 + exp(d));
}


x86 assembly (clang, -O0):
<addlog>:
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    117e <addlog+0x5e>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe7a(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11a0 <addlog+0x80>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d1 <addlog+0xb1>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <exp@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addlog>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
cmpltsd %xmm0,%xmm3
andpd  %xmm3,%xmm2
andnpd %xmm1,%xmm3
orpd   %xmm2,%xmm3
jbe    114f <addlog+0x2f>
xorpd  0xeb1(%rip),%xmm0
movsd  0xeb9(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1179 <addlog+0x59>
movapd %xmm3,(%rsp)
call   1030 <exp@plt>
lea    0x1(%rax),%rdi
call   1040 <log@plt>
movapd (%rsp),%xmm3
addsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @addlog(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 %16
12: ; preds = %2
%13 = load double, double* %6
%14 = fneg double %13
store double %14, double* %6
%15 = load double, double* %4
store double %15, double* %5
br label %16
16: ; preds = %12, %2
%17 = load double, double* %6
%18 = fcmp olt double %17, -4.400000e+01
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load double, double* %5
store double %20, double* %3
br label %28
21: ; preds = %16
%22 = load double, double* %5
%23 = load double, double* %6
%24 = call i64 @exp(double %23)
%25 = add nsw i64 1, %24
%26 = call double @log(i64 %25)
%27 = fadd double %22, %26
store double %27, double* %3
br label %28
28: ; preds = %21, %19
%29 = load double, double* %3
ret double %29
}

LLVM IR (-O2):
define double @addlog(double %0, double %1) {
%3 = fsub double %0, %1
%4 = fcmp ogt double %3, 0.000000e+00
%5 = fneg double %3
%6 = select i1 %4, double %0, double %1
%7 = select i1 %4, double %5, double %3
%8 = fcmp olt double %7, -4.400000e+01
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = tail call i64 @exp(double %7)
%11 = add nsw i64 %10, 1
%12 = tail call double @log(i64 %11)
%13 = fadd double %6, %12
br label %14
14: ; preds = %2, %9
%15 = phi double [ %13, %9 ], [ %6, %2 ]
ret double %15
}