#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 */
double MAX(double, double);
scalar_t__ exp(double);
double log(double);
double f_lnsum(int nr, double eta, double arg1, double arg2) {
  double sum = 0.0, mxm = MAX(arg1, arg2);
  if (eta <= 0.0) {
    return mxm;
  } else {
    sum += exp((arg1 - mxm) / eta);
    sum += exp((arg2 - mxm) / eta);
    return mxm + eta * log(sum);
  }
}


x86 assembly (clang, -O0):
<f_lnsum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <MAX@plt>
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1183 <f_lnsum+0x53>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <f_lnsum+0xd1>
movsd  -0x20(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <exp@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <exp@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_lnsum>:
sub    $0x28,%rsp
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm2,0x20(%rsp)
movaps %xmm2,%xmm1
call   1030 <MAX@plt>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm3
ucomisd %xmm3,%xmm0
jae    11c8 <f_lnsum+0x98>
movsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1040 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
call   1040 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret
movapd %xmm2,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @f_lnsum(i32 %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double 0.000000e+00, double* %10
%12 = load double, double* %8
%13 = load double, double* %9
%14 = call double @MAX(double %12, double %13)
store double %14, double* %11
%15 = load double, double* %7
%16 = fcmp ole double %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load double, double* %11
store double %18, double* %5
br label %43
19: ; preds = %4
%20 = load double, double* %8
%21 = load double, double* %11
%22 = fsub double %20, %21
%23 = load double, double* %7
%24 = fdiv double %22, %23
%25 = call i64 @exp(double %24)
%26 = sitofp i64 %25 to double
%27 = load double, double* %10
%28 = fadd double %27, %26
store double %28, double* %10
%29 = load double, double* %9
%30 = load double, double* %11
%31 = fsub double %29, %30
%32 = load double, double* %7
%33 = fdiv double %31, %32
%34 = call i64 @exp(double %33)
%35 = sitofp i64 %34 to double
%36 = load double, double* %10
%37 = fadd double %36, %35
store double %37, double* %10
%38 = load double, double* %11
%39 = load double, double* %7
%40 = load double, double* %10
%41 = call double @log(double %40)
%42 = call double @llvm.fmuladd.f64(double %39, double %41, double %38)
store double %42, double* %5
br label %43
43: ; preds = %19, %17
%44 = load double, double* %5
ret double %44
}

LLVM IR (-O2):
define double @f_lnsum(i32 %0, double %1, double %2, double %3) {
%5 = tail call double @MAX(double %2, double %3)
%6 = fcmp ugt double %1, 0.000000e+00
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = fsub double %2, %5
%9 = fdiv double %8, %1
%10 = tail call i64 @exp(double %9)
%11 = sitofp i64 %10 to double
%12 = fsub double %3, %5
%13 = fdiv double %12, %1
%14 = tail call i64 @exp(double %13)
%15 = sitofp i64 %14 to double
%16 = fadd double %11, %15
%17 = tail call double @log(double %16)
%18 = tail call double @llvm.fmuladd.f64(double %1, double %17, double %5)
br label %19
19: ; preds = %4, %7
%20 = phi double [ %18, %7 ], [ %5, %4 ]
ret double %20
}