#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 _logsumexp_pair(double, double);
double _logsumexp_sort_kahan_inplace(double *, int);
double log(double);
void _tram_get_log_Ref_K_i(double *log_lagrangian_mult,
                           double *biased_conf_energies, int *count_matrices,
                           int *state_counts, int n_therm_states,
                           int n_conf_states, double *scratch_M,
                           double *log_R_K_i) {
  int i, j, K, o;
  int Ki, Kj, KM, KMM;
  int Ci, CK, CKij, CKji, NC;
  double divisor, R_addon;
  for (K = 0; K < n_therm_states; ++K) {
    KM = K * n_conf_states;
    KMM = KM * n_conf_states;
    for (i = 0; i < n_conf_states; ++i) {
      Ki = KM + i;
      if (0 == state_counts[Ki]) {
        log_R_K_i[Ki] = -(1.0 / 0.0);
        continue;
      }
      Ci = 0;
      o = 0;
      for (j = 0; j < n_conf_states; ++j) {
        CKij = count_matrices[KMM + i * n_conf_states + j];
        CKji = count_matrices[KMM + j * n_conf_states + i];
        Ci += CKji;
        if (i == j) {
          scratch_M[o] = (0 == CKij) ? -(1.0 / 0.0) : log(0 + (double)CKij);
          scratch_M[o++] += biased_conf_energies[Ki];
          continue;
        }
        CK = CKij + CKji;
        if (0 == CK)
          continue;
        Kj = KM + j;
        divisor =
            _logsumexp_pair(log_lagrangian_mult[Kj] - biased_conf_energies[Ki],
                            log_lagrangian_mult[Ki] - biased_conf_energies[Kj]);
        scratch_M[o++] = log((double)CK) + log_lagrangian_mult[Kj] - divisor;
      }
      NC = state_counts[Ki] - Ci;
      R_addon =
          (0 < NC) ? log((double)NC) + biased_conf_energies[Ki] : -(1.0 / 0.0);
      log_R_K_i[Ki] =
          _logsumexp_pair(_logsumexp_sort_kahan_inplace(scratch_M, o), R_addon);
    }
  }
}


