// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/process_vcf_reorder.cpp
// Function: reorderMain(int, char**)
int reorderMain(int argc, char** argv) {
    parseReorderOptions(argc, argv);
    string fileRoot = stripExtension(opt::vcfFile);
    
    std::cerr << "Reordering columns in: " << opt::vcfFile << std::endl;
    std::cerr << "using ordering in: " << opt::newOrderFile << std::endl;
    
    // Open connection to read from the vcf file
    std::istream* vcfFile = createReader(opt::vcfFile.c_str());
    string reorderedFileName = fileRoot + opt::runName + "_reordered.vcf";
    std::ofstream* pReordered = new std::ofstream(reorderedFileName.c_str());
    
    int numChromosomes;
    int totalVariantNumber = 0;
    string line;
    std::vector<string> sampleNames;
    std::vector<string> newOrder = readSampleNamesFromTextFile(opt::newOrderFile);
    std::vector<string> fields;
    std::map<string, size_t> link;
    while (getline(*vcfFile, line)) {
        if (line[0] == '#' && line[1] == '#') {
            *pReordered << line << std::endl;
        } else if (line[0] == '#' && line[1] == 'C') {
            std::vector<std::string> fields = split(line, '\t');
            const std::vector<std::string>::size_type numSamples = fields.size() - NUM_NON_GENOTYPE_COLUMNS;
            numChromosomes = (int)numSamples * 2;
            // std::cerr << "Number of chromosomes: " << numChromosomes << std::endl;
            if (opt::sampleNameFile.empty()) {
                for (std::vector<std::string>::size_type i = NUM_NON_GENOTYPE_COLUMNS; i != fields.size(); i++) {
                    sampleNames.push_back(fields[i]);
                }
            } else {
                sampleNames = readSampleNamesFromTextFile(opt::sampleNameFile);
            }
            assert(sampleNames.size() == newOrder.size());
            link = linkVectors(newOrder, sampleNames);
            for (std::vector<std::string>::size_type i = 0; i != NUM_NON_GENOTYPE_COLUMNS; i++) {
                *pReordered << fields[i] << "\t";
            }
            
            for (std::vector<std::string>::size_type i = 0; i != sampleNames.size() - 1; i++) {
                *pReordered << newOrder[i] << "\t";
            } *pReordered << newOrder[newOrder.size()-1] << std::endl;
        } else {
            totalVariantNumber++;
            
            std::vector<std::string> fields = split(line, '\t');
            for (std::vector<std::string>::size_type i = 0; i != NUM_NON_GENOTYPE_COLUMNS; i++) {
                *pReordered << fields[i] << "\t";
            }
            
            for (std::vector<std::string>::size_type i = 0; i != sampleNames.size() - 1; i++) {
                *pReordered << fields[link[sampleNames[i]]+NUM_NON_GENOTYPE_COLUMNS] << "\t";
            } *pReordered << fields[link[sampleNames[sampleNames.size()-1]]+NUM_NON_GENOTYPE_COLUMNS] << std::endl;
 
            
        }
    }
    
    
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
callq 0x8986a
leaq 0x7a8ea(%rip), %rsi     # 0x1038b0
leaq 0x110(%rsp), %rdi
callq 0x4d82f
movq 0x7900e(%rip), %rdi     # 0x101fe8
leaq 0x51599(%rip), %rsi     # 0xda57a
movl $0x17, %edx
callq 0x84e0
movq 0x7a8be(%rip), %rsi     # 0x1038b0
movq 0x7a8bf(%rip), %rdx     # 0x1038b8
movq 0x78fe8(%rip), %rdi     # 0x101fe8
callq 0x84e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x78fb2(%rip), %rdi     # 0x101fe8
leaq 0x51555(%rip), %rsi     # 0xda592
movl $0x13, %edx
callq 0x84e0
movq 0x7a882(%rip), %rsi     # 0x1038d0
movq 0x7a883(%rip), %rdx     # 0x1038d8
movq 0x78f8c(%rip), %rdi     # 0x101fe8
callq 0x84e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x7a81e(%rip), %rsi     # 0x1038b0
leaq 0x50(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x287de
leaq 0x50(%rsp), %rdi
movl $0x8, %esi
callq 0x500af
movq %rax, %rbx
leaq 0x60(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x890ce
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x7a83b(%rip), %rdx     # 0x103910
leaq 0x50(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x2e8c4
leaq 0x514b8(%rip), %rsi     # 0xda5a6
leaq 0x50(%rsp), %rdi
callq 0x88c0
leaq 0xb0(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x89128
movq %rdx, 0xa0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb0(%rsp)
jmp 0x8912e
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0xa8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0x89160
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x8480
movl $0x200, %edi            # imm = 0x200
callq 0x8470
movq %rax, %r14
movq 0xa0(%rsp), %rsi
movq %rax, %rdi
movl $0x10, %edx
callq 0x84c0
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
leaq 0x7a726(%rip), %rsi     # 0x1038d0
leaq 0xd8(%rsp), %rdi
callq 0x4fe41
xorps %xmm0, %xmm0
movaps %xmm0, 0x130(%rsp)
xorl %eax, %eax
movq %rax, 0x140(%rsp)
leaq 0x58(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x80(%rsp), %r15
leaq 0x50(%rsp), %rbp
leaq 0x447cf(%rip), %r13     # 0xcd9ca
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x89661
movq 0x80(%rsp), %rsi
cmpb $0x23, (%rsi)
jne 0x8928d
movzbl 0x1(%rsi), %eax
cmpl $0x43, %eax
je 0x893d2
cmpl $0x23, %eax
jne 0x8928d
movq 0x88(%rsp), %rdx
movq %r14, %rdi
callq 0x84e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
jmp 0x891fb
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl $0x9, %edx
callq 0x4d650
movl $0x8, %r15d
movq 0x20(%rsp), %rax
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %r14, %rdi
callq 0x84e0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x84e0
addq $0x20, %r15
cmpq $0x128, %r15            # imm = 0x128
jne 0x892a5
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
cmpq $0x20, %rax
jne 0x892ef
xorl %r12d, %r12d
jmp 0x8935b
movq $-0x1, %r12
xorl %r15d, %r15d
addq %r15, %rsi
movq %rbp, %rdi
callq 0x89b1c
movq (%rax), %rax
movq 0x20(%rsp), %rcx
shlq $0x5, %rax
movq 0x120(%rcx,%rax), %rsi
movq 0x128(%rcx,%rax), %rdx
movq %r14, %rdi
callq 0x84e0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x84e0
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $-0x2, %rax
incq %r12
addq $0x20, %r15
cmpq %rax, %r12
jne 0x892f9
incq %r12
shlq $0x5, %r12
addq %rsi, %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x89b1c
leaq 0x80(%rsp), %r15
movq (%rax), %rax
movq 0x20(%rsp), %rcx
shlq $0x5, %rax
movq 0x120(%rcx,%rax), %rsi
movq 0x128(%rcx,%rax), %rdx
movq %r14, %rdi
callq 0x84e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
leaq 0x20(%rsp), %rdi
callq 0x2e784
jmp 0x891fb
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
movl $0x9, %edx
callq 0x4d650
cmpq $0x0, 0x7a509(%rip)     # 0x1038f8
je 0x8945f
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
leaq 0x7a4ed(%rip), %rsi     # 0x1038f0
callq 0x4fe41
movq 0x10(%rsp), %rax
movaps 0xf0(%rsp), %xmm0
movq 0x100(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movaps (%rsp), %xmm1
movaps %xmm0, (%rsp)
movaps %xmm1, 0x20(%rsp)
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xf0(%rsp)
movq $0x0, 0x100(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x2e784
movq %r15, %rdi
callq 0x2e784
jmp 0x894b4
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rax
subq %rsi, %rax
cmpq $0x120, %rax            # imm = 0x120
je 0x894b4
movl $0x9, %r15d
movl $0x120, %r12d           # imm = 0x120
addq %r12, %rsi
movq %rsp, %rdi
callq 0x3133c
incq %r15
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r12
cmpq %rax, %r15
jne 0x89486
movq 0x8(%rsp), %rax
subq (%rsp), %rax
movq 0xe0(%rsp), %rcx
subq 0xd8(%rsp), %rcx
cmpq %rcx, %rax
jne 0x8970c
leaq 0x150(%rsp), %r15
movq %r15, %rdi
movq %rsp, %rsi
callq 0x2fc8e
leaq 0x20(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
movq %r15, %rdx
callq 0x88e84
movq %rbp, %rdi
callq 0x89c10
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x89555
movl 0x28(%rsp), %ecx
movl %ecx, 0x58(%rsp)
movq %rax, 0x60(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x68(%rsp)
leaq 0x58(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x48(%rsp), %rax
movq %rax, 0x78(%rsp)
xorl %eax, %eax
movq %rax, 0x30(%rsp)
leaq 0x28(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x89b98
movq %r15, %rdi
callq 0x2e784
movl $0x8, %r15d
movq 0xc0(%rsp), %rax
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %r14, %rdi
callq 0x84e0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x84e0
addq $0x20, %r15
cmpq $0x128, %r15            # imm = 0x128
jne 0x8956d
movq 0x8(%rsp), %rax
subq (%rsp), %rax
cmpq $0x20, %rax
je 0x89605
movq $-0x1, %r15
movl $0x8, %r12d
movq 0xd8(%rsp), %rax
movq -0x8(%rax,%r12), %rsi
movq (%rax,%r12), %rdx
movq %r14, %rdi
callq 0x84e0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x84e0
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x5, %rax
addq $-0x2, %rax
incq %r15
addq $0x20, %r12
cmpq %rax, %r15
jne 0x895bf
movq 0xe0(%rsp), %rax
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %r14, %rdi
callq 0x84e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
leaq 0xc0(%rsp), %rdi
callq 0x2e784
leaq 0x80(%rsp), %r15
jmp 0x891fb
leaq 0x50(%rsp), %rdi
callq 0x89b98
leaq 0x130(%rsp), %rdi
callq 0x2e784
leaq 0xd8(%rsp), %rdi
callq 0x2e784
movq %rsp, %rdi
callq 0x2e784
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x896b2
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x896d7
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x896f8
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x8480
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50ea2(%rip), %rdi     # 0xda5b5
leaq 0x50ec1(%rip), %rsi     # 0xda5db
leaq 0x50ed2(%rip), %rcx     # 0xda5f3
movl $0x5f, %edx
callq 0x82c0
movq %rax, %rbx
jmp 0x897ef
movq %rax, %rbx
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
jmp 0x89817
movq %rax, %rbx
jmp 0x8981c
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
jne 0x89774
jmp 0x89841
jmp 0x89798
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x89841
movq 0x60(%rsp), %rsi
jmp 0x89839
jmp 0x89798
jmp 0x897af
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x2e784
jmp 0x897b2
jmp 0x897a6
jmp 0x897af
movq %rax, %rbx
jmp 0x89841
jmp 0x897af
jmp 0x897a6
jmp 0x897af
movq %rax, %rbx
jmp 0x897cb
jmp 0x897be
jmp 0x897af
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x897c6
jmp 0x897be
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2e784
leaq 0x50(%rsp), %rdi
callq 0x89b98
leaq 0x130(%rsp), %rdi
callq 0x2e784
leaq 0xd8(%rsp), %rdi
callq 0x2e784
movq %rsp, %rdi
callq 0x2e784
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x8981c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x89841
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x89862
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x8480
movq %rbx, %rdi
callq 0x8840