// File: millanek[P]evo/process_vcf_use_map.cpp
// Function: processGenome(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<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>>>>, std::allocator<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>>>>>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<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>>>>, std::allocator<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&)
void processGenome(const std::map<string, std::vector<std::vector<string> > >& LGmap) {
    
    std::cerr << "Joining genomic scaffolds from: " << opt::inputFile << std::endl;
    std::cerr << "using linkage groups defined in: " << opt::LGfile << std::endl;
    
    string line;
    std::vector<string> currentScaffoldNum;
    string nextScaffoldNum;
    string currentScaffoldString;
    std::map<std::string, std::string> scaffoldStrings;
    std::ifstream* genomeFile = new std::ifstream(opt::inputFile.c_str());
    
    getline(*genomeFile, line);
    currentScaffoldNum = split(line, '_');
    int i = 0;
    while (currentScaffoldString != "") {
        i++;
        currentScaffoldString = readScaffold(genomeFile, nextScaffoldNum);
        if (i % 10 == 0)
            std::cerr << "scaffold " << i << " read" << std::endl;
        /*if (i == 118) {
            std::cerr << "scaffold " << i << " read; length: " << currentScaffoldString.length() << std::endl;
            std::cerr << "currentScaffoldNum[1]: " << currentScaffoldNum[1] << std::endl;
        } */
        scaffoldStrings[currentScaffoldNum[1]] = currentScaffoldString;
        currentScaffoldNum = split(nextScaffoldNum,'_');
    }
    scaffoldStrings[currentScaffoldNum[1]] = currentScaffoldString;
    std::cerr << "scaffold " << currentScaffoldNum[1] << " read" << std::endl;
    
    // std::cerr << "Hello?? " << std::endl;
    std::vector<string> scaffoldsInLinkageGroups;
    string LGString; LGString.reserve(100000000);
    for(std::map<string, std::vector<std::vector<string> > >::const_iterator it = LGmap.begin(); it != LGmap.end(); ++it) {
        LGString = "";
        std::cerr << "Building " << it->first << std::endl;
        for (std::vector<std::vector<string> >::size_type i = 0; i != it->second.size(); i++) {
            std::cerr << "Adding " << it->second[i][0] << " length: " << scaffoldStrings[it->second[i][0]].length() << "(" << it->second[i][2] << ")" << std::endl;
            if (it->second[i][1] == "+") {
                LGString.append(scaffoldStrings[it->second[i][0]]);
            } else if (it->second[i][1] == "-") {
                LGString.append(reverseComplementIUPAC(scaffoldStrings[it->second[i][0]]));
            }
            scaffoldsInLinkageGroups.push_back(it->second[i][0]);
        }
        std::cout << ">" << it->first << std::endl;
        print80bpPerLineStdOut(std::cout, LGString);
    }
    // Print remaining scaffolds (the ones that are not in linkage groups
    for(std::map<std::string, std::string>::iterator it = scaffoldStrings.begin(); it != scaffoldStrings.end(); ++it) {
        if (std::find(scaffoldsInLinkageGroups.begin(), scaffoldsInLinkageGroups.end(), it->first) ==  scaffoldsInLinkageGroups.end()) {
            std::cout << ">scaffold_" << it->first << std::endl;
            print80bpPerLineStdOut(std::cout, it->second);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x8(%rbp)
movq 0xd60aa(%rip), %rdi     # 0x198ff0
movq %rdi, -0x218(%rbp)
leaq 0x7f8bc(%rip), %rsi     # 0x142810
callq 0xa5c0
movq %rax, %rdi
leaq 0xd7c45(%rip), %rsi     # 0x19aba8
callq 0xa520
movq %rax, %rdi
movq 0xd6016(%rip), %rsi     # 0x198f88
movq %rsi, -0x210(%rbp)
callq 0xa610
movq -0x218(%rbp), %rdi
leaq 0x7f862(%rip), %rsi     # 0x1427ee
callq 0xa5c0
movq %rax, %rdi
leaq 0xd7c2d(%rip), %rsi     # 0x19abc8
callq 0xa520
movq -0x210(%rbp), %rsi
movq %rax, %rdi
callq 0xa610
leaq -0x28(%rbp), %rdi
callq 0xa820
leaq -0x40(%rbp), %rdi
callq 0x48da0
leaq -0x60(%rbp), %rdi
callq 0xa820
leaq -0x80(%rbp), %rdi
callq 0xa820
leaq -0xb0(%rbp), %rdi
callq 0x584b0
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0x208(%rbp)
jmp 0xc2ff2
leaq 0xd7baf(%rip), %rdi     # 0x19aba8
callq 0xa220
movq -0x208(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0xc3014
movq -0x208(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xa0d0
jmp 0xc3034
leaq -0xe0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x5f, %edx
callq 0x7bbe0
jmp 0xc304b
leaq -0x40(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x50c30
leaq -0xe0(%rbp), %rdi
callq 0x3dfa0
movl $0x0, -0xe4(%rbp)
leaq 0x72e67(%rip), %rsi     # 0x135edf
leaq -0x80(%rbp), %rdi
callq 0x50eb0
movb %al, -0x219(%rbp)
jmp 0xc3089
movb -0x219(%rbp), %al
testb $0x1, %al
jne 0xc3098
jmp 0xc320b
movl -0xe4(%rbp), %eax
incl %eax
movl %eax, -0xe4(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x6a7e0
jmp 0xc30bf
leaq -0x80(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0xa710
leaq -0x108(%rbp), %rdi
callq 0xac88
movl -0xe4(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0xc319b
movq 0xd5ef7(%rip), %rdi     # 0x198ff0
leaq 0x8a5ba(%rip), %rsi     # 0x14d6ba
callq 0xa5c0
movq %rax, -0x228(%rbp)
jmp 0xc310e
movq -0x228(%rbp), %rdi
movl -0xe4(%rbp), %esi
callq 0xab20
movq %rax, -0x230(%rbp)
jmp 0xc3129
movq -0x230(%rbp), %rdi
leaq 0x7f6fa(%rip), %rsi     # 0x142831
callq 0xa5c0
movq %rax, -0x238(%rbp)
jmp 0xc3145
movq -0x238(%rbp), %rdi
movq 0xd5e35(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc315a
jmp 0xc319b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xc3a1a
movq -0x208(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0xc3a1a
leaq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x584d0
movq %rax, -0x240(%rbp)
jmp 0xc31c1
movq -0x240(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xa060
jmp 0xc31d3
leaq -0x120(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x5f, %edx
callq 0x7bbe0
jmp 0xc31ea
leaq -0x40(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x50c30
leaq -0x120(%rbp), %rdi
callq 0x3dfa0
jmp 0xc3071
leaq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x584d0
movq %rax, -0x248(%rbp)
jmp 0xc3231
movq -0x248(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xa060
jmp 0xc3243
movq 0xd5da6(%rip), %rdi     # 0x198ff0
leaq 0x8a469(%rip), %rsi     # 0x14d6ba
callq 0xa5c0
movq %rax, -0x250(%rbp)
jmp 0xc325f
leaq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq -0x250(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
movq %rax, -0x258(%rbp)
jmp 0xc3285
movq -0x258(%rbp), %rdi
leaq 0x7f59e(%rip), %rsi     # 0x142831
callq 0xa5c0
movq %rax, -0x260(%rbp)
jmp 0xc32a1
movq -0x260(%rbp), %rdi
movq 0xd5cd9(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc32b6
leaq -0x138(%rbp), %rdi
callq 0x48da0
leaq -0x158(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0xa820
movq -0x268(%rbp), %rdi
movl $0x5f5e100, %esi        # imm = 0x5F5E100
callq 0xa980
jmp 0xc32e8
movq -0x8(%rbp), %rdi
callq 0xc3d90
movq %rax, -0x160(%rbp)
movq -0x8(%rbp), %rdi
callq 0xc3dc0
movq %rax, -0x168(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x59490
testb $0x1, %al
jne 0xc3324
jmp 0xc380e
leaq 0x72bb4(%rip), %rsi     # 0x135edf
leaq -0x158(%rbp), %rdi
callq 0xa810
jmp 0xc3339
movq 0xd5cb0(%rip), %rdi     # 0x198ff0
leaq 0x7f4f0(%rip), %rsi     # 0x142837
callq 0xa5c0
movq %rax, -0x270(%rbp)
jmp 0xc3355
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq -0x270(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
movq %rax, -0x278(%rbp)
jmp 0xc3379
movq -0x278(%rbp), %rdi
movq 0xd5c01(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc338e
movq $0x0, -0x170(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x280(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x409f0
movq %rax, %rcx
movq -0x280(%rbp), %rax
cmpq %rcx, %rax
je 0xc374f
movq 0xd5c17(%rip), %rdi     # 0x198ff0
leaq 0x7f461(%rip), %rsi     # 0x142841
callq 0xa5c0
movq %rax, -0x288(%rbp)
jmp 0xc33ee
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52960
movq -0x288(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
movq %rax, -0x290(%rbp)
jmp 0xc3431
movq -0x290(%rbp), %rdi
leaq 0x7c65f(%rip), %rsi     # 0x13fa9e
callq 0xa5c0
movq %rax, -0x298(%rbp)
jmp 0xc344d
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52960
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x584d0
movq %rax, -0x2a0(%rbp)
jmp 0xc3490
movq -0x2a0(%rbp), %rdi
callq 0xa930
movq -0x298(%rbp), %rdi
movq %rax, %rsi
callq 0xa140
movq %rax, -0x2a8(%rbp)
jmp 0xc34b4
movq -0x2a8(%rbp), %rdi
leaq 0x7a7ae(%rip), %rsi     # 0x13dc70
callq 0xa5c0
movq %rax, -0x2b0(%rbp)
jmp 0xc34d0
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x2, %esi
callq 0x52960
movq -0x2b0(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
movq %rax, -0x2b8(%rbp)
jmp 0xc3514
movq -0x2b8(%rbp), %rdi
leaq 0x7dc06(%rip), %rsi     # 0x141128
callq 0xa5c0
movq %rax, -0x2c0(%rbp)
jmp 0xc3530
movq -0x2c0(%rbp), %rdi
movq 0xd5a4a(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc3545
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x1, %esi
callq 0x52960
movq %rax, %rdi
leaq 0x71588(%rip), %rsi     # 0x134b03
callq 0x2d770
movb %al, -0x2c1(%rbp)
jmp 0xc3588
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0xc3594
jmp 0xc3608
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52960
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x584d0
movq %rax, -0x2d0(%rbp)
jmp 0xc35d7
movq -0x2d0(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac20
jmp 0xc35ec
jmp 0xc36fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xc3a02
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x1, %esi
callq 0x52960
movq %rax, %rdi
leaq 0x714d2(%rip), %rsi     # 0x134b10
callq 0x2d770
movb %al, -0x2d1(%rbp)
jmp 0xc364b
movb -0x2d1(%rbp), %al
testb $0x1, %al
jne 0xc365a
jmp 0xc36f8
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52960
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x584d0
movq %rax, -0x2e0(%rbp)
jmp 0xc369d
movq -0x2e0(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x8e790
jmp 0xc36b2
leaq -0x158(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xac20
jmp 0xc36c7
leaq -0x190(%rbp), %rdi
callq 0xac88
jmp 0xc36f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x190(%rbp), %rdi
callq 0xac88
jmp 0xc3a02
jmp 0xc36fa
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0x170(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52960
movq %rax, %rsi
leaq -0x138(%rbp), %rdi
callq 0x48dc0
jmp 0xc3736
jmp 0xc3738
movq -0x170(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x170(%rbp)
jmp 0xc3399
movq 0xd5862(%rip), %rdi     # 0x198fb8
leaq 0x774c9(%rip), %rsi     # 0x13ac26
callq 0xa5c0
movq %rax, -0x2e8(%rbp)
jmp 0xc376b
leaq -0x160(%rbp), %rdi
callq 0x597e0
movq -0x2e8(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
movq %rax, -0x2f0(%rbp)
jmp 0xc378f
movq -0x2f0(%rbp), %rdi
movq 0xd57eb(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc37a4
leaq -0x1b0(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0xa250
jmp 0xc37b9
movq 0xd57f8(%rip), %rdi     # 0x198fb8
leaq -0x1b0(%rbp), %rsi
callq 0x81090
jmp 0xc37ce
leaq -0x1b0(%rbp), %rdi
callq 0xac88
leaq -0x160(%rbp), %rdi
callq 0xc3df0
jmp 0xc32f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xac88
jmp 0xc3a02
leaq -0xb0(%rbp), %rdi
callq 0x58660
movq %rax, -0x1b8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x586c0
movq %rax, -0x1c0(%rbp)
leaq -0x1b8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x58690
testb $0x1, %al
jne 0xc3850
jmp 0xc39b1
leaq -0x138(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x44030
movq -0x300(%rbp), %rdi
movq %rax, -0x1d0(%rbp)
callq 0x44060
movq %rax, -0x1d8(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x586f0
movq %rax, %rdx
movq -0x1d0(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
callq 0x84050
movq %rax, -0x2f8(%rbp)
jmp 0xc38a8
movq -0x2f8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x44060
movq %rax, -0x1e0(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x83a10
testb $0x1, %al
jne 0xc38e5
jmp 0xc399e
movq 0xd56cc(%rip), %rdi     # 0x198fb8
leaq 0x7ef56(%rip), %rsi     # 0x142849
callq 0xa5c0
movq %rax, -0x308(%rbp)
jmp 0xc3901
leaq -0x1b8(%rbp), %rdi
callq 0x586f0
movq -0x308(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
movq %rax, -0x310(%rbp)
jmp 0xc3925
movq -0x310(%rbp), %rdi
movq 0xd5655(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc393a
leaq -0x1b8(%rbp), %rdi
callq 0x586f0
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x200(%rbp), %rdi
callq 0xa250
jmp 0xc395b
movq 0xd5656(%rip), %rdi     # 0x198fb8
leaq -0x200(%rbp), %rsi
callq 0x81090
jmp 0xc3970
leaq -0x200(%rbp), %rdi
callq 0xac88
jmp 0xc399e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x200(%rbp), %rdi
callq 0xac88
jmp 0xc3a02
jmp 0xc39a0
leaq -0x1b8(%rbp), %rdi
callq 0x58820
jmp 0xc3821
leaq -0x158(%rbp), %rdi
callq 0xac88
leaq -0x138(%rbp), %rdi
callq 0x3dfa0
leaq -0xb0(%rbp), %rdi
callq 0x58620
leaq -0x80(%rbp), %rdi
callq 0xac88
leaq -0x60(%rbp), %rdi
callq 0xac88
leaq -0x40(%rbp), %rdi
callq 0x3dfa0
leaq -0x28(%rbp), %rdi
callq 0xac88
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0xac88
leaq -0x138(%rbp), %rdi
callq 0x3dfa0
leaq -0xb0(%rbp), %rdi
callq 0x58620
leaq -0x80(%rbp), %rdi
callq 0xac88
leaq -0x60(%rbp), %rdi
callq 0xac88
leaq -0x40(%rbp), %rdi
callq 0x3dfa0
leaq -0x28(%rbp), %rdi
callq 0xac88
movq -0xc0(%rbp), %rdi
callq 0xab50
nopw %cs:(%rax,%rax)