#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 exp(double);
double log(int);
double add_log(double a, double b, int add_sub) {
  if (a > b)
    return a + log(1 + add_sub * exp(b - a));
  else
    return b + log(1 + add_sub * exp(a - b));
}


x86 assembly (clang, -O0):
<add_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1188 <add_log+0x68>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
mov    -0x2c(%rbp),%edi
imul   %eax,%edi
add    $0x1,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c6 <add_log+0xa6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <exp@plt>
mov    -0x3c(%rbp),%edi
imul   %eax,%edi
add    $0x1,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_log>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movapd %xmm0,%xmm4
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
movapd %xmm1,%xmm0
cmpltsd %xmm4,%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm2,%xmm0
orpd   %xmm3,%xmm0
maxsd  %xmm1,%xmm4
movsd  %xmm4,0x8(%rsp)
call   1030 <exp@plt>
imul   %eax,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <log@plt>
addsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @add_log(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
%8 = load double, double* %5
%9 = load double, double* %6
%10 = fcmp ogt double %8, %9
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load double, double* %5
%13 = load i32, i32* %7
%14 = load double, double* %6
%15 = load double, double* %5
%16 = fsub double %14, %15
%17 = call i32 @exp(double %16)
%18 = mul nsw i32 %13, %17
%19 = add nsw i32 1, %18
%20 = call double @log(i32 %19)
%21 = fadd double %12, %20
store double %21, double* %4
br label %33
22: ; preds = %3
%23 = load double, double* %6
%24 = load i32, i32* %7
%25 = load double, double* %5
%26 = load double, double* %6
%27 = fsub double %25, %26
%28 = call i32 @exp(double %27)
%29 = mul nsw i32 %24, %28
%30 = add nsw i32 1, %29
%31 = call double @log(i32 %30)
%32 = fadd double %23, %31
store double %32, double* %4
br label %33
33: ; preds = %22, %11
%34 = load double, double* %4
ret double %34
}

LLVM IR (-O2):
define double @add_log(double %0, double %1, i32 %2) {
%4 = fcmp ogt double %0, %1
%5 = fsub double %0, %1
%6 = fsub double %1, %0
%7 = select i1 %4, double %6, double %5
%8 = select i1 %4, double %0, double %1
%9 = tail call i32 @exp(double %7)
%10 = mul nsw i32 %9, %2
%11 = add nsw i32 %10, 1
%12 = tail call double @log(i32 %11)
%13 = fadd double %12, %8
ret double %13
}