#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__ exp2(double);
scalar_t__ isinf(double);
double log2(scalar_t__);
double logplus(double a, double b) {
  if (isinf(a))
    return b;
  if (isinf(b))
    return a;
  if (a > b) {
    double t = b;
    b = a;
    a = t;
  };
  if (b > a + 50)
    return a;
  return a - log2(1 + exp2(a - b));
}


x86 assembly (clang, -O0):
<logplus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1165 <logplus+0x35>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1217 <logplus+0xe7>
movsd  -0x18(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1188 <logplus+0x58>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1217 <logplus+0xe7>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b6 <logplus+0x86>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe3d(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e1 <logplus+0xb1>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1217 <logplus+0xe7>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1040 <exp2@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1030 <log2@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logplus>:
sub    $0x18,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1050 <isinf@plt>
test   %rax,%rax
je     1155 <logplus+0x25>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1170 <logplus+0x40>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm2
movsd  0x10(%rsp),%xmm1
minsd  %xmm1,%xmm2
maxsd  %xmm0,%xmm1
movsd  0xe70(%rip),%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm1
jbe    11a3 <logplus+0x73>
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1040 <exp2@plt>
lea    0x1(%rax),%rdi
call   1030 <log2@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @logplus(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 = call i64 @isinf(double %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load double, double* %5
store double %11, double* %3
br label %42
12: ; preds = %2
%13 = load double, double* %5
%14 = call i64 @isinf(double %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load double, double* %4
store double %17, double* %3
br label %42
18: ; preds = %12
%19 = load double, double* %4
%20 = load double, double* %5
%21 = fcmp ogt double %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load double, double* %5
store double %23, double* %6
%24 = load double, double* %4
store double %24, double* %5
%25 = load double, double* %6
store double %25, double* %4
br label %26
26: ; preds = %22, %18
%27 = load double, double* %5
%28 = load double, double* %4
%29 = fadd double %28, 5.000000e+01
%30 = fcmp ogt double %27, %29
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load double, double* %4
store double %32, double* %3
br label %42
33: ; preds = %26
%34 = load double, double* %4
%35 = load double, double* %4
%36 = load double, double* %5
%37 = fsub double %35, %36
%38 = call i64 @exp2(double %37)
%39 = add nsw i64 1, %38
%40 = call double @log2(i64 %39)
%41 = fsub double %34, %40
store double %41, double* %3
br label %42
42: ; preds = %33, %31, %16, %10
%43 = load double, double* %3
ret double %43
}

LLVM IR (-O2):
define double @logplus(double %0, double %1) {
%3 = tail call i64 @isinf(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = tail call i64 @isinf(double %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = fcmp ogt double %0, %1
%10 = select i1 %9, double %1, double %0
%11 = select i1 %9, double %0, double %1
%12 = fadd double %10, 5.000000e+01
%13 = fcmp ogt double %11, %12
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = fsub double %10, %11
%16 = tail call i64 @exp2(double %15)
%17 = add nsw i64 %16, 1
%18 = tail call double @log2(i64 %17)
%19 = fsub double %10, %18
br label %20
20: ; preds = %8, %5, %2, %14
%21 = phi double [ %19, %14 ], [ %1, %2 ], [ %0, %5 ], [ %10, %8 ]
ret double %21
}