#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);
scalar_t__ fast_exact_is_equal(double, double);
double log1p(int /*<<< orphan*/);
double logadd(double log_a, double log_b) {
  if (log_a < log_b) {
    double tmp = log_a;
    log_a = log_b;
    log_b = tmp;
  } else if (fast_exact_is_equal(log_a, log_b)) {
    return 0.693147180559945 + log_a;
  }
  double negative_absolute_difference = log_b - log_a;
  if (negative_absolute_difference < -18.42)
    return (log_a);
  return (log_a + log1p(exp(negative_absolute_difference)));
}


x86 assembly (clang, -O0):
<logadd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1179 <logadd+0x49>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ae <logadd+0x7e>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <fast_exact_is_equal@plt>
cmp    $0x0,%rax
je     11a9 <logadd+0x79>
movsd  0xe66(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120b <logadd+0xdb>
jmp    11ae <logadd+0x7e>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe43(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11df <logadd+0xaf>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120b <logadd+0xdb>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <exp@plt>
mov    %eax,%edi
call   1050 <log1p@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logadd>:
sub    $0x18,%rsp
ucomisd %xmm0,%xmm1
ja     116c <logadd+0x3c>
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
call   1030 <fast_exact_is_equal@plt>
test   %rax,%rax
je     1160 <logadd+0x30>
movsd  0x10(%rsp),%xmm1
addsd  0xea2(%rip),%xmm1
jmp    119a <logadd+0x6a>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe90(%rip),%xmm2
ucomisd %xmm0,%xmm2
ja     119a <logadd+0x6a>
movsd  %xmm1,0x8(%rsp)
call   1040 <exp@plt>
mov    %eax,%edi
call   1050 <log1p@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @logadd(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %4
store double %1, double* %5
%8 = load double, double* %4
%9 = load double, double* %5
%10 = fcmp olt double %8, %9
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load double, double* %4
store double %12, double* %6
%13 = load double, double* %5
store double %13, double* %4
%14 = load double, double* %6
store double %14, double* %5
br label %24
15: ; preds = %2
%16 = load double, double* %4
%17 = load double, double* %5
%18 = call i64 @fast_exact_is_equal(double %16, double %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load double, double* %4
%22 = fadd double 0x3FE62E42FEFA39EC, %21
store double %22, double* %3
br label %38
23: ; preds = %15
br label %24
24: ; preds = %23, %11
%25 = load double, double* %5
%26 = load double, double* %4
%27 = fsub double %25, %26
store double %27, double* %7
%28 = load double, double* %7
%29 = fcmp olt double %28, -1.842000e+01
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = load double, double* %4
store double %31, double* %3
br label %38
32: ; preds = %24
%33 = load double, double* %4
%34 = load double, double* %7
%35 = call i32 @exp(double %34)
%36 = call double @log1p(i32 %35)
%37 = fadd double %33, %36
store double %37, double* %3
br label %38
38: ; preds = %32, %30, %20
%39 = load double, double* %3
ret double %39
}

LLVM IR (-O2):
define double @logadd(double %0, double %1) {
%3 = fcmp olt double %0, %1
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i64 @fast_exact_is_equal(double %0, double %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = fadd double %0, 0x3FE62E42FEFA39EC
br label %18
9: ; preds = %2, %4
%10 = phi double [ %1, %4 ], [ %0, %2 ]
%11 = phi double [ %0, %4 ], [ %1, %2 ]
%12 = fsub double %10, %11
%13 = fcmp olt double %12, -1.842000e+01
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = tail call i32 @exp(double %12)
%16 = tail call double @log1p(i32 %15)
%17 = fadd double %11, %16
br label %18
18: ; preds = %14, %9, %7
%19 = phi double [ %8, %7 ], [ %17, %14 ], [ %11, %9 ]
ret double %19
}