#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 logsum(double log_a, double log_b) {
  return (log_a < log_b ? log_b + log(1.0 + exp(log_a - log_b))
                        : log_a + log(1.0 + exp(log_b - log_a)));
}


x86 assembly (clang, -O0):
<logsum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1190 <logsum+0x70>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe94(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11d5 <logsum+0xb5>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1030 <exp@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe4a(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logsum>:
push   %rax
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm0,%xmm3
subsd  %xmm1,%xmm3
movapd %xmm0,%xmm4
cmpltsd %xmm1,%xmm4
andpd  %xmm4,%xmm3
andnpd %xmm2,%xmm4
orpd   %xmm3,%xmm4
maxsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm4,%xmm0
call   1030 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xe98(%rip),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <log@plt>
addsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @logsum(double %0, double %1) {
%3 = alloca double
%4 = alloca double
store double %0, double* %3
store double %1, double* %4
%5 = load double, double* %3
%6 = load double, double* %4
%7 = fcmp olt double %5, %6
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load double, double* %4
%10 = load double, double* %3
%11 = load double, double* %4
%12 = fsub double %10, %11
%13 = call i64 @exp(double %12)
%14 = sitofp i64 %13 to double
%15 = fadd double 1.000000e+00, %14
%16 = fptosi double %15 to i64
%17 = call double @log(i64 %16)
%18 = fadd double %9, %17
br label %30
19: ; preds = %2
%20 = load double, double* %3
%21 = load double, double* %4
%22 = load double, double* %3
%23 = fsub double %21, %22
%24 = call i64 @exp(double %23)
%25 = sitofp i64 %24 to double
%26 = fadd double 1.000000e+00, %25
%27 = fptosi double %26 to i64
%28 = call double @log(i64 %27)
%29 = fadd double %20, %28
br label %30
30: ; preds = %19, %8
%31 = phi double [ %18, %8 ], [ %29, %19 ]
ret double %31
}

LLVM IR (-O2):
define double @logsum(double %0, double %1) {
%3 = fcmp olt double %0, %1
%4 = fsub double %1, %0
%5 = fsub double %0, %1
%6 = select i1 %3, double %5, double %4
%7 = select i1 %3, double %1, double %0
%8 = tail call i64 @exp(double %6)
%9 = sitofp i64 %8 to double
%10 = fadd double %9, 1.000000e+00
%11 = fptosi double %10 to i64
%12 = tail call double @log(i64 %11)
%13 = fadd double %12, %7
ret double %13
}