// File: 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
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x10, -0x34(%rbp)
movq -0x8(%rbp), %rsi
leaq 0xaae4f(%rip), %rdx     # 0x13c307
leaq -0x58(%rbp), %rdi
callq 0x3da80
movq -0x8(%rbp), %rsi
leaq 0xaae4c(%rip), %rdx     # 0x13c318
leaq -0x78(%rbp), %rdi
callq 0x3da80
jmp 0x914d7
movq -0x8(%rbp), %rsi
leaq 0xaae4a(%rip), %rdx     # 0x13c32c
leaq -0xa8(%rbp), %rdi
callq 0x3da80
jmp 0x914f0
movq -0x8(%rbp), %rsi
leaq 0xaae4c(%rip), %rdx     # 0x13c347
leaq -0xc8(%rbp), %rdi
callq 0x3da80
jmp 0x91509
movl $0x200, %edi            # imm = 0x200
callq 0xa5d0
movq %rax, -0x158(%rbp)
jmp 0x9151c
leaq -0x58(%rbp), %rdi
callq 0xa220
movq -0x158(%rbp), %rdi
movq %rax, %rsi
movl -0x34(%rbp), %edx
callq 0xa650
jmp 0x91539
movq -0x158(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x200, %edi            # imm = 0x200
callq 0xa5d0
movq %rax, -0x160(%rbp)
jmp 0x9155a
leaq -0x78(%rbp), %rdi
callq 0xa220
movq -0x160(%rbp), %rdi
movq %rax, %rsi
movl -0x34(%rbp), %edx
callq 0xa650
jmp 0x91577
movq -0x160(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x200, %edi            # imm = 0x200
callq 0xa5d0
movq %rax, -0x168(%rbp)
jmp 0x91598
leaq -0xa8(%rbp), %rdi
callq 0xa220
movq -0x168(%rbp), %rdi
movq %rax, %rsi
movl -0x34(%rbp), %edx
callq 0xa650
jmp 0x915b8
movq -0x168(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl $0x200, %edi            # imm = 0x200
callq 0xa5d0
movq %rax, -0x170(%rbp)
jmp 0x915d9
leaq -0xc8(%rbp), %rdi
callq 0xa220
movq -0x170(%rbp), %rdi
movq %rax, %rsi
movl -0x34(%rbp), %edx
callq 0xa650
jmp 0x915f9
movq -0x170(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xd0(%rbp), %rdi
leaq 0xaab73(%rip), %rsi     # 0x13c188
callq 0xa5c0
movq %rax, -0x178(%rbp)
jmp 0x91623
movq -0x178(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa520
movq %rax, -0x180(%rbp)
jmp 0x9163c
movq -0x180(%rbp), %rdi
leaq 0xb51a6(%rip), %rsi     # 0x1467f0
callq 0xa5c0
movq %rax, -0x188(%rbp)
jmp 0x91658
movq -0x188(%rbp), %rdi
movq 0x107922(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9166d
movq -0xd0(%rbp), %rdi
leaq 0xaace4(%rip), %rsi     # 0x13c35f
callq 0xa5c0
movq %rax, -0x190(%rbp)
jmp 0x91689
movq -0x190(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xab20
movq %rax, -0x198(%rbp)
jmp 0x916a1
movq -0x198(%rbp), %rdi
movq 0x1078d9(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x916b6
movq -0xd0(%rbp), %rdi
leaq 0xaacd7(%rip), %rsi     # 0x13c39b
callq 0xa5c0
movq %rax, -0x1a0(%rbp)
jmp 0x916d2
movq -0x1a0(%rbp), %rdi
movq 0x1078a8(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x916e7
movq -0xd8(%rbp), %rdi
leaq 0xaaa93(%rip), %rsi     # 0x13c188
callq 0xa5c0
movq %rax, -0x1a8(%rbp)
jmp 0x91703
movq -0x1a8(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa520
movq %rax, -0x1b0(%rbp)
jmp 0x9171c
movq -0x1b0(%rbp), %rdi
leaq 0xb50c6(%rip), %rsi     # 0x1467f0
callq 0xa5c0
movq %rax, -0x1b8(%rbp)
jmp 0x91738
movq -0x1b8(%rbp), %rdi
movq 0x107842(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9174d
movq -0xd8(%rbp), %rdi
leaq 0xaac5b(%rip), %rsi     # 0x13c3b6
callq 0xa5c0
movq %rax, -0x1c0(%rbp)
jmp 0x91769
movq -0x1c0(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xab20
movq %rax, -0x1c8(%rbp)
jmp 0x91781
movq -0x1c8(%rbp), %rdi
movq 0x1077f9(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x91796
movq -0xd8(%rbp), %rdi
leaq 0xaac4f(%rip), %rsi     # 0x13c3f3
callq 0xa5c0
movq %rax, -0x1d0(%rbp)
jmp 0x917b2
movq -0x1d0(%rbp), %rdi
movq 0x1077c8(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x917c7
movq -0xe0(%rbp), %rdi
leaq 0xaa9b3(%rip), %rsi     # 0x13c188
callq 0xa5c0
movq %rax, -0x1d8(%rbp)
jmp 0x917e3
movq -0x1d8(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa520
movq %rax, -0x1e0(%rbp)
jmp 0x917fc
movq -0x1e0(%rbp), %rdi
leaq 0xb4fe6(%rip), %rsi     # 0x1467f0
callq 0xa5c0
movq %rax, -0x1e8(%rbp)
jmp 0x91818
movq -0x1e8(%rbp), %rdi
movq 0x107762(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9182d
movq -0xe0(%rbp), %rdi
leaq 0xaac00(%rip), %rsi     # 0x13c43b
callq 0xa5c0
movq %rax, -0x1f0(%rbp)
jmp 0x91849
movq -0x1f0(%rbp), %rdi
movq 0x107731(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9185e
movq -0xe0(%rbp), %rdi
leaq 0xaac52(%rip), %rsi     # 0x13c4be
callq 0xa5c0
movq %rax, -0x1f8(%rbp)
jmp 0x9187a
movq -0x1f8(%rbp), %rdi
movq 0x107700(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9188f
movq -0xe8(%rbp), %rdi
leaq 0xaa8eb(%rip), %rsi     # 0x13c188
callq 0xa5c0
movq %rax, -0x200(%rbp)
jmp 0x918ab
movq -0x200(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa520
movq %rax, -0x208(%rbp)
jmp 0x918c4
movq -0x208(%rbp), %rdi
leaq 0xb4f1e(%rip), %rsi     # 0x1467f0
callq 0xa5c0
movq %rax, -0x210(%rbp)
jmp 0x918e0
movq -0x210(%rbp), %rdi
movq 0x10769a(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x918f5
movq -0xe8(%rbp), %rdi
leaq 0xaaab3(%rip), %rsi     # 0x13c3b6
callq 0xa5c0
movq %rax, -0x218(%rbp)
jmp 0x91911
movq -0x218(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xab20
movq %rax, -0x220(%rbp)
jmp 0x91929
movq -0x220(%rbp), %rdi
movq 0x107651(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9193e
movq -0xe8(%rbp), %rdi
leaq 0xaabcb(%rip), %rsi     # 0x13c517
callq 0xa5c0
movq %rax, -0x228(%rbp)
jmp 0x9195a
movq -0x228(%rbp), %rdi
movq 0x107620(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x9196f
movq -0x10(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3fee0
jmp 0x91981
movq -0xd0(%rbp), %rsi
leaq -0x100(%rbp), %rdi
movl $0x9, %edx
movl $0x1, %ecx
callq 0x50da0
jmp 0x919a0
leaq -0x100(%rbp), %rdi
callq 0x3dfa0
movq -0x10(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x3fee0
jmp 0x919be
movq -0xd8(%rbp), %rsi
leaq -0x118(%rbp), %rdi
movl $0x9, %edx
movl $0x1, %ecx
callq 0x50da0
jmp 0x919dd
leaq -0x118(%rbp), %rdi
callq 0x3dfa0
movq -0x10(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x3fee0
jmp 0x919fb
movq -0xe0(%rbp), %rsi
leaq -0x130(%rbp), %rdi
movl $0x9, %edx
movl $0x1, %ecx
callq 0x50da0
jmp 0x91a1a
leaq -0x130(%rbp), %rdi
callq 0x3dfa0
movq -0x10(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x3fee0
jmp 0x91a38
movq -0xe8(%rbp), %rsi
leaq -0x148(%rbp), %rdi
movl $0x9, %edx
movl $0x1, %ecx
callq 0x50da0
jmp 0x91a57
leaq -0x148(%rbp), %rdi
callq 0x3dfa0
movl $0x0, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
movl %eax, -0x22c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x651b0
movq %rax, %rcx
movl -0x22c(%rbp), %eax
cmpl %ecx, %eax
jge 0x91db2
movl $0x0, -0x150(%rbp)
movl -0x150(%rbp), %eax
movl %eax, -0x230(%rbp)
movq -0x28(%rbp), %rdi
callq 0x651b0
movq %rax, %rcx
movl -0x230(%rbp), %eax
cmpl %ecx, %eax
jge 0x91d9c
movq -0x28(%rbp), %rdi
movslq -0x14c(%rbp), %rsi
callq 0x92690
movq %rax, %rdi
movslq -0x150(%rbp), %rsi
callq 0x84300
movsd (%rax), %xmm0
movsd 0x9c5fa(%rip), %xmm1    # 0x12e0e8
callq 0xa7f0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x91d86
jp 0x91d86
movq -0x28(%rbp), %rdi
movslq -0x14c(%rbp), %rsi
callq 0x92690
movq %rax, %rdi
movslq -0x150(%rbp), %rsi
callq 0x84300
movsd (%rax), %xmm0
movsd 0xa0787(%rip), %xmm1    # 0x1322b8
callq 0xa7f0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x91b46
jp 0x91b46
jmp 0x91d86
movq 0x1074a3(%rip), %rdi    # 0x198ff0
leaq 0xaa9db(%rip), %rsi     # 0x13c52f
callq 0xa5c0
movq %rax, -0x238(%rbp)
jmp 0x91b62
movq -0x238(%rbp), %rdi
movl -0x14c(%rbp), %esi
callq 0xab20
movq %rax, -0x240(%rbp)
jmp 0x91b7d
movq -0x240(%rbp), %rdi
leaq 0xbd2b7(%rip), %rsi     # 0x14ee42
callq 0xa5c0
movq %rax, -0x248(%rbp)
jmp 0x91b99
movq -0x248(%rbp), %rdi
movl -0x150(%rbp), %esi
callq 0xab20
movq %rax, -0x250(%rbp)
jmp 0x91bb4
movq -0x250(%rbp), %rdi
leaq 0xaa975(%rip), %rsi     # 0x13c537
callq 0xa5c0
movq %rax, -0x258(%rbp)
jmp 0x91bd0
movq -0x28(%rbp), %rdi
movslq -0x14c(%rbp), %rsi
callq 0x92690
movq %rax, %rdi
movslq -0x150(%rbp), %rsi
callq 0x84300
movq -0x258(%rbp), %rdi
movsd (%rax), %xmm0
callq 0xabd0
movq %rax, -0x260(%rbp)
jmp 0x91c08
movq -0x260(%rbp), %rdi
movq 0x107372(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x91c1d
jmp 0x91d86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x91e6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x91e62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x91e56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x91e4a
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
movl $0x200, %esi            # imm = 0x200
callq 0xa5e0
jmp 0x91e4a
movq -0x160(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
movl $0x200, %esi            # imm = 0x200
callq 0xa5e0
jmp 0x91e4a
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
movl $0x200, %esi            # imm = 0x200
callq 0xa5e0
jmp 0x91e4a
movq -0x170(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
movl $0x200, %esi            # imm = 0x200
callq 0xa5e0
jmp 0x91e4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x3dfa0
jmp 0x91e4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x3dfa0
jmp 0x91e4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3dfa0
jmp 0x91e4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3dfa0
jmp 0x91e4a
jmp 0x91d88
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x91a9d
jmp 0x91d9e
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x91a6d
movq -0x20(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x926b0
jmp 0x91dc4
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x927f0
jmp 0x91de1
movq -0x28(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x926b0
jmp 0x91df3
movq -0x30(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x926b0
jmp 0x91e05
movq 0x10(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0x92820
jmp 0x91e17
leaq -0xc8(%rbp), %rdi
callq 0xac88
leaq -0xa8(%rbp), %rdi
callq 0xac88
leaq -0x78(%rbp), %rdi
callq 0xac88
leaq -0x58(%rbp), %rdi
callq 0xac88
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0xac88
leaq -0xa8(%rbp), %rdi
callq 0xac88
leaq -0x78(%rbp), %rdi
callq 0xac88
leaq -0x58(%rbp), %rdi
callq 0xac88
movq -0x80(%rbp), %rdi
callq 0xab50
nopl (%rax)