#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);
int /*<<< orphan*/ assert(int);
double _tram_update_biased_conf_energies(double *bias_energy_sequence,
                                         int *state_sequence, int seq_length,
                                         double *log_R_K_i, int n_therm_states,
                                         int n_conf_states, double *scratch_T,
                                         double *new_biased_conf_energies,
                                         int return_log_L) {
  int i, K, x, o, Ki;
  int KM;
  double divisor, log_L;
  for (x = 0; x < seq_length; ++x) {
    i = state_sequence[x];
    if (i < 0)
      continue;
    o = 0;
    for (K = 0; K < n_therm_states; ++K) {
      assert(K < n_therm_states);
      assert(K >= 0);
      if (-(1.0 / 0.0) == log_R_K_i[K * n_conf_states + i])
        continue;
      scratch_T[o++] = log_R_K_i[K * n_conf_states + i] -
                       bias_energy_sequence[x * n_therm_states + K];
    }
    divisor = _logsumexp_sort_kahan_inplace(scratch_T, o);
    for (K = 0; K < n_therm_states; ++K) {
      new_biased_conf_energies[K * n_conf_states + i] = -_logsumexp_pair(
          -new_biased_conf_energies[K * n_conf_states + i],
          -(divisor + bias_energy_sequence[x * n_therm_states + K]));
    }
  }
  if (return_log_L) {
    log_L = 0;
    for (x = 0; x < seq_length; ++x) {
      o = 0;
      i = state_sequence[x];
      if (i < 0)
        continue;
      for (K = 0; K < n_therm_states; ++K) {
        KM = K * n_conf_states;
        Ki = KM + i;
        if (log_R_K_i[Ki] > 0)
          scratch_T[o++] =
              log_R_K_i[Ki] - bias_energy_sequence[x * n_therm_states + K];
      }
      log_L -= _logsumexp_sort_kahan_inplace(scratch_T, o);
    }
    return log_L;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<_tram_update_biased_conf_energies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    131e <_tram_update_biased_conf_energies+0x1ee>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    118a <_tram_update_biased_conf_energies+0x5a>
jmp    1310 <_tram_update_biased_conf_energies+0x1e0>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1248 <_tram_update_biased_conf_energies+0x118>
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x38(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xe1f(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jne    11f7 <_tram_update_biased_conf_energies+0xc7>
jp     11f7 <_tram_update_biased_conf_energies+0xc7>
jmp    123a <_tram_update_biased_conf_energies+0x10a>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
mov    -0x40(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x40(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1198 <_tram_update_biased_conf_energies+0x68>
mov    0x10(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    130b <_tram_update_biased_conf_energies+0x1db>
mov    0x18(%rbp),%rax
mov    -0x38(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x50(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1050 <_logsumexp_pair@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    0x18(%rbp),%rax
mov    -0x38(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1260 <_tram_update_biased_conf_energies+0x130>
jmp    1310 <_tram_update_biased_conf_energies+0x1e0>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1161 <_tram_update_biased_conf_energies+0x31>
cmpl   $0x0,0x20(%rbp)
je     142e <_tram_update_biased_conf_energies+0x2fe>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    141f <_tram_update_biased_conf_energies+0x2ef>
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1367 <_tram_update_biased_conf_energies+0x237>
jmp    1411 <_tram_update_biased_conf_energies+0x2e1>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13f4 <_tram_update_biased_conf_energies+0x2c4>
mov    -0x38(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    13e1 <_tram_update_biased_conf_energies+0x2b1>
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
mov    -0x40(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x40(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    13e6 <_tram_update_biased_conf_energies+0x2b6>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    136e <_tram_update_biased_conf_energies+0x23e>
mov    0x10(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1337 <_tram_update_biased_conf_energies+0x207>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1436 <_tram_update_biased_conf_energies+0x306>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tram_update_biased_conf_energies>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rcx,0x20(%rsp)
xorpd  %xmm0,%xmm0
test   %edx,%edx
jle    13a4 <_tram_update_biased_conf_energies+0x274>
mov    %rsi,%r13
movslq %r9d,%rax
mov    %r8d,0x4(%rsp)
movslq %r8d,%rcx
mov    %edx,0x1c(%rsp)
mov    %edx,%edx
mov    %rdx,0x28(%rsp)
mov    %ecx,%r12d
shl    $0x3,%rcx
mov    %rcx,0x30(%rsp)
shl    $0x3,%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rdi,0x38(%rsp)
mov    %rdi,%r14
mov    %rsi,0x40(%rsp)
jmp    11b8 <_tram_update_biased_conf_energies+0x88>
xchg   %ax,%ax
mov    0x90(%rsp),%rdi
xor    %esi,%esi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
mov    0x50(%rsp),%rax
add    $0x1,%rax
add    0x30(%rsp),%r14
cmp    0x28(%rsp),%rax
je     12d6 <_tram_update_biased_conf_energies+0x1a6>
mov    %rax,0x50(%rsp)
mov    0x0(%r13,%rax,4),%ecx
test   %ecx,%ecx
js     119f <_tram_update_biased_conf_energies+0x6f>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
jle    1190 <_tram_update_biased_conf_energies+0x60>
mov    0x20(%rsp),%rax
mov    %rcx,0x48(%rsp)
lea    (%rax,%rcx,8),%rbx
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    11fe <_tram_update_biased_conf_energies+0xce>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15
add    0x10(%rsp),%rbx
cmp    %r15,%r12
je     1240 <_tram_update_biased_conf_energies+0x110>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
movsd  (%rbx),%xmm0
movsd  0xde2(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    11f0 <_tram_update_biased_conf_energies+0xc0>
subsd  (%r14,%r15,8),%xmm0
movslq %r13d,%rax
add    $0x1,%r13d
mov    0x90(%rsp),%rcx
movsd  %xmm0,(%rcx,%rax,8)
jmp    11f0 <_tram_update_biased_conf_energies+0xc0>
mov    0x90(%rsp),%rdi
mov    %r13d,%esi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
test   %ebp,%ebp
mov    0x40(%rsp),%r13
mov    0x10(%rsp),%r15
movapd 0xdac(%rip),%xmm1
mov    0x48(%rsp),%rax
jle    119f <_tram_update_biased_conf_energies+0x6f>
movapd %xmm0,%xmm2
cltq
mov    0x98(%rsp),%rcx
lea    (%rcx,%rax,8),%rbx
xor    %ebp,%ebp
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax)
movsd  (%rbx),%xmm0
xorpd  %xmm1,%xmm0
movsd  (%r14,%rbp,8),%xmm1
addsd  %xmm2,%xmm1
xorpd  0xd66(%rip),%xmm1
call   1050 <_logsumexp_pair@plt>
movsd  0x8(%rsp),%xmm2
movapd 0xd53(%rip),%xmm1
xorpd  %xmm1,%xmm0
movlpd %xmm0,(%rbx)
add    $0x1,%rbp
add    %r15,%rbx
cmp    %rbp,%r12
jne    1290 <_tram_update_biased_conf_energies+0x160>
jmp    119f <_tram_update_biased_conf_energies+0x6f>
cmpl   $0x0,0xa0(%rsp)
je     13a0 <_tram_update_biased_conf_energies+0x270>
cmpl   $0x0,0x1c(%rsp)
mov    0x38(%rsp),%rbx
xorpd  %xmm0,%xmm0
mov    0x10(%rsp),%rbp
mov    0x4(%rsp),%r15d
jle    13a4 <_tram_update_biased_conf_energies+0x274>
xorpd  %xmm1,%xmm1
xor    %r14d,%r14d
xorpd  %xmm0,%xmm0
jmp    1341 <_tram_update_biased_conf_energies+0x211>
nop
xor    %esi,%esi
mov    0x90(%rsp),%rdi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
xorpd  %xmm1,%xmm1
add    $0x1,%r14
add    0x30(%rsp),%rbx
cmp    0x28(%rsp),%r14
je     13a4 <_tram_update_biased_conf_energies+0x274>
mov    0x0(%r13,%r14,4),%eax
test   %eax,%eax
js     1331 <_tram_update_biased_conf_energies+0x201>
test   %r15d,%r15d
movsd  %xmm0,0x8(%rsp)
jle    1310 <_tram_update_biased_conf_energies+0x1e0>
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
xor    %ecx,%ecx
xor    %esi,%esi
jmp    137c <_tram_update_biased_conf_energies+0x24c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rcx
add    %rbp,%rax
cmp    %rcx,%r12
je     1312 <_tram_update_biased_conf_energies+0x1e2>
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1370 <_tram_update_biased_conf_energies+0x240>
subsd  (%rbx,%rcx,8),%xmm0
movslq %esi,%rdx
add    $0x1,%esi
mov    0x90(%rsp),%rdi
movsd  %xmm0,(%rdi,%rdx,8)
jmp    1370 <_tram_update_biased_conf_energies+0x240>
xorpd  %xmm0,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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