#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 exp(double);
double log(double);
extern void _dtram_estimate_transition_matrix(
    double *log_lagrangian_mult, double *bias_energies, double *conf_energies,
    int *count_matrix, int n_conf_states, double *scratch_M,
    double *transition_matrix) {
  int i, j, o;
  int ij, ji;
  int C;
  double divisor, sum;
  for (i = 0; i < n_conf_states; ++i) {
    o = 0;
    for (j = 0; j < n_conf_states; ++j) {
      ij = i * n_conf_states + j;
      transition_matrix[ij] = 0.0;
      if (i == j) {
        scratch_M[o] = (0 == count_matrix[ij])
                           ? -23.025850929940457
                           : log(1.0E-10 + (double)count_matrix[ij]);
        scratch_M[o] -= log_lagrangian_mult[i];
        transition_matrix[ij] = exp(scratch_M[o++]);
        continue;
      }
      ji = j * n_conf_states + i;
      C = count_matrix[ij] + count_matrix[ji];
      if (0 == C)
        continue;
      divisor = _logsumexp_pair(
          log_lagrangian_mult[j] - conf_energies[i] - bias_energies[i],
          log_lagrangian_mult[i] - conf_energies[j] - bias_energies[j]);
      scratch_M[o] =
          log((double)C) - conf_energies[j] - bias_energies[j] - divisor;
      transition_matrix[ij] = exp(scratch_M[o++]);
    }
    sum = exp(_logsumexp_sort_kahan_inplace(scratch_M, o));
    if (0.0 == sum) {
      for (j = 0; j < n_conf_states; ++j)
        transition_matrix[i * n_conf_states + j] = 0.0;
      transition_matrix[i * n_conf_states + i] = 1.0;
    } else if (1.0 != sum) {
      for (j = 0; j < n_conf_states; ++j)
        transition_matrix[i * n_conf_states + j] /= sum;
    }
  }
}