x86 assembly (clang, -O0):
<_tram_get_log_Ref_K_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    13ea <_tram_get_log_Ref_K_i+0x2ba>
mov    -0x34(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13d7 <_tram_get_log_Ref_K_i+0x2a7>
mov    -0x44(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
xor    %eax,%eax
cmp    (%rcx,%rdx,4),%eax
jne    11cb <_tram_get_log_Ref_K_i+0x9b>
mov    0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  0xe3f(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    13c9 <_tram_get_log_Ref_K_i+0x299>
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    134d <_tram_get_log_Ref_K_i+0x21d>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%ecx
mov    -0x2c(%rbp),%edx
imul   -0x28(%rbp),%edx
add    %edx,%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%ecx
mov    -0x30(%rbp),%edx
imul   -0x28(%rbp),%edx
add    %edx,%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
add    -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    12ac <_tram_get_log_Ref_K_i+0x17c>
xor    %eax,%eax
cmp    -0x54(%rbp),%eax
jne    1256 <_tram_get_log_Ref_K_i+0x126>
movsd  0xdb4(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    126c <_tram_get_log_Ref_K_i+0x13c>
cvtsi2sdl -0x54(%rbp),%xmm1
xorps  %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
mov    0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x38(%rbp)
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    133f <_tram_get_log_Ref_K_i+0x20f>
mov    -0x54(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%eax
jne    12c5 <_tram_get_log_Ref_K_i+0x195>
jmp    133f <_tram_get_log_Ref_K_i+0x20f>
mov    -0x44(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
call   1040 <_logsumexp_pair@plt>
movsd  %xmm0,-0x68(%rbp)
cvtsi2sdl -0x50(%rbp),%xmm0
call   1050 <log@plt>
mov    -0x8(%rbp),%rax
movslq -0x40(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
subsd  -0x68(%rbp),%xmm0
mov    0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x38(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e0 <_tram_get_log_Ref_K_i+0xb0>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
xor    %eax,%eax
cmp    -0x5c(%rbp),%eax
jge    138a <_tram_get_log_Ref_K_i+0x25a>
cvtsi2sdl -0x5c(%rbp),%xmm0
call   1050 <log@plt>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    139c <_tram_get_log_Ref_K_i+0x26c>
movsd  0xc6e(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    139c <_tram_get_log_Ref_K_i+0x26c>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    0x10(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
movsd  -0x70(%rbp),%xmm1
call   1040 <_logsumexp_pair@plt>
mov    0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1189 <_tram_get_log_Ref_K_i+0x59>
jmp    13dc <_tram_get_log_Ref_K_i+0x2ac>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1162 <_tram_get_log_Ref_K_i+0x32>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tram_get_log_Ref_K_i>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %r9d,0x4(%rsp)
mov    %rdx,0x60(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,0x48(%rsp)
test   %r8d,%r8d
jle    144f <_tram_get_log_Ref_K_i+0x31f>
mov    %rcx,%r15
movslq 0x4(%rsp),%rax
mov    %r8d,%ecx
mov    %rcx,0x88(%rsp)
mov    %eax,%ecx
mov    %rcx,0x68(%rsp)
mov    %eax,%ecx
imul   %eax,%ecx
mov    %ecx,0x3c(%rsp)
mov    %rax,%rcx
imul   %rax,%rcx
shl    $0x2,%rcx
mov    %rcx,0x80(%rsp)
lea    0x0(,%rax,4),%rcx
mov    %rcx,0x98(%rsp)
mov    %rax,0x70(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x78(%rsp)
xor    %eax,%eax
mov    %rax,0x28(%rsp)
mov    0x10(%rsp),%rax
mov    %rax,0x58(%rsp)
mov    0x48(%rsp),%rax
mov    %rax,0x50(%rsp)
mov    0x60(%rsp),%rax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    %r15,0x90(%rsp)
jmp    123e <_tram_get_log_Ref_K_i+0x10e>
nopl   0x0(%rax)
mov    0x18(%rsp),%rcx
add    $0x1,%rcx
mov    0x28(%rsp),%rax
add    0x3c(%rsp),%eax
mov    %rax,0x28(%rsp)
mov    0x20(%rsp),%rax
add    0x80(%rsp),%rax
mov    %rax,0x20(%rsp)
mov    0x78(%rsp),%rax
add    %rax,0x50(%rsp)
add    %rax,0x58(%rsp)
mov    %rcx,%rax
mov    %rcx,0x18(%rsp)
cmp    0x88(%rsp),%rcx
je     144f <_tram_get_log_Ref_K_i+0x31f>
cmpl   $0x0,0x4(%rsp)
jle    11f0 <_tram_get_log_Ref_K_i+0xc0>
mov    0x18(%rsp),%rax
imul   0x70(%rsp),%rax
mov    %rax,0xa0(%rsp)
mov    0x20(%rsp),%r14
mov    0x28(%rsp),%rax
mov    %eax,%r13d
xor    %r8d,%r8d
jmp    12c3 <_tram_get_log_Ref_K_i+0x193>
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    0xf0(%rsp),%rdi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
movsd  0x8(%rsp),%xmm1
call   1040 <_logsumexp_pair@plt>
mov    0x40(%rsp),%r13d
mov    0x30(%rsp),%r8
mov    %rbp,%rdi
mov    0xf8(%rsp),%rax
movsd  %xmm0,(%rax,%rdi,8)
add    $0x1,%r8
add    $0x1,%r13d
add    0x98(%rsp),%r14
cmp    0x68(%rsp),%r8
je     11f0 <_tram_get_log_Ref_K_i+0xc0>
mov    0xa0(%rsp),%rax
lea    (%r8,%rax,1),%rdi
cmpl   $0x0,(%r15,%rdi,4)
movsd  0xd24(%rip),%xmm0
je     129b <_tram_get_log_Ref_K_i+0x16b>
xor    %ebx,%ebx
mov    %r13d,0x40(%rsp)
xor    %esi,%esi
xor    %r12d,%r12d
mov    %r8,0x30(%rsp)
mov    %rdi,0x8(%rsp)
mov    %r14,0xa8(%rsp)
jmp    1339 <_tram_get_log_Ref_K_i+0x209>
xchg   %ax,%ax
movslq %esi,%rax
mov    0xf0(%rsp),%rdx
movsd  %xmm0,(%rdx,%rax,8)
add    $0x1,%esi
mov    0x10(%rsp),%rcx
addsd  (%rcx,%rdi,8),%xmm0
movsd  %xmm0,(%rdx,%rax,8)
add    %r15d,%r12d
add    $0x1,%rbx
add    0x4(%rsp),%r13d
cmp    %rbx,0x68(%rsp)
je     1410 <_tram_get_log_Ref_K_i+0x2e0>
mov    (%r14,%rbx,4),%ebp
movslq %r13d,%rax
mov    0x60(%rsp),%rcx
mov    (%rcx,%rax,4),%r15d
cmp    %rbx,%r8
jne    1380 <_tram_get_log_Ref_K_i+0x250>
movsd  0xcaa(%rip),%xmm0
test   %ebp,%ebp
je     1300 <_tram_get_log_Ref_K_i+0x1d0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mov    %esi,%ebp
call   1050 <log@plt>
mov    %ebp,%esi
mov    0x8(%rsp),%rdi
mov    0x30(%rsp),%r8
jmp    1300 <_tram_get_log_Ref_K_i+0x1d0>
cs nopw 0x0(%rax,%rax,1)
add    %r15d,%ebp
je     1322 <_tram_get_log_Ref_K_i+0x1f2>
mov    0x50(%rsp),%r14
movsd  (%r14,%rbx,8),%xmm0
mov    0x10(%rsp),%rax
subsd  (%rax,%rdi,8),%xmm0
mov    0x48(%rsp),%rax
movsd  (%rax,%rdi,8),%xmm1
mov    0x58(%rsp),%rax
subsd  (%rax,%rbx,8),%xmm1
mov    %esi,0x44(%rsp)
call   1040 <_logsumexp_pair@plt>
movsd  %xmm0,0xb0(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
call   1050 <log@plt>
mov    0x44(%rsp),%esi
mov    0x8(%rsp),%rdi
mov    0x30(%rsp),%r8
addsd  (%r14,%rbx,8),%xmm0
mov    0xa8(%rsp),%r14
subsd  0xb0(%rsp),%xmm0
movslq %esi,%rax
add    $0x1,%esi
mov    0xf0(%rsp),%rcx
movsd  %xmm0,(%rcx,%rax,8)
jmp    1322 <_tram_get_log_Ref_K_i+0x1f2>
nopl   0x0(%rax)
mov    0x90(%rsp),%r15
mov    (%r15,%rdi,4),%eax
movsd  0xbdc(%rip),%xmm0
sub    %r12d,%eax
mov    %rdi,%rbp
jle    1270 <_tram_get_log_Ref_K_i+0x140>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %esi,%ebx
call   1050 <log@plt>
mov    %ebx,%esi
mov    0x10(%rsp),%rax
addsd  (%rax,%rbp,8),%xmm0
jmp    1270 <_tram_get_log_Ref_K_i+0x140>
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_tram_get_log_Ref_K_i(double* %0, double* %1, i32* %2, i32* %3, i32 %4, i32 %5, double* %6, double* %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca double
%31 = alloca double
store double* %0, double** %9
store double* %1, double** %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store double* %6, double** %15
store double* %7, double** %16
store i32 0, i32* %19
br label %32
32: ; preds = %212, %8
%33 = load i32, i32* %19
%34 = load i32, i32* %13
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %215
36: ; preds = %32
%37 = load i32, i32* %19
%38 = load i32, i32* %14
%39 = mul nsw i32 %37, %38
store i32 %39, i32* %23
%40 = load i32, i32* %23
%41 = load i32, i32* %14
%42 = mul nsw i32 %40, %41
store i32 %42, i32* %24
store i32 0, i32* %17
br label %43
43: ; preds = %208, %36
%44 = load i32, i32* %17
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %211
47: ; preds = %43
%48 = load i32, i32* %23
%49 = load i32, i32* %17
%50 = add nsw i32 %48, %49
store i32 %50, i32* %21
%51 = load i32*, i32** %12
%52 = load i32, i32* %21
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = icmp eq i32 0, %55
br i1 %56, label %57, label %62
57: ; preds = %47
%58 = load double*, double** %16
%59 = load i32, i32* %21
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
store double 0xFFF0000000000000, double* %61
br label %208
62: ; preds = %47
store i32 0, i32* %25
store i32 0, i32* %20
store i32 0, i32* %18
br label %63
63: ; preds = %173, %62
%64 = load i32, i32* %18
%65 = load i32, i32* %14
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %176
67: ; preds = %63
%68 = load i32*, i32** %11
%69 = load i32, i32* %24
%70 = load i32, i32* %17
%71 = load i32, i32* %14
%72 = mul nsw i32 %70, %71
%73 = add nsw i32 %69, %72
%74 = load i32, i32* %18
%75 = add nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %68, i64 %76
%78 = load i32, i32* %77
store i32 %78, i32* %27
%79 = load i32*, i32** %11
%80 = load i32, i32* %24
%81 = load i32, i32* %18
%82 = load i32, i32* %14
%83 = mul nsw i32 %81, %82
%84 = add nsw i32 %80, %83
%85 = load i32, i32* %17
%86 = add nsw i32 %84, %85
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %79, i64 %87
%89 = load i32, i32* %88
store i32 %89, i32* %28
%90 = load i32, i32* %28
%91 = load i32, i32* %25
%92 = add nsw i32 %91, %90
store i32 %92, i32* %25
%93 = load i32, i32* %17
%94 = load i32, i32* %18
%95 = icmp eq i32 %93, %94
br i1 %95, label %96, label %123
96: ; preds = %67
%97 = load i32, i32* %27
%98 = icmp eq i32 0, %97
br i1 %98, label %99, label %100
99: ; preds = %96
br label %105
100: ; preds = %96
%101 = load i32, i32* %27
%102 = sitofp i32 %101 to double
%103 = fadd double 0.000000e+00, %102
%104 = call double @log(double %103)
br label %105
105: ; preds = %100, %99
%106 = phi double [ 0xFFF0000000000000, %99 ], [ %104, %100 ]
%107 = load double*, double** %15
%108 = load i32, i32* %20
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
store double %106, double* %110
%111 = load double*, double** %10
%112 = load i32, i32* %21
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds double, double* %111, i64 %113
%115 = load double, double* %114
%116 = load double*, double** %15
%117 = load i32, i32* %20
%118 = add nsw i32 %117, 1
store i32 %118, i32* %20
%119 = sext i32 %117 to i64
%120 = getelementptr inbounds double, double* %116, i64 %119
%121 = load double, double* %120
%122 = fadd double %121, %115
store double %122, double* %120
br label %173
123: ; preds = %67
%124 = load i32, i32* %27
%125 = load i32, i32* %28
%126 = add nsw i32 %124, %125
store i32 %126, i32* %26
%127 = load i32, i32* %26
%128 = icmp eq i32 0, %127
br i1 %128, label %129, label %130
129: ; preds = %123
br label %173
130: ; preds = %123
%131 = load i32, i32* %23
%132 = load i32, i32* %18
%133 = add nsw i32 %131, %132
store i32 %133, i32* %22
%134 = load double*, double** %9
%135 = load i32, i32* %22
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds double, double* %134, i64 %136
%138 = load double, double* %137
%139 = load double*, double** %10
%140 = load i32, i32* %21
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double, double* %139, i64 %141
%143 = load double, double* %142
%144 = fsub double %138, %143
%145 = load double*, double** %9
%146 = load i32, i32* %21
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds double, double* %145, i64 %147
%149 = load double, double* %148
%150 = load double*, double** %10
%151 = load i32, i32* %22
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds double, double* %150, i64 %152
%154 = load double, double* %153
%155 = fsub double %149, %154
%156 = call double @_logsumexp_pair(double %144, double %155)
store double %156, double* %30
%157 = load i32, i32* %26
%158 = sitofp i32 %157 to double
%159 = call double @log(double %158)
%160 = load double*, double** %9
%161 = load i32, i32* %22
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds double, double* %160, i64 %162
%164 = load double, double* %163
%165 = fadd double %159, %164
%166 = load double, double* %30
%167 = fsub double %165, %166
%168 = load double*, double** %15
%169 = load i32, i32* %20
%170 = add nsw i32 %169, 1
store i32 %170, i32* %20
%171 = sext i32 %169 to i64
%172 = getelementptr inbounds double, double* %168, i64 %171
store double %167, double* %172
br label %173
173: ; preds = %130, %129, %105
%174 = load i32, i32* %18
%175 = add nsw i32 %174, 1
store i32 %175, i32* %18
br label %63
176: ; preds = %63
%177 = load i32*, i32** %12
%178 = load i32, i32* %21
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i32, i32* %177, i64 %179
%181 = load i32, i32* %180
%182 = load i32, i32* %25
%183 = sub nsw i32 %181, %182
store i32 %183, i32* %29
%184 = load i32, i32* %29
%185 = icmp slt i32 0, %184
br i1 %185, label %186, label %196
186: ; preds = %176
%187 = load i32, i32* %29
%188 = sitofp i32 %187 to double
%189 = call double @log(double %188)
%190 = load double*, double** %10
%191 = load i32, i32* %21
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds double, double* %190, i64 %192
%194 = load double, double* %193
%195 = fadd double %189, %194
br label %197
196: ; preds = %176
br label %197
197: ; preds = %196, %186
%198 = phi double [ %195, %186 ], [ 0xFFF0000000000000, %196 ]
store double %198, double* %31
%199 = load double*, double** %15
%200 = load i32, i32* %20
%201 = call double @_logsumexp_sort_kahan_inplace(double* %199, i32 %200)
%202 = load double, double* %31
%203 = call double @_logsumexp_pair(double %201, double %202)
%204 = load double*, double** %16
%205 = load i32, i32* %21
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds double, double* %204, i64 %206
store double %203, double* %207
br label %208
208: ; preds = %197, %57
%209 = load i32, i32* %17
%210 = add nsw i32 %209, 1
store i32 %210, i32* %17
br label %43
211: ; preds = %43
br label %212
212: ; preds = %211
%213 = load i32, i32* %19
%214 = add nsw i32 %213, 1
store i32 %214, i32* %19
br label %32
215: ; preds = %32
ret void
}

LLVM IR (-O2):
define void @_tram_get_log_Ref_K_i(double* nocapture %0, double* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32 %4, i32 %5, double* %6, double* nocapture writeonly %7) {
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %109
10: ; preds = %8
%11 = icmp sgt i32 %5, 0
%12 = sext i32 %5 to i64
%13 = zext i32 %4 to i64
%14 = zext i32 %5 to i64
br label %15
15: ; preds = %10, %106
%16 = phi i64 [ 0, %10 ], [ %107, %106 ]
%17 = mul nsw i64 %16, %12
%18 = mul nsw i64 %17, %12
br i1 %11, label %19, label %106
19: ; preds = %15
%20 = trunc i64 %18 to i32
br label %21
21: ; preds = %19, %101
%22 = phi i64 [ 0, %19 ], [ %104, %101 ]
%23 = add nsw i64 %22, %17
%24 = getelementptr inbounds i32, i32* %3, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %101, label %27
27: ; preds = %21
%28 = mul nsw i64 %22, %12
%29 = add nsw i64 %28, %18
%30 = trunc i64 %22 to i32
%31 = add i32 %30, %20
%32 = getelementptr inbounds double, double* %1, i64 %23
%33 = getelementptr inbounds double, double* %0, i64 %23
br label %34
34: ; preds = %27, %83
%35 = phi i64 [ 0, %27 ], [ %85, %83 ]
%36 = phi i32 [ 0, %27 ], [ %84, %83 ]
%37 = phi i32 [ 0, %27 ], [ %47, %83 ]
%38 = add nsw i64 %29, %35
%39 = getelementptr inbounds i32, i32* %2, i64 %38
%40 = load i32, i32* %39
%41 = trunc i64 %35 to i32
%42 = mul i32 %41, %5
%43 = add i32 %31, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %2, i64 %44
%46 = load i32, i32* %45
%47 = add nsw i32 %46, %37
%48 = icmp eq i64 %22, %35
br i1 %48, label %49, label %61
49: ; preds = %34
%50 = icmp eq i32 %40, 0
br i1 %50, label %54, label %51
51: ; preds = %49
%52 = sitofp i32 %40 to double
%53 = tail call double @log(double %52)
br label %54
54: ; preds = %49, %51
%55 = phi double [ %53, %51 ], [ 0xFFF0000000000000, %49 ]
%56 = sext i32 %36 to i64
%57 = getelementptr inbounds double, double* %6, i64 %56
store double %55, double* %57
%58 = load double, double* %32
%59 = add nsw i32 %36, 1
%60 = fadd double %55, %58
store double %60, double* %57
br label %83
61: ; preds = %34
%62 = add nsw i32 %46, %40
%63 = icmp eq i32 %62, 0
br i1 %63, label %83, label %64
64: ; preds = %61
%65 = add nsw i64 %35, %17
%66 = getelementptr inbounds double, double* %0, i64 %65
%67 = load double, double* %66
%68 = load double, double* %32
%69 = fsub double %67, %68
%70 = load double, double* %33
%71 = getelementptr inbounds double, double* %1, i64 %65
%72 = load double, double* %71
%73 = fsub double %70, %72
%74 = tail call double @_logsumexp_pair(double %69, double %73)
%75 = sitofp i32 %62 to double
%76 = tail call double @log(double %75)
%77 = load double, double* %66
%78 = fadd double %76, %77
%79 = fsub double %78, %74
%80 = add nsw i32 %36, 1
%81 = sext i32 %36 to i64
%82 = getelementptr inbounds double, double* %6, i64 %81
store double %79, double* %82
br label %83
83: ; preds = %61, %64, %54
%84 = phi i32 [ %59, %54 ], [ %36, %61 ], [ %80, %64 ]
%85 = add nuw nsw i64 %35, 1
%86 = icmp eq i64 %85, %14
br i1 %86, label %87, label %34
87: ; preds = %83
%88 = load i32, i32* %24
%89 = sub nsw i32 %88, %47
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %87
%92 = sitofp i32 %89 to double
%93 = tail call double @log(double %92)
%94 = getelementptr inbounds double, double* %1, i64 %23
%95 = load double, double* %94
%96 = fadd double %93, %95
br label %97
97: ; preds = %87, %91
%98 = phi double [ %96, %91 ], [ 0xFFF0000000000000, %87 ]
%99 = tail call double @_logsumexp_sort_kahan_inplace(double* %6, i32 %84)
%100 = tail call double @_logsumexp_pair(double %99, double %98)
br label %101
101: ; preds = %21, %97
%102 = phi double [ %100, %97 ], [ 0xFFF0000000000000, %21 ]
%103 = getelementptr inbounds double, double* %7, i64 %23
store double %102, double* %103
%104 = add nuw nsw i64 %22, 1
%105 = icmp eq i64 %104, %14
br i1 %105, label %106, label %21
106: ; preds = %101, %15
%107 = add nuw nsw i64 %16, 1
%108 = icmp eq i64 %107, %13
br i1 %108, label %109, label %15
109: ; preds = %106, %8
ret void
}