#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);
int exp(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ stderr;
void _tram_estimate_transition_matrix(double *log_lagrangian_mult,
                                      double *conf_energies, int *count_matrix,
                                      int n_conf_states, double *scratch_M,
                                      double *transition_matrix) {
  int i, j;
  int ij, ji;
  int C;
  double divisor, max_sum;
  double *sum;
  sum = scratch_M;
  for (i = 0; i < n_conf_states; ++i) {
    sum[i] = 0.0;
    for (j = 0; j < n_conf_states; ++j) {
      ij = i * n_conf_states + j;
      ji = j * n_conf_states + i;
      transition_matrix[ij] = 0.0;
      C = count_matrix[ij] + count_matrix[ji];
      if (0 == C)
        continue;
      if (i == j) {
        transition_matrix[ij] = 0.5 * C * exp(-log_lagrangian_mult[i]);
      } else {
        divisor = _logsumexp_pair(log_lagrangian_mult[j] - conf_energies[i],
                                  log_lagrangian_mult[i] - conf_energies[j]);
        transition_matrix[ij] = C * exp(-(conf_energies[j] + divisor));
      }
      sum[i] += transition_matrix[ij];
    }
  }
  max_sum = 0;
  for (i = 0; i < n_conf_states; ++i)
    if (sum[i] > max_sum)
      max_sum = sum[i];
  if (max_sum == 0)
    max_sum = 1.0;
  for (i = 0; i < n_conf_states; ++i) {
    for (j = 0; j < n_conf_states; ++j) {
      if (i == j) {
        transition_matrix[i * n_conf_states + i] =
            (transition_matrix[i * n_conf_states + i] + max_sum - sum[i]) /
            max_sum;
        if (0 == transition_matrix[i * n_conf_states + i] &&
            0 < count_matrix[i * n_conf_states + i])
          fprintf(stderr,
                  "# Warning: zero diagonal element T[%d,%d] with non-zero "
                  "counts.\n",
                  i, i);
      } else {
        transition_matrix[i * n_conf_states + j] =
            transition_matrix[i * n_conf_states + j] / max_sum;
      }
    }
  }
}


x86 assembly (clang, -O0):
<_tram_estimate_transition_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1315 <_tram_estimate_transition_matrix+0x1e5>
mov    -0x60(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1302 <_tram_estimate_transition_matrix+0x1d2>
mov    -0x34(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
movslq -0x40(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x44(%rbp)
xor    %eax,%eax
cmp    -0x44(%rbp),%eax
jne    11e0 <_tram_estimate_transition_matrix+0xb0>
jmp    12f4 <_tram_estimate_transition_matrix+0x1c4>
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    124a <_tram_estimate_transition_matrix+0x11a>
cvtsi2sdl -0x44(%rbp),%xmm1
movsd  0xe0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <exp@plt>
movsd  -0x68(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12d5 <_tram_estimate_transition_matrix+0x1a5>
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%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    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
call   1040 <_logsumexp_pair@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <exp@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x60(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1181 <_tram_estimate_transition_matrix+0x51>
jmp    1307 <_tram_estimate_transition_matrix+0x1d7>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115e <_tram_estimate_transition_matrix+0x2e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    136d <_tram_estimate_transition_matrix+0x23d>
mov    -0x60(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x58(%rbp),%xmm0
jbe    135a <_tram_estimate_transition_matrix+0x22a>
mov    -0x60(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    135f <_tram_estimate_transition_matrix+0x22f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1324 <_tram_estimate_transition_matrix+0x1f4>
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1392 <_tram_estimate_transition_matrix+0x262>
jp     1392 <_tram_estimate_transition_matrix+0x262>
movsd  0xc73(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    14bf <_tram_estimate_transition_matrix+0x38f>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    14ac <_tram_estimate_transition_matrix+0x37c>
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    1468 <_tram_estimate_transition_matrix+0x338>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x58(%rbp),%xmm0
mov    -0x60(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
divsd  -0x58(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jne    1463 <_tram_estimate_transition_matrix+0x333>
jp     1463 <_tram_estimate_transition_matrix+0x333>
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0x34(%rbp),%eax
movslq %eax,%rdx
xor    %eax,%eax
cmp    (%rcx,%rdx,4),%eax
jge    1463 <_tram_estimate_transition_matrix+0x333>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    0xbb2(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1499 <_tram_estimate_transition_matrix+0x369>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x58(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    149e <_tram_estimate_transition_matrix+0x36e>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    13ac <_tram_estimate_transition_matrix+0x27c>
jmp    14b1 <_tram_estimate_transition_matrix+0x381>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1399 <_tram_estimate_transition_matrix+0x269>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tram_estimate_transition_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x60(%rsp)
mov    %rdi,0x38(%rsp)
mov    %ecx,0xc(%rsp)
test   %ecx,%ecx
jle    1462 <_tram_estimate_transition_matrix+0x332>
mov    0xc(%rsp),%esi
lea    0x0(,%rsi,4),%r13
lea    0x0(,%rsi,8),%rax
mov    %rax,0x58(%rsp)
xor    %ebp,%ebp
mov    0x18(%rsp),%rax
mov    %rax,0x40(%rsp)
mov    0x20(%rsp),%rcx
xor    %r12d,%r12d
mov    %r8,0x30(%rsp)
mov    %rsi,0x28(%rsp)
jmp    11c0 <_tram_estimate_transition_matrix+0x90>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x4,%rbp
add    0x58(%rsp),%rcx
add    %r13,0x40(%rsp)
mov    0x28(%rsp),%rsi
cmp    %rsi,%r12
je     12c8 <_tram_estimate_transition_matrix+0x198>
movq   $0x0,(%r8,%r12,8)
mov    0x18(%rsp),%rbx
xor    %r15d,%r15d
mov    %rcx,0x10(%rsp)
mov    %rbp,0x68(%rsp)
jmp    125f <_tram_estimate_transition_matrix+0x12f>
nop
mov    0x38(%rsp),%rax
movsd  (%rax,%r15,2),%xmm0
mov    %r13,%rbp
mov    0x60(%rsp),%r13
subsd  0x0(%r13,%r12,8),%xmm0
movsd  (%rax,%r12,8),%xmm1
subsd  0x0(%r13,%r15,2),%xmm1
call   1040 <_logsumexp_pair@plt>
addsd  0x0(%r13,%r15,2),%xmm0
mov    %rbp,%r13
mov    0x68(%rsp),%rbp
xorpd  0xddd(%rip),%xmm0
call   1050 <exp@plt>
mov    0x10(%rsp),%rcx
mov    0x30(%rsp),%r8
imul   %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rcx,%r15,2)
addsd  (%r8,%r12,8),%xmm0
movsd  %xmm0,(%r8,%r12,8)
add    $0x4,%r15
add    %r13,%rbx
cmp    %r15,%r13
je     11a0 <_tram_estimate_transition_matrix+0x70>
movq   $0x0,(%rcx,%r15,2)
mov    (%rbx,%rbp,1),%r14d
mov    0x40(%rsp),%rax
add    (%rax,%r15,1),%r14d
je     124f <_tram_estimate_transition_matrix+0x11f>
cmp    %r15,%rbp
jne    11e0 <_tram_estimate_transition_matrix+0xb0>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
mulsd  0xd81(%rip),%xmm0
movsd  %xmm0,0x70(%rsp)
mov    0x38(%rsp),%rax
movsd  (%rax,%r12,8),%xmm0
xorps  0xd59(%rip),%xmm0
call   1050 <exp@plt>
mov    0x10(%rsp),%rcx
mov    0x30(%rsp),%r8
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x70(%rsp),%xmm0
jmp    123d <_tram_estimate_transition_matrix+0x10d>
cmpl   $0x0,0xc(%rsp)
jle    1462 <_tram_estimate_transition_matrix+0x332>
lea    -0x1(%rsi),%rcx
mov    %esi,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    12ea <_tram_estimate_transition_matrix+0x1ba>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    1334 <_tram_estimate_transition_matrix+0x204>
mov    %esi,%edx
and    $0xfffffffc,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%r8,%rcx,8),%xmm1
maxsd  %xmm0,%xmm1
movsd  0x8(%r8,%rcx,8),%xmm0
maxsd  %xmm1,%xmm0
movsd  0x10(%r8,%rcx,8),%xmm1
maxsd  %xmm0,%xmm1
movsd  0x18(%r8,%rcx,8),%xmm0
maxsd  %xmm1,%xmm0
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1300 <_tram_estimate_transition_matrix+0x1d0>
movapd %xmm0,%xmm1
test   %rax,%rax
je     1366 <_tram_estimate_transition_matrix+0x236>
lea    (%r8,%rcx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rcx,%rdx,8),%xmm1
maxsd  %xmm0,%xmm1
add    $0x1,%rdx
movapd %xmm1,%xmm0
cmp    %rdx,%rax
jne    1350 <_tram_estimate_transition_matrix+0x220>
cmpl   $0x0,0xc(%rsp)
jle    1462 <_tram_estimate_transition_matrix+0x332>
xorpd  %xmm2,%xmm2
movapd %xmm1,%xmm3
cmpeqsd %xmm2,%xmm3
movsd  0xc92(%rip),%xmm0
andpd  %xmm3,%xmm0
andnpd %xmm1,%xmm3
orpd   %xmm0,%xmm3
lea    0x0(,%rsi,8),%rax
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
mov    0x2c38(%rip),%r15
lea    0xc71(%rip),%r12
mov    0x20(%rsp),%r13
movapd %xmm3,0x40(%rsp)
jmp    13d4 <_tram_estimate_transition_matrix+0x2a4>
nopl   0x0(%rax)
add    $0x1,%rbx
add    0x10(%rsp),%r13
cmp    0x28(%rsp),%rbx
je     1462 <_tram_estimate_transition_matrix+0x332>
mov    %ebx,%eax
imul   0xc(%rsp),%eax
movslq %eax,%rbp
add    %rbx,%rbp
xor    %r14d,%r14d
jmp    140d <_tram_estimate_transition_matrix+0x2dd>
cs nopw 0x0(%rax,%rax,1)
movsd  0x0(%r13,%r14,8),%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,0x0(%r13,%r14,8)
add    $0x1,%r14
cmp    %r14,0x28(%rsp)
je     13c0 <_tram_estimate_transition_matrix+0x290>
cmp    %r14,%rbx
jne    13f0 <_tram_estimate_transition_matrix+0x2c0>
mov    0x20(%rsp),%rax
movsd  (%rax,%rbp,8),%xmm0
addsd  %xmm3,%xmm0
subsd  (%r8,%rbx,8),%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,(%rax,%rbp,8)
ucomisd %xmm2,%xmm0
jne    1402 <_tram_estimate_transition_matrix+0x2d2>
jp     1402 <_tram_estimate_transition_matrix+0x2d2>
mov    0x18(%rsp),%rax
cmpl   $0x0,(%rax,%rbp,4)
jle    1402 <_tram_estimate_transition_matrix+0x2d2>
mov    (%r15),%edi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %ebx,%ecx
call   1030 <fprintf@plt>
movapd 0x40(%rsp),%xmm3
xorpd  %xmm2,%xmm2
mov    0x30(%rsp),%r8
jmp    1402 <_tram_estimate_transition_matrix+0x2d2>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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