x86 assembly (clang, -O0):
<_dtram_estimate_transition_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
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    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1467 <_dtram_estimate_transition_matrix+0x327>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1360 <_dtram_estimate_transition_matrix+0x220>
mov    -0x34(%rbp),%eax
imul   -0x24(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    1265 <_dtram_estimate_transition_matrix+0x125>
mov    -0x20(%rbp),%rcx
movslq -0x40(%rbp),%rdx
xor    %eax,%eax
cmp    (%rcx,%rdx,4),%eax
jne    11df <_dtram_estimate_transition_matrix+0x9f>
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1202 <_dtram_estimate_transition_matrix+0xc2>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm1
movsd  0xe14(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x3c(%rbp)
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <exp@plt>
mov    0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1352 <_dtram_estimate_transition_matrix+0x212>
mov    -0x38(%rbp),%eax
imul   -0x24(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x20(%rbp),%rcx
movslq -0x44(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x48(%rbp)
xor    %eax,%eax
cmp    -0x48(%rbp),%eax
jne    129b <_dtram_estimate_transition_matrix+0x15b>
jmp    1352 <_dtram_estimate_transition_matrix+0x212>
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
call   1040 <_logsumexp_pair@plt>
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x48(%rbp),%xmm0
call   1060 <log@plt>
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
subsd  -0x50(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x3c(%rbp)
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <exp@plt>
mov    0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1185 <_dtram_estimate_transition_matrix+0x45>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1030 <_logsumexp_sort_kahan_inplace@plt>
call   1050 <exp@plt>
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x58(%rbp),%xmm0
jne    13e7 <_dtram_estimate_transition_matrix+0x2a7>
jp     13e7 <_dtram_estimate_transition_matrix+0x2a7>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    13c4 <_dtram_estimate_transition_matrix+0x284>
mov    0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1391 <_dtram_estimate_transition_matrix+0x251>
mov    0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xc23(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1454 <_dtram_estimate_transition_matrix+0x314>
movsd  0xc11(%rip),%xmm0
ucomisd -0x58(%rbp),%xmm0
jne    1405 <_dtram_estimate_transition_matrix+0x2c5>
jp     1405 <_dtram_estimate_transition_matrix+0x2c5>
jmp    144f <_dtram_estimate_transition_matrix+0x30f>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    144a <_dtram_estimate_transition_matrix+0x30a>
movsd  -0x58(%rbp),%xmm1
mov    0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    140c <_dtram_estimate_transition_matrix+0x2cc>
jmp    144f <_dtram_estimate_transition_matrix+0x30f>
jmp    1454 <_dtram_estimate_transition_matrix+0x314>
jmp    1459 <_dtram_estimate_transition_matrix+0x319>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116b <_dtram_estimate_transition_matrix+0x2b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dtram_estimate_transition_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9,0x10(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdx,0x88(%rsp)
mov    %rsi,0x80(%rsp)
mov    %rdi,0x48(%rsp)
mov    %r8d,0x8(%rsp)
test   %r8d,%r8d
jle    14b9 <_dtram_estimate_transition_matrix+0x369>
mov    0xd0(%rsp),%r14
mov    0x8(%rsp),%edx
lea    0x0(,%rdx,8),%rcx
mov    %rcx,0x38(%rsp)
mov    %edx,%ecx
and    $0xfffffffe,%ecx
mov    %rcx,0x68(%rsp)
add    $0xfffffffffffffffe,%rcx
mov    %rcx,0x60(%rsp)
mov    %rcx,%rsi
shr    %rsi
add    $0x1,%rsi
mov    %rsi,%rcx
mov    %rsi,0x58(%rsp)
and    $0xfffffffffffffffe,%rsi
mov    %rsi,0x50(%rsp)
lea    0x0(,%rdx,4),%r15
xor    %ecx,%ecx
mov    %rcx,0x20(%rsp)
mov    0x30(%rsp),%rcx
mov    %rcx,0x18(%rsp)
xor    %r13d,%r13d
mov    %rdx,0x28(%rsp)
mov    %r15,0x78(%rsp)
jmp    1278 <_dtram_estimate_transition_matrix+0x128>
nopl   (%rax)
mov    0x10(%rsp),%rdi
mov    %ebp,%esi
call   1040 <_logsumexp_sort_kahan_inplace@plt>
call   1060 <exp@plt>
ucomisd 0xdff(%rip),%xmm0
jne    13e0 <_dtram_estimate_transition_matrix+0x290>
jp     13e0 <_dtram_estimate_transition_matrix+0x290>
mov    0x70(%rsp),%rdi
xor    %esi,%esi
mov    0x38(%rsp),%rdx
call   1030 <memset@plt>
mov    %r13,%rax
mov    0x28(%rsp),%rdx
imul   %rdx,%rax
add    %r13,%rax
mov    0xd0(%rsp),%rcx
movabs $0x3ff0000000000000,%rsi
mov    %rsi,(%rcx,%rax,8)
add    $0x1,%r13
addq   $0x4,0x20(%rsp)
add    0x38(%rsp),%r14
add    %r15,0x18(%rsp)
cmp    %rdx,%r13
je     14b9 <_dtram_estimate_transition_matrix+0x369>
mov    %r13d,%eax
imul   0x8(%rsp),%eax
cltq
mov    0xd0(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
mov    %rax,0x70(%rsp)
mov    0x30(%rsp),%rbx
xor    %r12d,%r12d
xor    %ebp,%ebp
mov    %r14,0x40(%rsp)
jmp    1371 <_dtram_estimate_transition_matrix+0x221>
nopw   0x0(%rax,%rax,1)
mov    %ebp,0xc(%rsp)
mov    0x20(%rsp),%rax
mov    (%rbx,%rax,1),%r14d
mov    0x18(%rsp),%rax
add    (%rax,%r12,1),%r14d
je     13cc <_dtram_estimate_transition_matrix+0x27c>
mov    0x48(%rsp),%rax
movsd  (%rax,%r12,2),%xmm0
mov    0x88(%rsp),%r15
subsd  (%r15,%r13,8),%xmm0
mov    0x80(%rsp),%rbp
subsd  0x0(%rbp,%r13,8),%xmm0
movsd  (%rax,%r13,8),%xmm1
subsd  (%r15,%r12,2),%xmm1
subsd  0x0(%rbp,%r12,2),%xmm1
call   1050 <_logsumexp_pair@plt>
movsd  %xmm0,0x90(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
call   1070 <log@plt>
subsd  (%r15,%r12,2),%xmm0
mov    0x78(%rsp),%r15
subsd  0x0(%rbp,%r12,2),%xmm0
subsd  0x90(%rsp),%xmm0
mov    0xc(%rsp),%ebp
movslq %ebp,%rax
mov    0x10(%rsp),%rcx
movsd  %xmm0,(%rcx,%rax,8)
mov    0x40(%rsp),%r14
add    $0x1,%ebp
call   1060 <exp@plt>
movsd  %xmm0,(%r14,%r12,2)
add    $0x4,%r12
add    %r15,%rbx
cmp    %r12,%r15
je     1200 <_dtram_estimate_transition_matrix+0xb0>
movq   $0x0,(%r14,%r12,2)
cmp    %r12,0x20(%rsp)
jne    12b0 <_dtram_estimate_transition_matrix+0x160>
mov    0x18(%rsp),%rax
mov    (%rax,%r12,1),%eax
movsd  0xc6b(%rip),%xmm0
test   %eax,%eax
je     13ad <_dtram_estimate_transition_matrix+0x25d>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xc60(%rip),%xmm0
call   1070 <log@plt>
movslq %ebp,%rax
mov    0x10(%rsp),%rcx
movsd  %xmm0,(%rcx,%rax,8)
mov    0x48(%rsp),%rdx
subsd  (%rdx,%r13,8),%xmm0
movsd  %xmm0,(%rcx,%rax,8)
jmp    1353 <_dtram_estimate_transition_matrix+0x203>
mov    0x40(%rsp),%r14
mov    0xc(%rsp),%ebp
jmp    1361 <_dtram_estimate_transition_matrix+0x211>
nopw   0x0(%rax,%rax,1)
ucomisd 0xc28(%rip),%xmm0
mov    0x28(%rsp),%rdx
jne    13f5 <_dtram_estimate_transition_matrix+0x2a5>
jnp    125b <_dtram_estimate_transition_matrix+0x10b>
cmpl   $0x2,0x8(%rsp)
jae    1403 <_dtram_estimate_transition_matrix+0x2b3>
xor    %eax,%eax
jmp    1490 <_dtram_estimate_transition_matrix+0x340>
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
cmpq   $0x0,0x60(%rsp)
je     14ae <_dtram_estimate_transition_matrix+0x35e>
mov    0x50(%rsp),%rcx
xor    %eax,%eax
xchg   %ax,%ax
movupd (%r14,%rax,8),%xmm2
movupd 0x10(%r14,%rax,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%r14,%rax,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%r14,%rax,8)
add    $0x4,%rax
add    $0xfffffffffffffffe,%rcx
jne    1420 <_dtram_estimate_transition_matrix+0x2d0>
testb  $0x1,0x58(%rsp)
je     1473 <_dtram_estimate_transition_matrix+0x323>
mov    %r13,%rcx
imul   %rdx,%rcx
add    %rcx,%rax
mov    0xd0(%rsp),%rcx
movupd (%rcx,%rax,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rcx,%rax,8)
mov    0x68(%rsp),%rcx
mov    %rcx,%rax
cmp    %rdx,%rcx
je     125b <_dtram_estimate_transition_matrix+0x10b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%rax,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rax,8)
add    $0x1,%rax
cmp    %rax,%rdx
jne    1490 <_dtram_estimate_transition_matrix+0x340>
jmp    125b <_dtram_estimate_transition_matrix+0x10b>
xor    %eax,%eax
testb  $0x1,0x58(%rsp)
jne    1453 <_dtram_estimate_transition_matrix+0x303>
jmp    1473 <_dtram_estimate_transition_matrix+0x323>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @_dtram_estimate_transition_matrix(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32* nocapture %3, i32 %4, double* %5, double* nocapture %6) {
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %153
9: ; preds = %7
%10 = zext i32 %4 to i64
%11 = zext i32 %4 to i64
%12 = shl nuw nsw i64 %11, 3
%13 = and i64 %11, 4294967294
%14 = add nsw i64 %13, -2
%15 = lshr exact i64 %14, 1
%16 = add nuw i64 %15, 1
%17 = icmp ult i32 %4, 2
%18 = and i64 %11, 4294967294
%19 = and i64 %16, 1
%20 = icmp eq i64 %14, 0
%21 = and i64 %16, -2
%22 = icmp eq i64 %19, 0
%23 = icmp eq i64 %18, %11
br label %24
24: ; preds = %150, %9
%25 = phi i64 [ 0, %9 ], [ %151, %150 ]
%26 = trunc i64 %25 to i32
%27 = mul i32 %26, %4
%28 = sext i32 %27 to i64
%29 = getelementptr double, double* %6, i64 %28
%30 = bitcast double* %29 to i8*
%31 = mul nsw i64 %25, %10
%32 = getelementptr inbounds double, double* %2, i64 %25
%33 = getelementptr inbounds double, double* %1, i64 %25
%34 = getelementptr inbounds double, double* %0, i64 %25
br label %35
35: ; preds = %24, %92
%36 = phi i64 [ 0, %24 ], [ %94, %92 ]
%37 = phi i32 [ 0, %24 ], [ %93, %92 ]
%38 = add nuw nsw i64 %36, %31
%39 = getelementptr inbounds double, double* %6, i64 %38
store double 0.000000e+00, double* %39
%40 = icmp eq i64 %25, %36
br i1 %40, label %41, label %55
41: ; preds = %35
%42 = getelementptr inbounds i32, i32* %3, i64 %38
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = sitofp i32 %43 to double
%47 = fadd double %46, 1.000000e-10
%48 = tail call double @log(double %47)
br label %49
49: ; preds = %41, %45
%50 = phi double [ %48, %45 ], [ 0xC037069E2AA2AA5B, %41 ]
%51 = sext i32 %37 to i64
%52 = getelementptr inbounds double, double* %5, i64 %51
store double %50, double* %52
%53 = load double, double* %34
%54 = fsub double %50, %53
store double %54, double* %52
br label %88
55: ; preds = %35
%56 = mul nsw i64 %36, %10
%57 = add nuw nsw i64 %56, %25
%58 = getelementptr inbounds i32, i32* %3, i64 %38
%59 = load i32, i32* %58
%60 = getelementptr inbounds i32, i32* %3, i64 %57
%61 = load i32, i32* %60
%62 = add nsw i32 %61, %59
%63 = icmp eq i32 %62, 0
br i1 %63, label %92, label %64
64: ; preds = %55
%65 = getelementptr inbounds double, double* %0, i64 %36
%66 = load double, double* %65
%67 = load double, double* %32
%68 = fsub double %66, %67
%69 = load double, double* %33
%70 = fsub double %68, %69
%71 = load double, double* %34
%72 = getelementptr inbounds double, double* %2, i64 %36
%73 = load double, double* %72
%74 = fsub double %71, %73
%75 = getelementptr inbounds double, double* %1, i64 %36
%76 = load double, double* %75
%77 = fsub double %74, %76
%78 = tail call double @_logsumexp_pair(double %70, double %77)
%79 = sitofp i32 %62 to double
%80 = tail call double @log(double %79)
%81 = load double, double* %72
%82 = fsub double %80, %81
%83 = load double, double* %75
%84 = fsub double %82, %83
%85 = fsub double %84, %78
%86 = sext i32 %37 to i64
%87 = getelementptr inbounds double, double* %5, i64 %86
store double %85, double* %87
br label %88
88: ; preds = %49, %64
%89 = phi double [ %85, %64 ], [ %54, %49 ]
%90 = add nsw i32 %37, 1
%91 = tail call double @exp(double %89)
store double %91, double* %39
br label %92
92: ; preds = %88, %55
%93 = phi i32 [ %37, %55 ], [ %90, %88 ]
%94 = add nuw nsw i64 %36, 1
%95 = icmp eq i64 %94, %11
br i1 %95, label %96, label %35
96: ; preds = %92
%97 = tail call double @_logsumexp_sort_kahan_inplace(double* %5, i32 %93)
%98 = tail call double @exp(double %97)
%99 = fcmp oeq double %98, 0.000000e+00
br i1 %99, label %100, label %104
100: ; preds = %96
%101 = mul nsw i64 %25, %10
%102 = add nuw nsw i64 %101, %25
%103 = getelementptr inbounds double, double* %6, i64 %102
store double 1.000000e+00, double* %103
br label %150
104: ; preds = %96
%105 = fcmp oeq double %98, 1.000000e+00
br i1 %105, label %150, label %106
106: ; preds = %104
%107 = mul nsw i64 %25, %10
br i1 %17, label %140, label %108
108: ; preds = %106
%109 = insertelement <2 x double> poison, double %98, i64 0
%110 = shufflevector <2 x double> %109, <2 x double> poison, <2 x i32> zeroinitializer
br i1 %20, label %130, label %111
111: ; preds = %108, %111
%112 = phi i64 [ %127, %111 ], [ 0, %108 ]
%113 = phi i64 [ %128, %111 ], [ 0, %108 ]
%114 = add nuw nsw i64 %112, %107
%115 = getelementptr inbounds double, double* %6, i64 %114
%116 = bitcast double* %115 to <2 x double>*
%117 = load <2 x double>, <2 x double>* %116
%118 = fdiv <2 x double> %117, %110
%119 = bitcast double* %115 to <2 x double>*
store <2 x double> %118, <2 x double>* %119
%120 = or i64 %112, 2
%121 = add nuw nsw i64 %120, %107
%122 = getelementptr inbounds double, double* %6, i64 %121
%123 = bitcast double* %122 to <2 x double>*
%124 = load <2 x double>, <2 x double>* %123
%125 = fdiv <2 x double> %124, %110
%126 = bitcast double* %122 to <2 x double>*
store <2 x double> %125, <2 x double>* %126
%127 = add nuw i64 %112, 4
%128 = add nuw i64 %113, 2
%129 = icmp eq i64 %128, %21
br i1 %129, label %130, label %111
130: ; preds = %111, %108
%131 = phi i64 [ 0, %108 ], [ %127, %111 ]
br i1 %22, label %139, label %132
132: ; preds = %130
%133 = add nuw nsw i64 %131, %107
%134 = getelementptr inbounds double, double* %6, i64 %133
%135 = bitcast double* %134 to <2 x double>*
%136 = load <2 x double>, <2 x double>* %135
%137 = fdiv <2 x double> %136, %110
%138 = bitcast double* %134 to <2 x double>*
store <2 x double> %137, <2 x double>* %138
br label %139
139: ; preds = %130, %132
br i1 %23, label %150, label %140
140: ; preds = %106, %139
%141 = phi i64 [ 0, %106 ], [ %18, %139 ]
br label %142
142: ; preds = %140, %142
%143 = phi i64 [ %148, %142 ], [ %141, %140 ]
%144 = add nuw nsw i64 %143, %107
%145 = getelementptr inbounds double, double* %6, i64 %144
%146 = load double, double* %145
%147 = fdiv double %146, %98
store double %147, double* %145
%148 = add nuw nsw i64 %143, 1
%149 = icmp eq i64 %148, %11
br i1 %149, label %150, label %142
150: ; preds = %142, %139, %104, %100
%151 = add nuw nsw i64 %25, 1
%152 = icmp eq i64 %151, %11
br i1 %152, label %153, label %24
153: ; preds = %150, %7
ret void
}