// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/./process_vcf_coding_sequences.h
// Function: addAllPairwiseN_S_Nd_Sd_DifferentIndividuals(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::map<unsigned long, int, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, int>>>&, CDSComparisonMatrices&)
inline void addAllPairwiseN_S_Nd_Sd_DifferentIndividuals(const std::vector<string>& altCodons, std::map<std::vector<string>::size_type, int>& haveStop, CDSComparisonMatrices& p) {

    for (std::vector<std::string>::size_type j = 0; j != altCodons.size() - 1; j++) {
        if (haveStop[j] == 1 || getAminoAcid(altCodons[j]) == "Uncrecognised codon....")
            continue; // only consider this individual if it did not have a premature stop codon and there are no unrecognised letters
        for (std::vector<std::string>::size_type k = j+1; k != altCodons.size(); k++) {
            if (haveStop[k] == 1 || getAminoAcid(altCodons[k]) == "Uncrecognised codon....")
                continue;
            int d = getCodonDistance(altCodons[j],altCodons[k]);
            // std::cerr << "Got codon distance: d = " << d << std::endl;
//            double n_d_ijk = calculateNd(altCodons[j],altCodons[k], d);
//            double s_d_ijk = d - n_d_ijk;
            //std::cerr << "N_d_jk[j][k] = " << p.N_d_jk[j][k] << std::endl;
            //print_matrix(N_d_jk, std::cout);
            double n_d_ijk = calculateNd(altCodons[j],altCodons[k], d);
          //  std::cerr << "Calculated Nd; n_d_ijk[0] = " << n_d_ijk[0] << std::endl;
          //  std::cerr << "Calculated Nd; n_d_ijk[1] = " << n_d_ijk[1] << std::endl;
          //  std::cerr << "Calculated Nd; n_d_ijk[2] = " << n_d_ijk[2] << std::endl;
            double s_d_ijk = d - n_d_ijk;
            p.N_d_jk[j][k] = p.N_d_jk[j][k] + n_d_ijk;
            p.S_d_jk[j][k] = p.S_d_jk[j][k] + s_d_ijk;

//          p.N_d_jk[j][k] = p.N_d_jk[j][k] + n_d_ijk;
//          p.S_d_jk[j][k] = p.S_d_jk[j][k] + s_d_ijk;
            
            //  n_di = n_di + n_d_ijk; s_di = s_di + s_d_ijk;
            double N_ijk = calculateN(altCodons[j],altCodons[k], d, false);
            //std::cerr << "Calculated N; N_ijk = " <<N_ijk << std::endl;
            double S_ijk = (3 - N_ijk);
            p.N_jk[j][k] = p.N_jk[j][k] + N_ijk; p.S_jk[j][k] = p.S_jk[j][k] + S_ijk;
            //std::cerr << "altCodons[j] = " << altCodons[j] << "; altCodons[k] = " << altCodons[k] << std::endl;
            //std::cerr << "j = " << j << "; k = " << k << std::endl;
            //std::cerr << "d = " << d << "; n_d_ijk = " << n_d_ijk << "; N_ijk = " << N_ijk << std::endl;
            //std::cerr << "N_d_jk[j][k] = " << p.N_d_jk[j][k] << "; N_jk[j][k] = " << p.N_jk[j][k] << std::endl;
            double N_tS = calculateNtS(altCodons[j],altCodons[k], d, false);
            p.tS_N_jk[j][k] = p.tS_N_jk[j][k] + N_tS;
            p.tS_S_jk[j][k] = p.tS_S_jk[j][k] + (1 - N_tS);
            p.tV_N_jk[j][k] = p.tV_N_jk[j][k] + (N_ijk - N_tS);
            p.tV_S_jk[j][k] = p.tV_S_jk[j][k] + (2 - (N_ijk - N_tS));
            

        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
xorl %eax, %eax
leaq 0x18(%rsp), %r13
leaq 0x8(%rsp), %r12
movq %rax, (%rsp)
movq 0x8(%r15), %rcx
subq (%r15), %rcx
sarq $0x5, %rcx
decq %rcx
cmpq %rcx, %rax
je 0x5aff3
movq %r14, %rdi
movq %rsp, %rsi
callq 0x5a5fe
cmpl $0x1, (%rax)
je 0x5ae05
movq (%rsp), %rsi
shlq $0x5, %rsi
addq (%r15), %rsi
movq %r13, %rdi
callq 0x5a79e
movq %r13, %rdi
leaq 0x49cf6(%rip), %rsi     # 0xa4ae7
callq 0x2193f
movl %eax, %ebp
movq %r13, %rdi
callq 0x8978
testb %bpl, %bpl
je 0x5ae0e
movq (%rsp), %rax
incq %rax
jmp 0x5ada9
movq %rsp, %rax
movq (%rax), %rax
incq %rax
movq %rax, 0x8(%rsp)
movq 0x8(%r15), %rcx
subq (%r15), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
je 0x5ae05
movq %r14, %rdi
movq %r12, %rsi
callq 0x5a5fe
cmpl $0x1, (%rax)
movq %r12, %rax
je 0x5ae11
movq 0x8(%rsp), %rsi
shlq $0x5, %rsi
addq (%r15), %rsi
movq %r13, %rdi
callq 0x5a79e
movq %r13, %rdi
leaq 0x49c8a(%rip), %rsi     # 0xa4ae7
callq 0x2193f
movl %eax, %ebp
movq %r13, %rdi
callq 0x8978
movq %r12, %rax
testb %bpl, %bpl
jne 0x5ae11
movq (%rsp), %rdi
movq (%r15), %rax
shlq $0x5, %rdi
addq %rax, %rdi
movq 0x8(%rsp), %rsi
shlq $0x5, %rsi
addq %rax, %rsi
callq 0x5b732
movl %eax, %ebp
movq (%rsp), %rdi
movq (%r15), %rax
shlq $0x5, %rdi
addq %rax, %rdi
movq 0x8(%rsp), %rsi
shlq $0x5, %rsi
addq %rax, %rsi
movl %ebp, %edx
callq 0x5b840
cvtsi2sd %ebp, %xmm1
subsd %xmm0, %xmm1
movq (%rsp), %rdi
movq (%rbx), %rax
imulq $0x18, %rdi, %rcx
movq 0x8(%rsp), %rsi
movq (%rax,%rcx), %rax
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
movq 0x30(%rbx), %rax
movq (%rax,%rcx), %rax
addsd (%rax,%rsi,8), %xmm1
movsd %xmm1, (%rax,%rsi,8)
movq (%r15), %rax
shlq $0x5, %rdi
addq %rax, %rdi
shlq $0x5, %rsi
addq %rax, %rsi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x5c045
movapd %xmm0, %xmm2
movsd %xmm0, 0x10(%rsp)
movsd 0x4934e(%rip), %xmm0    # 0xa4268
subsd %xmm2, %xmm0
movq (%rsp), %rdi
movq 0x18(%rbx), %rax
imulq $0x18, %rdi, %rcx
movq 0x8(%rsp), %rsi
movq (%rax,%rcx), %rax
movsd (%rax,%rsi,8), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, (%rax,%rsi,8)
movq 0x48(%rbx), %rax
movq (%rax,%rcx), %rax
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
movq (%r15), %rax
shlq $0x5, %rdi
addq %rax, %rdi
shlq $0x5, %rsi
addq %rax, %rsi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x5cb94
imulq $0x18, (%rsp), %rax
movq 0x60(%rbx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rax), %rcx
movsd (%rcx,%rdx,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
movq 0x78(%rbx), %rcx
movq (%rcx,%rax), %rcx
movsd 0x3c653(%rip), %xmm1    # 0x975f0
subsd %xmm0, %xmm1
addsd (%rcx,%rdx,8), %xmm1
movsd %xmm1, (%rcx,%rdx,8)
movq 0x90(%rbx), %rcx
movq (%rcx,%rax), %rcx
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x49298(%rip), %xmm0    # 0xa4260
subsd %xmm1, %xmm0
addsd (%rcx,%rdx,8), %xmm1
movsd %xmm1, (%rcx,%rdx,8)
movq 0xa8(%rbx), %rcx
movq (%rcx,%rax), %rax
addsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rdx,8)
movq %r12, %rax
jmp 0x5ae11
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq