// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_coding_sequences.cpp
// Function: getStatsHaploidSeq(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::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>>>>&, double)
void getStatsHaploidSeq(const std::vector<std::string>& allSeqs, std::vector<string>& statsThisGene, double tStVratio) {
    std::string::size_type geneLengthNt = allSeqs[0].length();
    int numSamples = (int)allSeqs.size();
    double pN = 0; double pS = 0;
    std::vector<string> altCodons; altCodons.resize(numSamples);
    std::map<std::vector<string>::size_type, int> haveStop;
    
    for (std::vector<string>::size_type i = 0; i != numSamples; i++) {
        assert(allSeqs[i].length() == geneLengthNt);
        altCodons[i] = ""; haveStop[i] = 0; 
    }
    
    CDSComparisonMatrices* pairwiseMatrices = new CDSComparisonMatrices(numSamples);
    for (string::size_type i = 0; i != geneLengthNt; i++) {
        for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
            altCodons[j] += allSeqs[j][i];
        }
        // Find the types of mutation we are dealing with
        if ((i+1)%3 == 0) {
            for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
                if (getAminoAcid(altCodons[j]) == "Stop") haveStop[j] = 1;
            }
           // std::cerr << "Now going to loop through codons: i = " << i << "altCodons.size():" << altCodons.size() << std::endl;
            addAllPairwiseN_S_Nd_Sd_DifferentIndividuals(altCodons,haveStop, *pairwiseMatrices);
            //std::cerr << "Added pairwise among H1:" << std::endl;
            for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
             //   std::cerr << "j = " << j << "; altCodons[j]: " << altCodons[j] << std::endl;
                altCodons[j] = "";
               // std::cerr << "j = " << j << "; haveStop[j]: " << haveStop[j] << std::endl;
            }
        }
    }
     
    double sumPn = 0; double sumPs = 0;
    std::vector<double> pNjackknifeVector;
    std::vector<double> pSjackknifeVector;
    std::vector<double> pN_pSjackknifeVector;
    // Add the within H1 and within H2 comparisons
    for (std::vector<std::string>::size_type j = 0; j != numSamples - 1; j++) {
        //std::cerr << "j = " << j << "; sumPn: " << sumPn << "; sumPs:" << sumPs << std::endl;
        for (std::vector<std::string>::size_type k = j+1; k != numSamples; k++) {
            //double pN_jk = pairwiseMatrices.H1p->N_d_jk[j][k]/pairwiseMatrices.H1p->N_jk[j][k];
            double pN_jk = pairwiseMatrices->N_d_jk[j][k]/((2*tStVratio*pairwiseMatrices->tS_N_jk[j][k])+pairwiseMatrices->tV_N_jk[j][k]);
            if (std::isnan(pN_jk) || pairwiseMatrices->tS_N_jk[j][k] == 0) {
            std::cerr << "j = " << j << "; k = " << k << std::endl;
            std::cerr << "N_d_jk[j][k] = " << pairwiseMatrices->N_d_jk[j][k] << "; tS_N_jk[j][k] = " << pairwiseMatrices->tS_N_jk[j][k] << std::endl;
            std::cerr << "pN_jk = " << pN_jk << "; sumPn = " << sumPn << std::endl;
                print_matrix(pairwiseMatrices->N_d_jk, std::cerr);
                print_matrix(pairwiseMatrices->S_d_jk, std::cerr);
            }
            sumPn = sumPn + pN_jk;
            double pS_jk = pairwiseMatrices->S_d_jk[j][k]/((2*tStVratio*pairwiseMatrices->tS_S_jk[j][k])+pairwiseMatrices->tV_S_jk[j][k]);
            sumPs = sumPs + pS_jk;
    
            // make sure each sample is used only once in the jackknife calculation
            // to keep the observations independent
            if ((j % 2 == 0) && (k == j+1)) {
                pNjackknifeVector.push_back(pN_jk); pSjackknifeVector.push_back(pS_jk);
                pN_pSjackknifeVector.push_back(pN_jk-pS_jk);
            }
        }
    }
    pN = (2.0/(numSamples*(numSamples-1)))*sumPn;
    pS = (2.0/(numSamples*(numSamples-1)))*sumPs;
    
    statsThisGene.push_back(numToString(geneLengthNt));
    statsThisGene.push_back(numToString(pN));
    statsThisGene.push_back(numToString(pS));
    if (pNjackknifeVector.size() > 10) {
        double pNstdErr = jackknive_std_err(pNjackknifeVector);
        double pSstdErr = jackknive_std_err(pSjackknifeVector);
        double pNpSstdErr = jackknive_std_err(pN_pSjackknifeVector);
        statsThisGene.push_back(numToString(pNstdErr));
        statsThisGene.push_back(numToString(pSstdErr));
        statsThisGene.push_back(numToString(pNpSstdErr));
    } else {
        statsThisGene.push_back("NA");
        statsThisGene.push_back("NA");
        statsThisGene.push_back("NA");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movsd %xmm0, 0x38(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x8(%rdi), %rbp
movq 0x8(%rax), %rcx
movq %rcx, 0x48(%rsp)
subq %rax, %rbp
shrq $0x5, %rbp
xorpd %xmm0, %xmm0
leaq 0x90(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movslq %ebp, %rsi
movq %rsi, 0x30(%rsp)
callq 0x34872
leaq 0x150(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorl %edi, %edi
leaq 0x42385(%rip), %r14     # 0x99e1f
leaq 0x148(%rsp), %r15
movq %rsp, %r13
movq %rdi, (%rsp)
cmpq 0x30(%rsp), %rdi
je 0x57aee
movq (%rbx), %rax
shlq $0x5, %rdi
movq 0x48(%rsp), %rcx
cmpq %rcx, 0x8(%rax,%rdi)
jne 0x581a4
addq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0x88f0
movq %r15, %rdi
movq %r13, %rsi
callq 0x5a5fe
andl $0x0, (%rax)
movq (%rsp), %rdi
incq %rdi
jmp 0x57aa5
movl $0xc0, %edi
callq 0x8490
movq %rax, %r13
movq %r12, 0xb0(%rsp)
movq %rax, %rdi
movq %rbp, 0x78(%rsp)
movl %ebp, %esi
callq 0x5a64e
xorl %r14d, %r14d
movq %rsp, %rbp
cmpq 0x48(%rsp), %r14
je 0x57c0e
movq 0x30(%rsp), %r15
xorl %r12d, %r12d
subq $0x1, %r15
jb 0x57b53
movq (%rbx), %rax
movq (%rax,%r12), %rax
movsbl (%rax,%r14), %esi
movq 0x90(%rsp), %rdi
addq %r12, %rdi
callq 0x8400
addq $0x20, %r12
jmp 0x57b2b
incq %r14
movq %r14, %rax
xorl %edx, %edx
pushq $0x3
popq %rcx
divq %rcx
testq %rdx, %rdx
leaq 0x148(%rsp), %r12
jne 0x57b18
xorl %esi, %esi
movq %rsi, 0x60(%rsp)
cmpq 0x30(%rsp), %rsi
je 0x57bcc
shlq $0x5, %rsi
addq 0x90(%rsp), %rsi
movq %rbp, %rdi
callq 0x5a79e
movq %rbp, %rdi
leaq 0x4cc34(%rip), %rsi     # 0xa47ce
callq 0x2193f
movl %eax, %r15d
movq %rbp, %rdi
callq 0x8978
testb %r15b, %r15b
je 0x57bc2
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0x5a5fe
movl $0x1, (%rax)
movq 0x60(%rsp), %rsi
incq %rsi
jmp 0x57b70
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5ad86
movq 0x30(%rsp), %r15
xorl %r12d, %r12d
subq $0x1, %r15
jb 0x57b18
movq 0x90(%rsp), %rdi
addq %r12, %rdi
leaq 0x4221c(%rip), %rsi     # 0x99e1f
callq 0x88f0
addq $0x20, %r12
jmp 0x57be7
leaq 0x60(%rsp), %rax
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
leaq 0x100(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0xe0(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x78(%rsp), %rax
decl %eax
movl %eax, 0x5c(%rsp)
cltq
movq %rax, 0xb8(%rsp)
movsd 0x38(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r13, %rax
addq $0x30, %rax
movq %rax, 0xc8(%rsp)
decq 0x30(%rsp)
pushq $0x8
popq %r12
pushq $0x1
popq %rax
movq %rax, 0x80(%rsp)
xorl %eax, %eax
movq 0x85355(%rip), %rbp     # 0xdcfe8
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x50(%rsp)
cmpq 0xb8(%rsp), %rax
je 0x57f8a
leaq 0x1(%rax), %rcx
movq %rcx, 0xc0(%rsp)
movq %rax, 0x88(%rsp)
imulq $0x18, %rax, %rbx
xorl %r15d, %r15d
cmpq %r15, 0x30(%rsp)
je 0x57f6c
movq (%r13), %rax
movq 0x60(%r13), %rcx
movq (%rax,%rbx), %rax
addq %r12, %rax
movsd (%rax,%r15,8), %xmm1
movq (%rcx,%rbx), %rax
addq %r12, %rax
movq 0x90(%r13), %rcx
movq (%rcx,%rbx), %rcx
addq %r12, %rcx
movsd (%rax,%r15,8), %xmm0
mulsd 0x38(%rsp), %xmm0
addsd (%rcx,%r15,8), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd %xmm1, 0x20(%rsp)
ucomisd %xmm1, %xmm1
jp 0x57d42
movsd (%rax,%r15,8), %xmm0
ucomisd 0x3e462(%rip), %xmm0    # 0x96198
jne 0x57e91
jp 0x57e91
movq %rbp, %rdi
leaq 0x4ca87(%rip), %rsi     # 0xa47d3
callq 0x8480
movq %rax, %rdi
movq 0x88(%rsp), %rsi
callq 0x8320
movq %rax, %rdi
leaq 0x4ca6d(%rip), %rsi     # 0xa47d8
callq 0x8480
movq 0x80(%rsp), %rcx
leaq (%rcx,%r15), %rsi
movq %rax, %rdi
callq 0x8320
movq %rax, %rdi
callq 0x8230
movq %rbp, %rdi
leaq 0x4ca49(%rip), %rsi     # 0xa47df
callq 0x8480
movq (%r13), %rcx
movq (%rcx,%rbx), %rcx
addq %r12, %rcx
movsd (%rcx,%r15,8), %xmm0
movq %rax, %rdi
callq 0x8750
movq %rax, %rdi
leaq 0x4ca31(%rip), %rsi     # 0xa47ef
callq 0x8480
movq 0x60(%r13), %rcx
movq (%rcx,%rbx), %rcx
addq %r12, %rcx
movsd (%rcx,%r15,8), %xmm0
movq %rax, %rdi
callq 0x8750
movq %rax, %rdi
callq 0x8230
movq %rbp, %rdi
leaq 0x4ca14(%rip), %rsi     # 0xa4802
callq 0x8480
movsd (%rsp), %xmm0
movq %rax, %rdi
callq 0x8750
movq %rax, %rdi
leaq 0x4ca01(%rip), %rsi     # 0xa480b
callq 0x8480
movq %rax, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x8750
movq %rax, %rdi
callq 0x8230
leaq 0x130(%rsp), %rdi
movq %r13, %rsi
callq 0x5b09c
movq %rbp, %rsi
leaq 0x130(%rsp), %rbp
movq %rbp, %rdi
movq %rsi, %r14
callq 0x5b002
movq %rbp, %rdi
callq 0x37c74
leaq 0x118(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x5b09c
movq %r14, %rbp
leaq 0x118(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5b002
movq %r14, %rdi
callq 0x37c74
movsd (%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x30(%r13), %rax
movq 0x78(%r13), %rcx
movq (%rax,%rbx), %rax
addq %r12, %rax
movsd (%rax,%r15,8), %xmm1
movq (%rcx,%rbx), %rax
addq %r12, %rax
movq 0xa8(%r13), %rcx
movq (%rcx,%rbx), %rcx
addq %r12, %rcx
movsd (%rax,%r15,8), %xmm0
mulsd 0x38(%rsp), %xmm0
addsd (%rcx,%r15,8), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
testq %r15, %r15
setne %al
orb 0x88(%rsp), %al
testb $0x1, %al
jne 0x57f42
movsd %xmm1, 0xd0(%rsp)
leaq 0x60(%rsp), %rdi
movq %rsp, %rsi
callq 0x5a406
leaq 0x100(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x5a406
movsd (%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x2af10
movsd 0xd0(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x50(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
incq %r15
jmp 0x57ccc
addq $0x8, %r12
incq 0x80(%rsp)
decq 0x30(%rsp)
movq 0xc0(%rsp), %rax
jmp 0x57ca3
movq %rsp, %rdi
movq 0x48(%rsp), %rsi
callq 0x554cb
movq %rsp, %rsi
movq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3490e
movq 0x78(%rsp), %rax
movl 0x5c(%rsp), %ecx
imull %eax, %ecx
cvtsi2sd %ecx, %xmm0
movsd 0x4c29e(%rip), %xmm1    # 0xa4260
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rsp, %rdi
callq 0x8978
movq %rsp, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x37bd4
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movsd 0x20(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rsp, %rdi
callq 0x8978
movq %rsp, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x37bd4
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movq %rsp, %rdi
callq 0x8978
movq 0x68(%rsp), %rax
subq 0x60(%rsp), %rax
cmpq $0x51, %rax
jb 0x580df
leaq 0x60(%rsp), %rdi
callq 0x2f3e3
movsd %xmm0, 0x28(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x2f3e3
movsd %xmm0, 0x20(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x2f3e3
movsd %xmm0, 0x38(%rsp)
movq %rsp, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x37bd4
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movq %rsp, %rdi
callq 0x8978
movq %rsp, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x37bd4
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movq %rsp, %rdi
callq 0x8978
movq %rsp, %rdi
movsd 0x38(%rsp), %xmm0
callq 0x37bd4
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
jmp 0x5814c
leaq 0x3a65e(%rip), %rsi     # 0x92744
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x21904
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movq %rsp, %rdi
callq 0x8978
leaq 0x3a637(%rip), %rsi     # 0x92744
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x21904
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movq %rsp, %rdi
callq 0x8978
leaq 0x3a610(%rip), %rsi     # 0x92744
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x21904
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3490e
movq %rsp, %rdi
callq 0x8978
leaq 0xe0(%rsp), %rdi
callq 0x2b43c
leaq 0x100(%rsp), %rdi
callq 0x2b43c
leaq 0x60(%rsp), %rdi
callq 0x2b43c
leaq 0x148(%rsp), %rdi
callq 0x5d6e4
leaq 0x90(%rsp), %rdi
callq 0x28a08
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4c5a6(%rip), %rdi     # 0xa4751
leaq 0x4c41c(%rip), %rsi     # 0xa45ce
leaq 0x4c5bc(%rip), %rcx     # 0xa4775
movl $0x171, %edx            # imm = 0x171
callq 0x82f0
jmp 0x581e9
jmp 0x58243
jmp 0x581e9
jmp 0x581e9
jmp 0x58243
jmp 0x58243
jmp 0x581e9
jmp 0x581e9
jmp 0x58243
jmp 0x58243
jmp 0x58243
jmp 0x581e9
jmp 0x58243
jmp 0x58243
jmp 0x58243
jmp 0x581e9
jmp 0x58243
jmp 0x581e9
jmp 0x58243
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8978
jmp 0x58246
jmp 0x58243
movq %rax, %rbx
movl $0xc0, %esi
movq %r13, %rdi
callq 0x84a0
jmp 0x5826a
jmp 0x5823e
movq %rax, %rbx
jmp 0x58277
jmp 0x5823e
jmp 0x5823e
jmp 0x5823e
jmp 0x5823e
jmp 0x5823e
jmp 0x58243
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
jmp 0x58235
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x37c74
jmp 0x58246
jmp 0x58243
movq %rax, %rbx
jmp 0x5826a
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2b43c
leaq 0x100(%rsp), %rdi
callq 0x2b43c
leaq 0x60(%rsp), %rdi
callq 0x2b43c
leaq 0x148(%rsp), %rdi
callq 0x5d6e4
leaq 0x90(%rsp), %rdi
callq 0x28a08
movq %rbx, %rdi
callq 0x8870