#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 */
int /*<<< orphan*/ exp(double);
double log1p(int /*<<< orphan*/);
double log_diff(double log_a, double log_b) {
  if (log_a >= log_b) {
    return log_a + log1p(-exp(log_b - log_a));
  } else {
    return log_b + log1p(-exp(log_a - log_b));
  }
}


x86 assembly (clang, -O0):
<log_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     117a <log_diff+0x5a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1040 <log1p@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ad <log_diff+0x8d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <exp@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1040 <log1p@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):
<log_diff>:
ucomisd %xmm1,%xmm0
jb     1130 <log_diff+0x10>
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
jmp    1138 <log_diff+0x18>
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
sub    $0x18,%rsp
movapd %xmm1,%xmm3
cmpnlesd %xmm0,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,(%rsp)
movapd %xmm2,%xmm0
call   1030 <exp@plt>
neg    %eax
mov    %eax,%edi
call   1040 <log1p@plt>
addsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @log_diff(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* %5
%8 = fcmp oge double %6, %7
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load double, double* %4
%11 = load double, double* %5
%12 = load double, double* %4
%13 = fsub double %11, %12
%14 = call i32 @exp(double %13)
%15 = sub nsw i32 0, %14
%16 = call double @log1p(i32 %15)
%17 = fadd double %10, %16
store double %17, double* %3
br label %27
18: ; preds = %2
%19 = load double, double* %5
%20 = load double, double* %4
%21 = load double, double* %5
%22 = fsub double %20, %21
%23 = call i32 @exp(double %22)
%24 = sub nsw i32 0, %23
%25 = call double @log1p(i32 %24)
%26 = fadd double %19, %25
store double %26, double* %3
br label %27
27: ; preds = %18, %9
%28 = load double, double* %3
ret double %28
}

LLVM IR (-O2):
define double @log_diff(double %0, double %1) {
%3 = fcmp ult double %0, %1
%4 = fsub double %0, %1
%5 = fsub double %1, %0
%6 = select i1 %3, double %4, double %5
%7 = select i1 %3, double %1, double %0
%8 = tail call i32 @exp(double %6)
%9 = sub nsw i32 0, %8
%10 = tail call double @log1p(i32 %9)
%11 = fadd double %10, %7
ret double %11
}