// File: /workspace/github_c_makefile_star2_O3/debbiemarkslab[P]plmc/src/inference.c
// Function: ZeroAPCPriors
void ZeroAPCPriors(alignment_t *ali, options_t *options, numeric_t *lambdas,
    lbfgsfloatval_t *x) {
    /* Compute the variances of the couplings for each pair */
    for (int i = 0; i < ali->nSites - 1; i++)
        for (int j = i + 1; j < ali->nSites; j++) {
            /* Mean(eij) over ai, aj */
            numeric_t mean = 0.0;
            for (int ai = 0; ai < ali->nCodes; ai++)
                for (int aj = 0; aj < ali->nCodes; aj++)
                    mean += xEij(i, j, ai, aj);
            mean *= 1.0 / ((numeric_t) ali->nCodes * ali->nCodes);

            /* Var(eij) over ai, aj */
            numeric_t ssq = 0.0;
            for (int ai = 0; ai < ali->nCodes; ai++)
                for (int aj = 0; aj < ali->nCodes; aj++)
                    ssq += (xEij(i, j, ai, aj) - mean)
                         * (xEij(i, j, ai, aj) - mean);
            /* Use N rather than N-1 since N has better MSE */
            numeric_t var = ssq / ((numeric_t) (ali->nCodes * ali->nCodes));
            lambdaEij(i, j) = var;
        }

    /* Determine the site-wise statistics of the variances */
    numeric_t nPairs =  ((numeric_t) ((ali->nSites) * (ali->nSites - 1))) / 2.0;
    numeric_t V_avg = 0.0;
    numeric_t *V_pos_avg = (numeric_t *) malloc(ali->nSites * sizeof(numeric_t));
    for (int i = 0; i < ali->nSites; i++) {
        V_pos_avg[i] = 0.0;
    }
    for (int i = 0; i < ali->nSites - 1; i++) {
        for (int j = i + 1; j < ali->nSites; j++) {
            V_pos_avg[i] += lambdaEij(i, j) / (numeric_t) (ali->nSites - 1);
            V_pos_avg[j] += lambdaEij(i, j) / (numeric_t) (ali->nSites - 1);
            V_avg += lambdaEij(i, j) / nPairs;
        }
    }

    /* Remove the first component of the variances */
    for (int i = 0; i < ali->nSites - 1; i++)
        for (int j = i + 1; j < ali->nSites; j++)
            lambdaEij(i, j) =
                lambdaEij(i, j) - V_pos_avg[i] * V_pos_avg[j] / V_avg;

    /* Transform and truncate variances into lambda hyperparameters */
    numeric_t pcount = 0.0;
    numeric_t psum = 0.0;
    numeric_t inbounds = 0;
    numeric_t min = LAMBDA_J_MAX;
    numeric_t max = LAMBDA_J_MIN;
    for (int i = 0; i < ali->nSites - 1; i++) {
        for (int j = i + 1; j < ali->nSites; j++) {
            /* Lambda coefficients are 1/2 the inverse variance */
            if (lambdaEij(i, j) > 0) {
                lambdaEij(i, j) = 1.0 / (2.0 * lambdaEij(i, j));
                psum += lambdaEij(i, j);
                pcount += 1.0;
            } else {
                lambdaEij(i, j) = LAMBDA_J_MAX + 1.0;
            }

            /* Truncate lambda for numerical stability */
            if (lambdaEij(i, j) >= LAMBDA_J_MIN && lambdaEij(i, j) <= LAMBDA_J_MAX)
                inbounds += 1.0 / (numeric_t) ((ali->nSites)*(ali->nSites - 1) / 2.0);
            if (lambdaEij(i, j) < 0 || !isfinite(lambdaEij(i, j)))
                lambdaEij(i, j) = LAMBDA_J_MAX;
            if (lambdaEij(i, j) < LAMBDA_J_MIN) lambdaEij(i, j) = LAMBDA_J_MIN;
            if (lambdaEij(i, j) > LAMBDA_J_MAX) lambdaEij(i, j) = LAMBDA_J_MAX;

            /* Track extremes */
            if (lambdaEij(i, j) > max) max = lambdaEij(i, j);
            if (lambdaEij(i, j) < min) min = lambdaEij(i, j);
        }
    }
    fprintf(stderr, "Raw coupling hyperparameter statistics:\n"
                    "\tMean positive lambda: %f\n"
                    "\tPercent of ij's positive: %f\n"
                    "\tPercent in bounds (%f < L < %f): %f\n",
                    psum / pcount,
                    pcount / nPairs,
                    min, max, inbounds);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movslq 0x4(%rdi), %r12
leal -0x1(%r12), %eax
movl %eax, 0x4(%rsp)
pushq $0x2
popq %rbp
cmpq $0x2, %r12
jl 0x1c31
movl 0x8(%rdi), %r8d
movl %r8d, %r9d
imull %r12d, %r9d
cvtsi2sd %r8d, %xmm1
mulsd %xmm1, %xmm1
movsd 0xb5a5(%rip), %xmm0     # 0xd068
divsd %xmm1, %xmm0
movl %r8d, %eax
imull %r8d, %eax
movl %eax, 0x8(%rsp)
cvtsi2sd %eax, %xmm1
xorl %eax, %eax
pushq $0x1
popq %rsi
movl %eax, %r15d
leal 0x1(%r15), %edi
leal -0x1(%r15), %eax
imull %r15d, %eax
cltd
idivl %ebp
movq %rsi, 0x18(%rsp)
movq %rax, 0x20(%rsp)
leal (%rax,%rsi), %r13d
imull 0x8(%rsp), %r13d
movl %edi, 0x10(%rsp)
movl %edi, %r14d
testl %r8d, %r8d
jle 0x1bca
movq %r12, %r10
movq %rbx, %r12
leal -0x1(%r14), %edi
imull %r14d, %edi
movl %edi, %eax
cltd
idivl %ebp
addl %r15d, %eax
imull 0x8(%rsp), %eax
xorpd %xmm2, %xmm2
xorl %edx, %edx
movl %r13d, %r11d
movl %eax, %ebp
xorl %esi, %esi
leal (%r11,%rsi), %ebx
cmpl %r14d, %r15d
cmovbl %ebp, %ebx
addl %r9d, %ebx
movslq %ebx, %rbx
addsd (%rcx,%rbx,8), %xmm2
incl %esi
addl %r8d, %ebp
cmpl %esi, %r8d
jne 0x1b39
incl %edx
addl %r8d, %r11d
incl %eax
cmpl %r8d, %edx
jne 0x1b35
testl %r8d, %r8d
jle 0x1bd0
mulsd %xmm0, %xmm2
movl %edi, %eax
cltd
pushq $0x2
popq %rsi
idivl %esi
addl %r15d, %eax
imull 0x8(%rsp), %eax
xorpd %xmm3, %xmm3
xorl %edx, %edx
movl %r13d, %edi
movq %r12, %rbx
movq %r10, %r12
movl %eax, %r11d
xorl %ebp, %ebp
leal (%rdi,%rbp), %esi
cmpl %r14d, %r15d
cmovbl %r11d, %esi
addl %r9d, %esi
movslq %esi, %rsi
movsd (%rcx,%rsi,8), %xmm4
subsd %xmm2, %xmm4
mulsd %xmm4, %xmm4
addsd %xmm4, %xmm3
incl %ebp
addl %r8d, %r11d
cmpl %ebp, %r8d
jne 0x1b91
incl %edx
addl %r8d, %edi
incl %eax
cmpl %r8d, %edx
jne 0x1b8c
jmp 0x1bda
xorpd %xmm3, %xmm3
jmp 0x1bda
xorpd %xmm3, %xmm3
movq %r12, %rbx
movq %r10, %r12
cmpl %r14d, %r15d
jae 0x1bf2
leal -0x1(%r14), %eax
imull %r14d, %eax
cltd
pushq $0x2
popq %rbp
idivl %ebp
addl %r15d, %eax
jmp 0x1bfd
movq 0x20(%rsp), %rax
addl %r14d, %eax
pushq $0x2
popq %rbp
divsd %xmm1, %xmm3
addl %r12d, %eax
cltq
movsd %xmm3, (%rbx,%rax,8)
incl %r14d
addl 0x8(%rsp), %r13d
cmpl %r12d, %r14d
jne 0x1b08
movq 0x18(%rsp), %rsi
incl %esi
movl 0x10(%rsp), %eax
cmpl 0x4(%rsp), %eax
jne 0x1adb
movl 0x4(%rsp), %eax
imull %r12d, %eax
cvtsi2sd %eax, %xmm0
mulsd 0xb40b(%rip), %xmm0     # 0xd050
movsd %xmm0, 0x10(%rsp)
leaq (,%r12,8), %r15
movq %r15, %rdi
callq 0x11b0
movsd 0xb82d(%rip), %xmm3     # 0xd490
movsd 0xb865(%rip), %xmm2     # 0xd4d0
xorpd %xmm1, %xmm1
testl %r12d, %r12d
jle 0x219b
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x1110
cmpl $0x2, %r12d
jl 0x21ac
movabsq $0x100000000, %rsi      # imm = 0x100000000
movl 0x4(%rsp), %eax
cvtsi2sd %eax, %xmm1
movl %eax, %r13d
xorpd %xmm0, %xmm0
pushq $0x1
popq %rdi
xorl %r8d, %r8d
movq %rsi, %r9
movsd 0x10(%rsp), %xmm10
movsd 0xb7cd(%rip), %xmm3     # 0xd490
movsd 0xb805(%rip), %xmm2     # 0xd4d0
movq %r8, %r10
incq %r8
leal (%rsi,%r10), %eax
decl %eax
imull %r10d, %eax
cltd
idivl %ebp
movl %eax, %ecx
movq %r9, %r11
movq %rdi, %r15
cmpq %r15, %r10
jae 0x1cfa
movl %r11d, %eax
imull %r15d, %eax
cltd
idivl %ebp
addl %r10d, %eax
jmp 0x1cfe
leal (%rcx,%r15), %eax
addl %r12d, %eax
cltq
movsd (%rbx,%rax,8), %xmm4
divsd %xmm1, %xmm4
addsd (%r14,%r10,8), %xmm4
movsd %xmm4, (%r14,%r10,8)
cmpq %r15, %r10
jae 0x1d2c
movl %r11d, %eax
imull %r15d, %eax
cltd
idivl %ebp
addl %r10d, %eax
jmp 0x1d30
leal (%rcx,%r15), %eax
addl %r12d, %eax
cltq
movsd (%rbx,%rax,8), %xmm4
divsd %xmm1, %xmm4
addsd (%r14,%r15,8), %xmm4
movsd %xmm4, (%r14,%r15,8)
cmpq %r15, %r10
jae 0x1d5e
movl %r11d, %eax
imull %r15d, %eax
cltd
idivl %ebp
addl %r10d, %eax
jmp 0x1d62
leal (%rcx,%r15), %eax
addl %r12d, %eax
cltq
movsd (%rbx,%rax,8), %xmm4
divsd %xmm10, %xmm4
addsd %xmm4, %xmm0
incq %r15
incq %r11
cmpq %r15, %r12
jne 0x1ce6
incq %rdi
incq %r9
cmpq %r13, %r8
jne 0x1ccb
xorpd %xmm1, %xmm1
cmpl $0x2, %r12d
jl 0x21d1
pushq $0x1
popq %rdi
xorl %r8d, %r8d
movq %rsi, %r9
movq %r8, %r10
incq %r8
leal (%rsi,%r10), %eax
decl %eax
imull %r10d, %eax
cltd
idivl %ebp
movl %eax, %ecx
movsd (%r14,%r10,8), %xmm6
movq %r9, %r11
movq %rdi, %r15
cmpq %r15, %r10
jae 0x1ddf
movl %r11d, %eax
imull %r15d, %eax
cltd
idivl %ebp
addl %r10d, %eax
jmp 0x1de3
leal (%rcx,%r15), %eax
addl %r12d, %eax
cltq
movsd (%rbx,%rax,8), %xmm5
movsd (%r14,%r15,8), %xmm4
mulsd %xmm6, %xmm4
cmpq %r15, %r10
jae 0x1e0b
movl %r11d, %eax
imull %r15d, %eax
cltd
idivl %ebp
addl %r10d, %eax
jmp 0x1e0f
leal (%rcx,%r15), %eax
divsd %xmm0, %xmm4
subsd %xmm4, %xmm5
addl %r12d, %eax
cltq
movsd %xmm5, (%rbx,%rax,8)
incq %r15
incq %r11
cmpq %r15, %r12
jne 0x1dcb
incq %rdi
incq %r9
cmpq %r13, %r8
jne 0x1daa
xorpd %xmm0, %xmm0
xorpd %xmm4, %xmm4
cmpl $0x2, %r12d
jl 0x21d9
movsd 0xb212(%rip), %xmm13    # 0xd068
movapd %xmm13, %xmm12
divsd %xmm10, %xmm12
leal 0x1(%r12), %eax
movl %eax, 0x18(%rsp)
leaq -0x1(%r12), %r9
xorpd %xmm11, %xmm11
movsd 0xb655(%rip), %xmm5     # 0xd4d0
movsd 0xb60d(%rip), %xmm6     # 0xd490
xorl %eax, %eax
movabsq $0x40c3880000000000, %r15 # imm = 0x40C3880000000000
movabsq $0x40c3888000000000, %r8 # imm = 0x40C3888000000000
movapd %xmm6, %xmm3
movapd %xmm5, %xmm2
xorpd %xmm1, %xmm1
movq %r13, 0x20(%rsp)
movq %rax, %r13
incq %rax
movq %rax, 0x8(%rsp)
leal (%rsi,%r13), %eax
decl %eax
imull %r13d, %eax
cltd
idivl %ebp
leal (%r12,%r13), %edi
movslq %eax, %r11
leaq 0x1(%r11), %r14
addl 0x18(%rsp), %r11d
movq %r13, %r10
movq %r10, %rcx
incq %r10
cmpq %r10, %r13
jae 0x1f17
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
leal (%rax,%rdi), %edx
movslq %edx, %rdx
movsd (%rbx,%rdx,8), %xmm7
ucomisd %xmm11, %xmm7
jbe 0x1f52
addsd %xmm7, %xmm7
movapd %xmm13, %xmm8
divsd %xmm7, %xmm8
movsd %xmm8, (%rbx,%rdx,8)
addl %r13d, %eax
jmp 0x1f41
leal (%r11,%rcx), %eax
cltq
movsd (%rbx,%rax,8), %xmm7
ucomisd %xmm11, %xmm7
jbe 0x1f57
addsd %xmm7, %xmm7
movapd %xmm13, %xmm8
divsd %xmm7, %xmm8
movsd %xmm8, (%rbx,%rax,8)
leal (%r14,%rcx), %eax
addl %r12d, %eax
cltq
addsd (%rbx,%rax,8), %xmm0
addsd %xmm13, %xmm1
jmp 0x1f64
addl %r13d, %eax
jmp 0x1f5b
leal (%r14,%rcx), %eax
addl %r12d, %eax
cltq
movq %r8, (%rbx,%rax,8)
cmpq %r10, %r13
jae 0x1f8b
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
leal (%rax,%rdi), %edx
movslq %edx, %rdx
movsd (%rbx,%rdx,8), %xmm7
ucomisd %xmm6, %xmm7
jb 0x1fd5
addl %r13d, %eax
jmp 0x1fa0
leal (%r11,%rcx), %eax
cltq
movsd (%rbx,%rax,8), %xmm7
ucomisd %xmm6, %xmm7
jb 0x2006
leal (%r14,%rcx), %eax
addl %r12d, %eax
cltq
movsd (%rbx,%rax,8), %xmm7
movapd %xmm12, %xmm8
addsd %xmm4, %xmm8
cmpnlesd %xmm5, %xmm7
movapd %xmm7, %xmm9
andnpd %xmm8, %xmm9
andpd %xmm4, %xmm7
orpd %xmm9, %xmm7
movapd %xmm7, %xmm4
cmpq %r10, %r13
jae 0x2000
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
leal (%rax,%rdi), %edx
movslq %edx, %rdx
ucomisd (%rbx,%rdx,8), %xmm11
jbe 0x2039
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
addl %r13d, %eax
jmp 0x206a
leal (%r11,%rcx), %eax
cltq
ucomisd (%rbx,%rax,8), %xmm11
ja 0x2066
leal (%r11,%rcx), %eax
cltq
movq (%rbx,%rax,8), %rax
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
andq %rdx, %rax
movabsq $0x7fefffffffffffff, %rdx # imm = 0x7FEFFFFFFFFFFFFF
cmpq %rdx, %rax
jg 0x2066
jmp 0x211c
addl %r13d, %eax
addl %r12d, %eax
cltq
movq (%rbx,%rax,8), %rax
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
andq %rdx, %rax
movabsq $0x7fefffffffffffff, %rdx # imm = 0x7FEFFFFFFFFFFFFF
cmpq %rdx, %rax
jle 0x2073
cmpq %r10, %r13
jb 0x1fef
leal (%r14,%rcx), %eax
addl %r12d, %eax
cltq
movq %r15, (%rbx,%rax,8)
cmpq %r10, %r13
jae 0x211c
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
leal (%rax,%rdi), %edx
movslq %edx, %rdx
ucomisd (%rbx,%rdx,8), %xmm6
jbe 0x20ab
addl %r13d, %eax
addl %r12d, %eax
cltq
movabsq $0x3f847ae147ae147b, %rdx # imm = 0x3F847AE147AE147B
movq %rdx, (%rbx,%rax,8)
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
leal (%rax,%rdi), %edx
movslq %edx, %rdx
movsd (%rbx,%rdx,8), %xmm7
ucomisd %xmm5, %xmm7
jbe 0x20d4
addl %r13d, %eax
addl %r12d, %eax
cltq
movq %r15, (%rbx,%rax,8)
leal (%rcx,%rsi), %edx
movl %r10d, %eax
imull %edx, %eax
cltd
idivl %ebp
leal (%rax,%rdi), %edx
movslq %edx, %rdx
movsd (%rbx,%rdx,8), %xmm7
ucomisd %xmm3, %xmm7
jbe 0x20fe
addl %r13d, %eax
addl %r12d, %eax
cltq
movsd (%rbx,%rax,8), %xmm3
addl %esi, %ecx
movl %r10d, %eax
imull %ecx, %eax
cltd
idivl %ebp
movl %eax, %ecx
leal (%rcx,%rdi), %eax
cltq
ucomisd (%rbx,%rax,8), %xmm2
jbe 0x217d
addl %r13d, %ecx
jmp 0x2172
leal (%r11,%rcx), %eax
cltq
ucomisd (%rbx,%rax,8), %xmm6
jbe 0x213d
leal (%r11,%rcx), %eax
cltq
movabsq $0x3f847ae147ae147b, %rdx # imm = 0x3F847AE147AE147B
movq %rdx, (%rbx,%rax,8)
movsd (%rbx,%rax,8), %xmm7
ucomisd %xmm5, %xmm7
jbe 0x2152
leal (%r11,%rcx), %eax
cltq
movq %r15, (%rbx,%rax,8)
movsd (%rbx,%rax,8), %xmm7
ucomisd %xmm3, %xmm7
jbe 0x2168
leal (%r11,%rcx), %eax
cltq
movsd (%rbx,%rax,8), %xmm3
ucomisd (%rbx,%rax,8), %xmm2
jbe 0x217d
addl %r14d, %ecx
leal (%r12,%rcx), %eax
cltq
movsd (%rbx,%rax,8), %xmm2
cmpq %r10, %r9
jne 0x1ed5
movq 0x20(%rsp), %r13
movq 0x8(%rsp), %rax
cmpq %r13, %rax
jne 0x1eaa
jmp 0x21d9
xorpd %xmm0, %xmm0
xorpd %xmm4, %xmm4
movsd 0x10(%rsp), %xmm10
jmp 0x21d9
xorpd %xmm0, %xmm0
xorpd %xmm4, %xmm4
movsd 0x10(%rsp), %xmm10
movsd 0xb2cd(%rip), %xmm3     # 0xd490
movsd 0xb305(%rip), %xmm2     # 0xd4d0
xorpd %xmm1, %xmm1
jmp 0x21d9
xorpd %xmm0, %xmm0
xorpd %xmm4, %xmm4
movq 0xee18(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
divsd %xmm1, %xmm0
divsd %xmm10, %xmm1
leaq 0xb449(%rip), %rsi      # 0xd63c
movb $0x5, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1180