// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_print_routines.cpp
// Function: print_pairwise_diff_stats(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>>>> const&, int, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>> const&, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>> const&, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>> const&, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> const&)
void print_pairwise_diff_stats(const string& fileRoot, const std::vector<std::string>& header, const int totalVariantNumber, const std::vector<std::vector<double> >& diffMatrix, const std::vector<std::vector<double> >& diffMatrixMe, const std::vector<std::vector<double> >& diffMatrixHetsVsHomDiff, const std::vector<std::vector<int> >& pairwiseMissingness) {
    std::ios_base::openmode mode_out = std::ios_base::out;
    string diffFileName = fileRoot + ".diff_matrix.txt";
    string diffMeFileName = fileRoot + ".diff_me_matrix.txt";
    string hetHomFileName = fileRoot + ".hets_over_homs_matrix.txt";
    string pairwiseMisFileName = fileRoot + ".parwiseMissingness.txt";
    std::ofstream* pDiffOutFile = new std::ofstream(diffFileName.c_str(), mode_out);
    std::ofstream* pDiffMeOutFile = new std::ofstream(diffMeFileName.c_str(), mode_out);
    std::ofstream* pHetHomOutFile = new std::ofstream(hetHomFileName.c_str(), mode_out);
    std::ofstream* pPairMisOutFile = new std::ofstream(pairwiseMisFileName.c_str(), mode_out);
    *pDiffOutFile << "# Input file:" << fileRoot << ".vcf" << std::endl;
    *pDiffOutFile << "# Total number of segragating variant sites in this sample:" << totalVariantNumber << std::endl;
    *pDiffOutFile << "# Richard's scoring scheme" << std::endl;
    *pDiffMeOutFile << "# Input file:" << fileRoot << ".vcf" << std::endl;
    *pDiffMeOutFile << "# Total number of segragating variant sites in this sample: " << totalVariantNumber << std::endl;
    *pDiffMeOutFile << "# Homozygous difference = 1, one homozygous, another heterozygous = 0.5" << std::endl;
    *pHetHomOutFile << "# Input file:" << fileRoot << ".vcf" << std::endl;
    *pHetHomOutFile << "# number of sites both individuals hets/number of sites individuals have a homozygous difference; i.e. num(1/0::1/0)/num(1/1::0/0)" << std::endl;
    *pHetHomOutFile << "# For a free mixing population, we expect this number ~2; for fully separated species ~0" << std::endl;
    *pPairMisOutFile << "# Input file:" << fileRoot << ".vcf" << std::endl;
    *pPairMisOutFile << "# Total number of segragating variant sites in this sample: " << totalVariantNumber << std::endl;
    *pPairMisOutFile << "# Pairwise missingness:" << std::endl;
    
    
    // print headers
    print_vector(header,*pDiffOutFile);
    print_vector(header,*pDiffMeOutFile);
    print_vector(header,*pHetHomOutFile);
    print_vector(header,*pPairMisOutFile);
    
    for (int i = 0; i < (int)diffMatrixMe.size(); i++) {
        for (int j = 0; j < (int)diffMatrixMe.size(); j++) {
            if (fmod(diffMatrixMe[i][j],0.2) == 0 && fmod(diffMatrixMe[i][j],1.0) != 0)  {
                std::cerr << "[i][j] " << i << " " << j << " diffMatrixMe[i][j] = " << diffMatrixMe[i][j] << std::endl;
            }
        }
    }
    
    // print statistics
    print_matrix<const std::vector<std::vector<double> >&>(diffMatrix, *pDiffOutFile);
    pDiffMeOutFile->precision(10); print_matrix<const std::vector<std::vector<double> >&>(diffMatrixMe, *pDiffMeOutFile);
    print_matrix<const std::vector<std::vector<double> >&>(diffMatrixHetsVsHomDiff, *pHetHomOutFile);
    print_matrix<const std::vector<std::vector<int> >&>(pairwiseMissingness, *pPairMisOutFile);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r12
movl %edx, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
leaq 0x5830e(%rip), %rdx     # 0xa01da
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x28806
leaq 0x58308(%rip), %rdx     # 0xa01eb
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
callq 0x28806
leaq 0x58305(%rip), %rdx     # 0xa01ff
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x28806
leaq 0x58309(%rip), %rdx     # 0xa021a
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x28806
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %r13
movq 0xf8(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0x84e0
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %rbp
movq 0xd8(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0x84e0
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq 0xb8(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x84e0
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, 0x8(%rsp)
movq 0x98(%rsp), %rsi
pushq $0x10
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x84e0
leaq 0x580ad(%rip), %rsi     # 0xa005b
movq %r13, %rdi
callq 0x8480
movq %rax, %rdi
movq %r15, %rsi
callq 0x8430
leaq 0x622d8(%rip), %rsi     # 0xaa2a0
movq %rax, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x58253(%rip), %rsi     # 0xa0232
movq %r13, %rdi
callq 0x8480
movq %rax, %rdi
movl 0x20(%rsp), %esi
callq 0x8840
movq %rax, %rdi
callq 0x8230
leaq 0x5826c(%rip), %rsi     # 0xa026e
movq %r13, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x58042(%rip), %rsi     # 0xa005b
movq %rbp, %rdi
callq 0x8480
movq %rax, %rdi
movq %r15, %rsi
callq 0x8430
leaq 0x6226d(%rip), %rsi     # 0xaa2a0
movq %rax, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x5823f(%rip), %rsi     # 0xa0289
movq %rbp, %rdi
callq 0x8480
movq %rax, %rdi
movl 0x20(%rsp), %esi
callq 0x8840
movq %rax, %rdi
callq 0x8230
leaq 0x58259(%rip), %rsi     # 0xa02c6
movq %rbp, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x57fd7(%rip), %rsi     # 0xa005b
movq 0x18(%rsp), %rdi
callq 0x8480
movq %rax, %rdi
movq %r15, %rsi
callq 0x8430
leaq 0x62200(%rip), %rsi     # 0xaa2a0
movq %rax, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x58257(%rip), %rsi     # 0xa030e
movq 0x18(%rsp), %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x582c1(%rip), %rsi     # 0xa0391
movq 0x18(%rsp), %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x57f72(%rip), %rsi     # 0xa005b
movq 0x8(%rsp), %rdi
callq 0x8480
movq %rax, %rdi
movq %r15, %rsi
callq 0x8430
leaq 0x6219b(%rip), %rsi     # 0xaa2a0
movq %rax, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x5816d(%rip), %rsi     # 0xa0289
movq 0x8(%rsp), %rdi
callq 0x8480
movq %rax, %rdi
movl 0x20(%rsp), %esi
callq 0x8840
movq %rax, %rdi
callq 0x8230
leaq 0x582a9(%rip), %rsi     # 0xa03ea
movq 0x8(%rsp), %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x80(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x297dc
leaq 0x80(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0x1
popq %rcx
movq %r13, %rsi
callq 0x2ea24
leaq 0x80(%rsp), %rdi
callq 0x28a08
leaq 0x68(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x297dc
leaq 0x68(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0x1
popq %rcx
movq %rbp, %rsi
callq 0x2ea24
leaq 0x68(%rsp), %rdi
callq 0x28a08
leaq 0x50(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x297dc
leaq 0x50(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0x1
popq %rcx
movq 0x18(%rsp), %rsi
callq 0x2ea24
leaq 0x50(%rsp), %rdi
callq 0x28a08
leaq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x297dc
movq %rbp, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x38(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0x1
popq %rcx
movq 0x8(%rsp), %rsi
callq 0x2ea24
leaq 0x38(%rsp), %rdi
callq 0x28a08
movq (%r14), %rcx
movq 0x8(%r14), %rsi
xorl %r15d, %r15d
pushq $0x18
popq %rbp
leaq 0x581d2(%rip), %r13     # 0xa040a
movq %rsi, %rax
subq %rcx, %rax
cqto
idivq %rbp
cltq
cmpq %rax, %r15
jge 0x48333
imulq $0x18, %r15, %rbx
xorl %r12d, %r12d
movq %rsi, %rax
subq %rcx, %rax
cqto
idivq %rbp
cltq
cmpq %rax, %r12
jge 0x4832b
movq (%rcx,%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movsd 0x49e63(%rip), %xmm1    # 0x920e0
callq 0x85e0
ucomisd 0x4df0e(%rip), %xmm0    # 0x96198
jne 0x4831c
jp 0x4831c
movq (%r14), %rax
movq (%rax,%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movsd 0x4f345(%rip), %xmm1    # 0x975f0
callq 0x85e0
ucomisd 0x4dee0(%rip), %xmm0    # 0x96198
jne 0x482bc
jnp 0x4831c
movq 0x94d25(%rip), %rdi     # 0xdcfe8
leaq 0x58138(%rip), %rsi     # 0xa0402
callq 0x8480
movq %rax, %rdi
movl %r15d, %esi
callq 0x8840
movq %rax, %rdi
leaq 0x6a323(%rip), %rsi     # 0xb2607
callq 0x8480
movq %rax, %rdi
movl %r12d, %esi
callq 0x8840
movq %rax, %rdi
movq %r13, %rsi
callq 0x8480
movq (%r14), %rcx
movq (%rcx,%rbx), %rcx
movsd (%rcx,%r12,8), %xmm0
movq %rax, %rdi
callq 0x8750
movq %rax, %rdi
callq 0x8230
incq %r12
movq (%r14), %rcx
movq 0x8(%r14), %rsi
jmp 0x48255
incq %r15
jmp 0x48238
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x4892d
movq 0x10(%rsp), %rbx
movq 0x28(%rsp), %rsi
movq (%rsi), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x8(%rsi,%rax)
movq %r14, %rdi
callq 0x4892d
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x4892d
movq 0x150(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x489c6
leaq 0x98(%rsp), %rdi
callq 0x8978
leaq 0xb8(%rsp), %rdi
callq 0x8978
leaq 0xd8(%rsp), %rdi
callq 0x8978
leaq 0xf8(%rsp), %rdi
callq 0x8978
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x483f2
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x483f2
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x483f2
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x28a08
jmp 0x48450
movq %rax, %rbx
movl $0x200, %esi            # imm = 0x200
movq 0x8(%rsp), %rdi
jmp 0x48433
movq %rax, %rbx
movl $0x200, %esi            # imm = 0x200
movq 0x18(%rsp), %rdi
jmp 0x48433
jmp 0x4844d
movq %rax, %rbx
movl $0x200, %esi            # imm = 0x200
movq %rbp, %rdi
jmp 0x48433
jmp 0x4844d
movq %rax, %rbx
movl $0x200, %esi            # imm = 0x200
movq %r13, %rdi
callq 0x84a0
jmp 0x48450
jmp 0x4844d
movq %rax, %rbx
jmp 0x4845d
movq %rax, %rbx
jmp 0x4846a
movq %rax, %rbx
jmp 0x48477
jmp 0x4844d
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x8978
leaq 0xb8(%rsp), %rdi
callq 0x8978
leaq 0xd8(%rsp), %rdi
callq 0x8978
leaq 0xf8(%rsp), %rdi
callq 0x8978
movq %rbx, %rdi
callq 0x8870