// File: millanek[P]evo/process_vcf_use_map.cpp
// Function: processVCF(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 processVCF(const std::map<string, std::vector<std::vector<string> > >& LGmap) {
    
    std::cerr << "Processing VCF variant calls from: " << opt::inputFile << std::endl;
    std::cerr << "using linkage groups defined in: " << opt::LGfile << std::endl;
    
    string line;
    std::ifstream* vcfFile = new std::ifstream(opt::inputFile.c_str());
    
    string currentScaffoldNum = "";
    bool bInLG;
    string thisLG;
    int LGsizeUpToHere;
    int thisScaffoldSize;
    char thisScaffoldOrientation;
    
    while (getline(*vcfFile, line)) {
        if (line[0] == '#')
            std::cout << line << std::endl;
        else {
            std::vector<string> vcfFields = split(line, '\t');
            if (vcfFields[0] == currentScaffoldNum) {
                printProcessedVCFline(vcfFields, bInLG, thisScaffoldOrientation, thisLG, LGsizeUpToHere, thisScaffoldSize, line);
            } else {
                currentScaffoldNum = vcfFields[0];
                std::vector<string> scaffoldNumVec = split(vcfFields[0], '_');
                bInLG = false;
                thisLG = "";
                for(std::map<string, std::vector<std::vector<string> > >::const_iterator it = LGmap.begin(); it != LGmap.end(); ++it) {
                    // std::cerr << "Building " << it->first << std::endl;
                    LGsizeUpToHere = 0;
                    for (std::vector<std::vector<string> >::size_type i = 0; i != it->second.size(); i++) {
                        // std::cerr << "Adding " << it->second[i][0] << std::endl;
                        if (it->second[i][0] == scaffoldNumVec[1]) {
                            bInLG = true;
                            thisLG = it->first;
                            thisScaffoldSize = atoi(it->second[i][2].c_str());
                            if (it->second[i][1] == "+")
                                thisScaffoldOrientation = '+';
                            else if (it->second[i][1] == "-")
                                thisScaffoldOrientation = '-';
                            break;
                        } else {
                            LGsizeUpToHere += atoi(it->second[i][2].c_str());
                            //std::cerr << "Here: " << it->second[i][0] << std::endl;
                            //std::cerr << "LG:" << it->first << " LGsizeUpToHere: " << LGsizeUpToHere << std::endl;
                        }
                    }
                    if (bInLG) break;
                }
                // std::cerr << "LGsizeUpToHere: " << LGsizeUpToHere << std::endl;
                printProcessedVCFline(vcfFields, bInLG, thisScaffoldOrientation, thisLG, LGsizeUpToHere, thisScaffoldSize, line);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq 0xd66ea(%rip), %rdi     # 0x198ff0
movq %rdi, -0xf8(%rbp)
leaq 0x7feb6(%rip), %rsi     # 0x1427ca
callq 0xa5c0
movq %rax, %rdi
leaq 0xd8285(%rip), %rsi     # 0x19aba8
callq 0xa520
movq %rax, %rdi
movq 0xd6656(%rip), %rsi     # 0x198f88
movq %rsi, -0xf0(%rbp)
callq 0xa610
movq -0xf8(%rbp), %rdi
leaq 0x7fea2(%rip), %rsi     # 0x1427ee
callq 0xa5c0
movq %rax, %rdi
leaq 0xd826d(%rip), %rsi     # 0x19abc8
callq 0xa520
movq -0xf0(%rbp), %rsi
movq %rax, %rdi
callq 0xa610
leaq -0x28(%rbp), %rdi
callq 0xa820
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0xe8(%rbp)
jmp 0xc298b
leaq 0xd8216(%rip), %rdi     # 0x19aba8
callq 0xa220
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0xc29ad
movq -0xe8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xab60
movq -0x100(%rbp), %rdx
leaq 0x73509(%rip), %rsi     # 0x135edf
leaq -0x60(%rbp), %rdi
callq 0x2d6c0
jmp 0xc29e1
leaq -0x61(%rbp), %rdi
callq 0xa640
leaq -0x88(%rbp), %rdi
callq 0xa820
movq -0x30(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x108(%rbp)
jmp 0xc2a0c
movq -0x108(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x109(%rbp)
jmp 0xc2a2a
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0xc2a39
jmp 0xc2edc
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0xac60
movq %rax, -0x118(%rbp)
jmp 0xc2a4f
movq -0x118(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0xc2af3
movq 0xd654f(%rip), %rdi     # 0x198fb8
leaq -0x28(%rbp), %rsi
callq 0xa520
movq %rax, -0x120(%rbp)
jmp 0xc2a7b
movq -0x120(%rbp), %rdi
movq 0xd64ff(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0xc2a90
jmp 0xc2ed7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc2f18
movq -0xe8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0xc2f18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x61(%rbp), %rdi
callq 0xa640
jmp 0xc2f18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc2f03
leaq -0xb0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0xc2b0a
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d940
movq %rax, %rdi
leaq -0x60(%rbp), %rsi
callq 0x39210
testb $0x1, %al
jne 0xc2b2c
jmp 0xc2b7d
movsbl -0x91(%rbp), %edx
movzbl -0x62(%rbp), %esi
movq %rsp, %rax
leaq -0x28(%rbp), %rcx
movq %rcx, (%rax)
andl $0x1, %esi
leaq -0xb0(%rbp), %rdi
leaq -0x88(%rbp), %rcx
leaq -0x8c(%rbp), %r8
leaq -0x90(%rbp), %r9
callq 0xc3a60
jmp 0xc2b67
jmp 0xc2ebb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc2ec9
xorl %eax, %eax
movl %eax, %esi
leaq -0xb0(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0xa060
jmp 0xc2b9b
xorl %eax, %eax
movl %eax, %esi
leaq -0xb0(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0xc8(%rbp), %rdi
movl $0x5f, %edx
callq 0x7bbe0
jmp 0xc2bc1
movb $0x0, -0x62(%rbp)
leaq 0x73313(%rip), %rsi     # 0x135edf
leaq -0x88(%rbp), %rdi
callq 0xa810
jmp 0xc2bda
movq -0x8(%rbp), %rdi
callq 0xc3d90
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
callq 0xc3dc0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x59490
testb $0x1, %al
jne 0xc2c16
jmp 0xc2e74
movl $0x0, -0x8c(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x409f0
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
je 0xc2e59
leaq -0xd0(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0xe0(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52960
movq %rax, -0x130(%rbp)
leaq -0xc8(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x39210
testb $0x1, %al
jne 0xc2cbf
jmp 0xc2df8
movb $0x1, -0x62(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x597e0
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0xa060
jmp 0xc2ce0
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0xe0(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x2, %esi
callq 0x52960
movq %rax, %rdi
callq 0xa220
movq %rax, %rdi
callq 0xa970
movq -0x140(%rbp), %rdi
movl %eax, -0x90(%rbp)
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0xe0(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x1, %esi
callq 0x52960
movq %rax, %rdi
leaq 0x71da4(%rip), %rsi     # 0x134b03
callq 0x2d770
movb %al, -0x131(%rbp)
jmp 0xc2d6c
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0xc2d78
jmp 0xc2d9e
movb $0x2b, -0x91(%rbp)
jmp 0xc2df6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3dfa0
jmp 0xc2ec9
leaq -0xd0(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0xe0(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x1, %esi
callq 0x52960
movq %rax, %rdi
leaq 0x71d3c(%rip), %rsi     # 0x134b10
callq 0x2d770
movb %al, -0x141(%rbp)
jmp 0xc2de1
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0xc2ded
jmp 0xc2df4
movb $0x2d, -0x91(%rbp)
jmp 0xc2df6
jmp 0xc2e59
leaq -0xd0(%rbp), %rdi
callq 0x597e0
movq %rax, %rdi
addq $0x20, %rdi
movq -0xe0(%rbp), %rsi
callq 0x59850
movq %rax, %rdi
movl $0x2, %esi
callq 0x52960
movq %rax, %rdi
callq 0xa220
movq %rax, %rdi
callq 0xa970
addl -0x8c(%rbp), %eax
movl %eax, -0x8c(%rbp)
jmp 0xc2e42
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0xc2c2b
testb $0x1, -0x62(%rbp)
je 0xc2e61
jmp 0xc2e74
jmp 0xc2e63
leaq -0xd0(%rbp), %rdi
callq 0xc3df0
jmp 0xc2bea
movsbl -0x91(%rbp), %edx
movzbl -0x62(%rbp), %esi
movq %rsp, %rax
leaq -0x28(%rbp), %rcx
movq %rcx, (%rax)
andl $0x1, %esi
leaq -0xb0(%rbp), %rdi
leaq -0x88(%rbp), %rcx
leaq -0x8c(%rbp), %r8
leaq -0x90(%rbp), %r9
callq 0xc3a60
jmp 0xc2eaf
leaq -0xc8(%rbp), %rdi
callq 0x3dfa0
leaq -0xb0(%rbp), %rdi
callq 0x3dfa0
jmp 0xc2ed7
leaq -0xb0(%rbp), %rdi
callq 0x3dfa0
jmp 0xc2f03
jmp 0xc29f6
leaq -0x88(%rbp), %rdi
callq 0xac88
leaq -0x60(%rbp), %rdi
callq 0xac88
leaq -0x28(%rbp), %rdi
callq 0xac88
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0xac88
leaq -0x60(%rbp), %rdi
callq 0xac88
leaq -0x28(%rbp), %rdi
callq 0xac88
movq -0x38(%rbp), %rdi
callq 0xab50
nopw (%rax,%rax)