#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);
scalar_t__ isnan(double);
double log(scalar_t__);
double logSum(double x, double y) {
  if (isnan(x))
    return y;
  if (isnan(y))
    return x;
  if (x > y)
    return x + log(1 + exp(y - x));
  return y + log(1 + exp(x - y));
}


x86 assembly (clang, -O0):
<logSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1165 <logSum+0x35>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <logSum+0xd9>
movsd  -0x18(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1188 <logSum+0x58>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <logSum+0xd9>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11d3 <logSum+0xa3>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <logSum+0xd9>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <exp@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <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):
<logSum>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     1155 <logSum+0x25>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret
movsd  0x10(%rsp),%xmm0
call   1040 <isnan@plt>
test   %rax,%rax
je     1170 <logSum+0x40>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm4
movapd %xmm4,%xmm1
movsd  0x10(%rsp),%xmm3
subsd  %xmm3,%xmm1
movapd %xmm3,%xmm2
subsd  %xmm4,%xmm2
movapd %xmm3,%xmm0
cmpltsd %xmm4,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
maxsd  %xmm3,%xmm4
movsd  %xmm4,0x8(%rsp)
call   1030 <exp@plt>
lea    0x1(%rax),%rdi
call   1050 <log@plt>
addsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

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

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