// File: millanek[P]evo/process_vcf_merge.cpp
// Function: mergeMain(int, char**)
int mergeMain(int argc, char** argv) {
    parseMergeOptions(argc, argv);
    
    std::cerr << "Merging: " << opt::VCF1File << " and " << opt::VCF2File << std::endl;
    std::cerr << "writing output to:" << opt::out << std::endl;
    
    // Open connection to read from the vcf files
    std::ifstream* pVCF1 = new std::ifstream(opt::VCF1File.c_str());
    std::ifstream* pVCF2 = new std::ifstream(opt::VCF2File.c_str());
    std::ofstream* pOut = new std::ofstream(opt::out.c_str());
    
    
    string line1; string line2;
    while (getline(*pVCF1, line1)) {
        if (line1[1] != '#') break;
        *pOut << line1 << std::endl;
    }
    while (getline(*pVCF2, line2)) {
        if (line2[1] != '#') break;
    }
    
    // Print the sample names
    std::vector<std::string> fields2 = split(line2, '\t');
    std::vector<std::string> genotypes(fields2.begin()+9,fields2.end());
    *pOut << line1 << "\t"; print_vector(genotypes, *pOut);
    
    // Print the variant details
    while (getline(*pVCF1, line1)) {
        getline(*pVCF2, line2);
        fields2 = split(line2, '\t');
        std::vector<std::string> genotypes(fields2.begin()+9,fields2.end());
        if (opt::bGTonly) {
            for (std::vector<std::string>::size_type i = 0; i != genotypes.size(); i++) {
                std::vector<std::string> gtFields = split(genotypes[i], ':');
                genotypes[i] = gtFields[0];
            }
        }
        *pOut << line1 << "\t"; print_vector(genotypes, *pOut);
    }
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0xe7560
movq 0xb220b(%rip), %rdi     # 0x198ff0
movq %rdi, -0x190(%rbp)
leaq 0x621bb(%rip), %rsi     # 0x148fae
callq 0xa5c0
movq %rax, %rdi
leaq 0xb41d6(%rip), %rsi     # 0x19afd8
movq %rsi, -0x180(%rbp)
callq 0xa520
movq %rax, %rdi
leaq 0x621a0(%rip), %rsi     # 0x148fb8
callq 0xa5c0
movq %rax, %rdi
leaq 0xb41d1(%rip), %rsi     # 0x19aff8
callq 0xa520
movq %rax, %rdi
movq 0xb2152(%rip), %rsi     # 0x198f88
movq %rsi, -0x188(%rbp)
callq 0xa610
movq -0x190(%rbp), %rdi
leaq 0x6216e(%rip), %rsi     # 0x148fbe
callq 0xa5c0
movq %rax, %rdi
leaq 0xb41b9(%rip), %rsi     # 0x19b018
callq 0xa520
movq -0x188(%rbp), %rsi
movq %rax, %rdi
callq 0xa610
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq -0x180(%rbp), %rdi
movq %rax, -0x170(%rbp)
movq %rax, -0x178(%rbp)
callq 0xa220
movq -0x170(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0xe6ead
movq -0x178(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0x198(%rbp)
movq %rax, -0x1a0(%rbp)
leaq 0xb4121(%rip), %rdi     # 0x19aff8
callq 0xa220
movq -0x198(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0xe6ef2
movq -0x1a0(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x200, %edi            # imm = 0x200
callq 0xa5d0
movq %rax, -0x1a8(%rbp)
movq %rax, -0x1b0(%rbp)
leaq 0xb40fc(%rip), %rdi     # 0x19b018
callq 0xa220
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
movl $0x10, %edx
callq 0xa650
jmp 0xe6f37
movq -0x1b0(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xa820
leaq -0x78(%rbp), %rdi
callq 0xa820
movq -0x18(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x1b8(%rbp)
jmp 0xe6f6a
movq -0x1b8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x1b9(%rbp)
jmp 0xe6f88
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0xe6f97
jmp 0xe7069
leaq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0xac60
movq %rax, -0x1c8(%rbp)
jmp 0xe6fae
movq -0x1c8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0xe7039
jmp 0xe7069
movq -0x178(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0xe7553
movq -0x1a0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0xe7553
movq -0x1b0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x200, %esi            # imm = 0x200
callq 0xa5e0
jmp 0xe7553
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xe7541
movq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xa520
movq %rax, -0x1d0(%rbp)
jmp 0xe704f
movq -0x1d0(%rbp), %rdi
movq 0xb1f2b(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xe7064
jmp 0xe6f54
jmp 0xe706b
movq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x1d8(%rbp)
jmp 0xe7081
movq -0x1d8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x1d9(%rbp)
jmp 0xe709f
movb -0x1d9(%rbp), %al
testb $0x1, %al
jne 0xe70ab
jmp 0xe70d5
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0xac60
movq %rax, -0x1e8(%rbp)
jmp 0xe70c2
movq -0x1e8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0xe70d3
jmp 0xe70d5
jmp 0xe706b
leaq -0x90(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0xe70ec
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x44030
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
movl $0x9, %esi
callq 0x44390
movq -0x1f8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x44060
movq %rax, -0xc0(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x48e80
movq -0x1f0(%rbp), %rcx
movq -0xb0(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0xc6600
jmp 0xe7167
leaq -0xc1(%rbp), %rdi
callq 0x40090
movq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xa520
movq %rax, -0x200(%rbp)
jmp 0xe7189
movq -0x200(%rbp), %rdi
leaq 0x4ed47(%rip), %rsi     # 0x135ede
callq 0xa5c0
jmp 0xe719e
leaq -0xe0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3fee0
jmp 0xe71b3
movq -0x38(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
movl $0x9, %edx
movl $0x1, %ecx
callq 0x50da0
jmp 0xe71cf
leaq -0xe0(%rbp), %rdi
callq 0x3dfa0
movq -0x18(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x208(%rbp)
jmp 0xe71f1
movq -0x208(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x209(%rbp)
jmp 0xe720f
movb -0x209(%rbp), %al
testb $0x1, %al
jne 0xe721e
jmp 0xe74f4
movq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xa0d0
jmp 0xe722d
leaq -0xf8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0xe7244
leaq -0x90(%rbp), %rdi
movq %rdi, -0x220(%rbp)
leaq -0xf8(%rbp), %rsi
movq %rsi, -0x228(%rbp)
callq 0x50c30
movq -0x228(%rbp), %rdi
callq 0x3dfa0
movq -0x220(%rbp), %rdi
callq 0x44030
movq %rax, -0x120(%rbp)
leaq -0x120(%rbp), %rdi
movl $0x9, %esi
callq 0x44390
movq -0x220(%rbp), %rdi
movq %rax, -0x118(%rbp)
callq 0x44060
movq %rax, -0x128(%rbp)
leaq -0x129(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x48e80
movq -0x218(%rbp), %rcx
movq -0x118(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0xc6600
jmp 0xe72e5
leaq -0x129(%rbp), %rdi
callq 0x40090
testb $0x1, 0xb3d40(%rip)     # 0x19b038
je 0xe7455
movq $0x0, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3ffd0
movq %rax, %rcx
movq -0x230(%rbp), %rax
cmpq %rcx, %rax
je 0xe7453
movq -0x138(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
movl $0x3a, %edx
callq 0x7bbe0
jmp 0xe735f
xorl %eax, %eax
movl %eax, %esi
leaq -0x150(%rbp), %rdi
callq 0x3d940
movq %rax, -0x238(%rbp)
movq -0x138(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x3d940
movq -0x238(%rbp), %rsi
movq %rax, %rdi
callq 0xa060
jmp 0xe739a
leaq -0x150(%rbp), %rdi
callq 0x3dfa0
movq -0x138(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x138(%rbp)
jmp 0xe7309
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x40090
jmp 0xe7535
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xe7529
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x3dfa0
jmp 0xe7529
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x129(%rbp), %rdi
callq 0x40090
jmp 0xe7529
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xe74e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3dfa0
jmp 0xe74e6
jmp 0xe7455
movq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xa520
movq %rax, -0x240(%rbp)
jmp 0xe746b
movq -0x240(%rbp), %rdi
leaq 0x4ea65(%rip), %rsi     # 0x135ede
callq 0xa5c0
jmp 0xe7480
leaq -0x168(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3fee0
jmp 0xe7495
movq -0x38(%rbp), %rsi
leaq -0x168(%rbp), %rdi
movl $0x9, %edx
movl $0x1, %ecx
callq 0x50da0
jmp 0xe74b1
leaq -0x168(%rbp), %rdi
callq 0x3dfa0
leaq -0x110(%rbp), %rdi
callq 0x3dfa0
jmp 0xe71db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x3dfa0
leaq -0x110(%rbp), %rdi
callq 0x3dfa0
jmp 0xe7529
leaq -0xa8(%rbp), %rdi
callq 0x3dfa0
leaq -0x90(%rbp), %rdi
callq 0x3dfa0
leaq -0x78(%rbp), %rdi
callq 0xac88
leaq -0x58(%rbp), %rdi
callq 0xac88
xorl %eax, %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
leaq -0xa8(%rbp), %rdi
callq 0x3dfa0
leaq -0x90(%rbp), %rdi
callq 0x3dfa0
leaq -0x78(%rbp), %rdi
callq 0xac88
leaq -0x58(%rbp), %rdi
callq 0xac88
movq -0x20(%rbp), %rdi
callq 0xab50
nopl (%rax)