// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_sequenom.cpp
// Function: sequenomMain(int, char**)
int sequenomMain(int argc, char** argv) {
    parseSequenomOptions(argc, argv);
    std::ios_base::openmode mode = std::ios_base::in;
    string vcfFileName = opt::vcfFile;
    string vcfFileRoot = stripExtension(vcfFileName);
    string genomeFileName = opt::genomeFile;
    string geneFileName = opt::geneFile;
    
    
    std::cerr << "Generating a txt file for sequenom assay from: " << vcfFileName << std::endl;
    std::cerr << "and the reference genome: " << genomeFileName << std::endl;
    std::cerr << "with SNP flanking regions defined in: " << geneFileName << std::endl;
    
    // Open connections to read from the vcf and reference genome files
    std::ifstream* vcfFile = new std::ifstream(vcfFileName.c_str(), mode);
    std::ifstream* genomeFile = new std::ifstream(genomeFileName.c_str(), mode);
    std::ifstream* geneFile = new std::ifstream(geneFileName.c_str(), mode);
    std::ofstream* sequenomDesignFile = new std::ofstream("sequenom.txt");
    
    string line;
    int currentScaffoldNum = -1;
    string currentScaffoldReference;
    string::size_type inStrPos;
    std::vector<string> sampleNames;
    string thisScaffoldName;
    std::string sequenomString = "";
    
    // Load up the annotation file with SNP flanking regions
    std::vector<std::vector<string> > annotation;
    Annotation wgAnnotation(geneFile, false);
    
    while (getline(*vcfFile, line)) {
        if (line[0] == '#' && line[1] == '#')
            continue;
        else if (line[0] == '#' && line[1] == 'C') {
            
            std::vector<std::string> fields = split(line, '\t');
            // Initialize vectors
            sequenomString.reserve(100000000);
            sequenomString = "";
            
            for (std::vector<std::string>::size_type i = NUM_NON_GENOTYPE_COLUMNS; i != fields.size(); i++) {
                if (opt::sampleNameFile.empty())
                    sampleNames.push_back(fields[i]);
                else
                    sampleNames = readSampleNamesFromTextFile(opt::sampleNameFile);
            }
        } else {
            std::vector<std::string> fields = split(line, '\t');
            // Also get overall depth for this variant
            std::vector<std::string> info = split(fields[7], ';');
            std::vector<std::string> sc = split(fields[0], '_');
            if (atoi(sc[1].c_str()) > currentScaffoldNum) {
                if (currentScaffoldNum >= 0) {
                    // Fill in the rest of the scaffold sequence (after the last variant)
                    sequenomString.append(currentScaffoldReference.substr(inStrPos, string::npos));
                    
#ifdef DEBUG
                    if (sequenomString.length() != currentScaffoldReference.length()) {
                        std::cerr << "Error!!! Reference scaffold length: " << currentScaffoldReference.length() << " vcf scaffold length: " << sequenomString.length() << std::endl;
                    }
#endif
                    
                    string sc = "scaffold_" + numToString(currentScaffoldNum);
                    std::cerr << "Scaffold: " << sc << std::endl;
                    annotation = wgAnnotation.annotationMap[sc]; // Get the SNP surrounding regions on this scaffold
                    for (std::vector<std::vector<string> >::size_type k = 0; k != annotation.size(); k++) {
                        std::vector<string> annotLineVec = split(annotation[k][0], '\t');
                        // std::cerr << "Gene:" << annotLineVec[4] << std::endl;
                        
                        string regionSeq = getIndividualSequenceForThisRegion(annotation[k], annotLineVec[3], sequenomString);
                        string refSeq = getReferenceForThisRegion(annotation[k], annotLineVec[3], currentScaffoldReference);
                        int coordinate = atoi(annotLineVec[2].c_str()) - 100;
                        string location = sc + "_" + numToString(coordinate);
                        
                        writeSequenomOutput(regionSeq, refSeq, location, sequenomDesignFile);
                    }
                    
                    sequenomString = "";
                } else {
                    getline(*genomeFile, thisScaffoldName);
                }
                
                std::cerr << "Starting to read " << thisScaffoldName << std::endl;
                currentScaffoldReference = readScaffold(genomeFile, thisScaffoldName);
#ifdef DEBUG2
                std::cerr << "Finished reading. Next scaffold will be: " << thisScaffoldName << std::endl;
#endif
                inStrPos = 0;
                currentScaffoldNum = atoi(sc[1].c_str());
            }
            if (info[0] != "INDEL") {
                sequenomString.append(currentScaffoldReference.substr(inStrPos, (atoi(fields[1].c_str()) - 1)-inStrPos));
                Counts thisVariantCounts = getThisVariantCounts(fields);
                if (thisVariantCounts.overall != ((fields.size()-NUM_NON_GENOTYPE_COLUMNS)*2)) {
                    string ambiguityBase = getAmbiguityCode(fields[3], fields[4]);
                    sequenomString.append(ambiguityBase);
                } else {
                    sequenomString.append(fields[4]);
                }
                inStrPos = atoi(fields[1].c_str());
                
#ifdef DEBUG
                if (currentScaffoldReference[inStrPos-1] != fields[3][0]) {
                    std::cerr << "Error!!! Sequence: " << currentScaffoldReference[inStrPos-1] << " vcf-ref: " << fields[3][0] << std::endl;
                }
#endif
            }
        }
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
callq 0x5e719
leaq 0x80a5b(%rip), %rsi     # 0xde660
leaq 0x1a8(%rsp), %rbx
movq %rbx, %rdi
callq 0x8600
leaq 0x208(%rsp), %rdi
movq %rbx, %rsi
callq 0x404d7
leaq 0x80a54(%rip), %rsi     # 0xde680
leaq 0x188(%rsp), %rdi
callq 0x8600
leaq 0x80a60(%rip), %rsi     # 0xde6a0
leaq 0x168(%rsp), %rdi
callq 0x8600
movq 0x7f394(%rip), %rdi     # 0xdcfe8
leaq 0x48441(%rip), %rsi     # 0xa609c
callq 0x8480
leaq 0x1a8(%rsp), %rsi
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq 0x7f369(%rip), %rdi     # 0xdcfe8
leaq 0x457b5(%rip), %rsi     # 0xa343b
callq 0x8480
leaq 0x188(%rsp), %rsi
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq 0x7f33e(%rip), %rdi     # 0xdcfe8
leaq 0x4841b(%rip), %rsi     # 0xa60cc
callq 0x8480
leaq 0x168(%rsp), %rsi
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %rbx
movq 0x1a8(%rsp), %rsi
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r15
movq 0x188(%rsp), %rsi
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
movq %r15, 0x48(%rsp)
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r15
movq 0x168(%rsp), %rsi
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
movq %r15, 0xf0(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %r15
leaq 0x483a4(%rip), %rsi     # 0xa60f3
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0x84e0
leaq 0x140(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %r15, 0xe8(%rsp)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
andq $0x0, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x3c06a(%rip), %rsi     # 0x99e1f
leaq 0x70(%rsp), %rdi
leaq 0x2a8(%rsp), %rdx
callq 0x21904
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x3a8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
xorl %edx, %edx
callq 0x32000
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
leaq 0x130(%rsp), %r15
leaq 0x2a8(%rsp), %r14
leaq 0x70(%rsp), %r13
leaq 0x268(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5e42f
movq 0x130(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x5df00
movzbl 0x1(%rax), %eax
cmpl $0x23, %eax
je 0x5de10
cmpl $0x43, %eax
jne 0x5df00
movq %r14, %rdi
movq %r15, %rsi
pushq $0x9
popq %rdx
callq 0x40349
movq %r15, %r13
movl $0x5f5e100, %esi        # imm = 0x5F5E100
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x8700
movq %r14, %rdi
leaq 0x3bfa2(%rip), %rsi     # 0x99e1f
callq 0x88f0
movl $0x120, %r14d           # imm = 0x120
pushq $0x9
popq %r15
movq 0x2a8(%rsp), %rsi
movq 0x2b0(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r15
je 0x5e1ab
cmpq $0x0, 0x80814(%rip)     # 0xde6c8
je 0x5dee7
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x807f8(%rip), %rsi     # 0xde6c0
callq 0x4237c
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
callq 0x2f6c0
movq %rbp, %rdi
callq 0x28a08
jmp 0x5def7
addq %r14, %rsi
leaq 0x90(%rsp), %rdi
callq 0x2b0a4
incq %r15
addq $0x20, %r14
jmp 0x5de8c
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
pushq $0x9
popq %rdx
callq 0x40349
movq 0x18(%rsp), %rsi
movl $0xe0, %eax
addq %rax, %rsi
leaq 0x150(%rsp), %rdi
pushq $0x3b
popq %rdx
callq 0x40349
movq 0x18(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
pushq $0x5f
popq %rdx
callq 0x40349
movq 0xf8(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x86f0
movl 0x8(%rsp), %ecx
cmpl %ecx, %eax
jle 0x5e276
testl %ecx, %ecx
js 0x5e1f1
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rdx
pushq $-0x1
popq %rcx
callq 0x84b0
movq %r13, %rdi
movq %r14, %rsi
callq 0x8920
movq %r14, %rdi
callq 0x8978
movq 0x78(%rsp), %rax
cmpq 0x58(%rsp), %rax
je 0x5dfdf
movq 0x7f046(%rip), %rdi     # 0xdcfe8
leaq 0x465a1(%rip), %rsi     # 0xa454a
callq 0x8480
movq 0x58(%rsp), %rsi
movq %rax, %rdi
callq 0x8320
movq %rax, %rdi
leaq 0x4550f(%rip), %rsi     # 0xa34d4
callq 0x8480
movq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x8320
movq %rax, %rdi
callq 0x8230
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movl 0x8(%rsp), %esi
callq 0x28ad3
movq %r14, %rdi
leaq 0x4836d(%rip), %rsi     # 0xa636a
movq %r15, %rdx
callq 0x5eb31
movq %r15, %rdi
callq 0x8978
movq 0x7efd4(%rip), %rdi     # 0xdcfe8
leaq 0x480e5(%rip), %rsi     # 0xa6100
callq 0x8480
movq %rax, %rdi
movq %r14, %rsi
callq 0x8430
movq %rax, %rdi
callq 0x8230
leaq 0x3a8(%rsp), %rdi
movq %r14, %rsi
callq 0x2957c
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x295e2
xorl %r15d, %r15d
xorl %edi, %edi
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %rax, %rdi
je 0x5e1c8
movq %rdi, 0x8(%rsp)
movq (%rcx,%r15), %rsi
leaq 0xb0(%rsp), %rdi
pushq $0x9
popq %rdx
callq 0x40349
movq 0x30(%rsp), %rsi
addq %r15, %rsi
movq 0xb0(%rsp), %rdx
addq $0x60, %rdx
leaq 0xc8(%rsp), %rdi
movq %r13, %rcx
callq 0x468d8
movq 0x30(%rsp), %rsi
addq %r15, %rsi
movq 0xb0(%rsp), %rdx
addq $0x60, %rdx
leaq 0x1e8(%rsp), %rdi
leaq 0x50(%rsp), %rcx
callq 0x46a62
movq %rbx, %rbp
movq 0xb0(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x86f0
movl %eax, %r13d
movq %r12, %rdi
leaq 0x2a8(%rsp), %rsi
leaq 0x456bd(%rip), %rdx     # 0xa37bc
callq 0x28806
addl $-0x64, %r13d
leaq 0x248(%rsp), %rbx
movq %rbx, %rdi
movl %r13d, %esi
callq 0x28ad3
leaq 0x288(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x28a48
movq %rbx, %rdi
callq 0x8978
movq %r12, %rbx
movq %r12, %rdi
callq 0x8978
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
leaq 0x1e8(%rsp), %r12
movq %r12, %rsi
movq %r14, %rdx
leaq 0xe8(%rsp), %rcx
callq 0x5e8f4
movq %r14, %rdi
callq 0x8978
movq %r12, %rdi
callq 0x8978
movq %r13, %rdi
callq 0x8978
leaq 0xb0(%rsp), %rdi
callq 0x28a08
movq 0x8(%rsp), %rdi
incq %rdi
addq $0x18, %r15
movq %rbx, %r12
movq %rbp, %rbx
leaq 0x70(%rsp), %r13
jmp 0x5e055
leaq 0x2a8(%rsp), %r14
movq %r14, %rdi
callq 0x28a08
movq %r13, %r15
leaq 0x70(%rsp), %r13
jmp 0x5de10
movq %r13, %rdi
leaq 0x3bc4d(%rip), %rsi     # 0x99e1f
callq 0x88f0
leaq 0x2a8(%rsp), %r14
movq %r14, %rdi
callq 0x8978
leaq 0x130(%rsp), %r15
jmp 0x5e203
movq 0x48(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x80a0
movq 0x7edde(%rip), %rdi     # 0xdcfe8
leaq 0x45389(%rip), %rsi     # 0xa359a
callq 0x8480
movq %rax, %rdi
leaq 0x110(%rsp), %rsi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq %r14, %rdi
leaq 0x48(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x3a53b
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x8550
movq %r14, %rdi
callq 0x8978
movq 0xf8(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x86f0
movl %eax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x150(%rsp), %rdi
leaq 0x39435(%rip), %rsi     # 0x976ba
callq 0x2ea9b
testb %al, %al
je 0x5e406
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x86f0
decl %eax
movslq %eax, %rcx
movq 0x10(%rsp), %rdx
subq %rdx, %rcx
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
callq 0x84b0
movq %r13, %rdi
movq %r14, %rsi
callq 0x8920
movq %r14, %rdi
callq 0x8978
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x40d83
movslq 0x2a8(%rsp), %rax
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
subq %rsi, %rcx
sarq $0x4, %rcx
addq $-0x12, %rcx
cmpq %rax, %rcx
jne 0x5e30a
subq $-0x80, %rsi
movq %r13, %rdi
callq 0x8920
jmp 0x5e37a
addq $0x60, %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x8600
leaq 0x228(%rsp), %rbp
movq 0x18(%rsp), %rsi
subq $-0x80, %rsi
movq %rbp, %rdi
callq 0x8600
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
leaq 0x1c8(%rsp), %r13
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4667a
movq %rbp, %rdi
callq 0x8978
movq %r13, %rdi
callq 0x8978
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x8920
movq %r14, %rdi
callq 0x8978
movq 0x18(%rsp), %r14
movq 0x20(%r14), %rdi
callq 0x86f0
movslq %eax, %rdx
movq 0x50(%rsp), %rax
movq %rdx, 0x10(%rsp)
movb -0x1(%rdx,%rax), %al
movq 0x60(%r14), %rcx
cmpb (%rcx), %al
je 0x5e3f6
movq 0x7ec40(%rip), %rdi     # 0xdcfe8
leaq 0x462a1(%rip), %rsi     # 0xa4650
callq 0x8480
movq 0x50(%rsp), %rcx
movq 0x10(%rsp), %rdx
movsbl -0x1(%rcx,%rdx), %esi
movq %rax, %rdi
callq 0x8510
movq %rax, %rdi
leaq 0x4628f(%rip), %rsi     # 0xa4664
callq 0x8480
movq 0x18(%rsp), %rcx
movq 0x60(%rcx), %rcx
movsbl (%rcx), %esi
movq %rax, %rdi
callq 0x8510
movq %rax, %rdi
callq 0x8230
leaq 0x2a8(%rsp), %r14
movq %r14, %rdi
callq 0x289b4
leaq 0xf8(%rsp), %rdi
callq 0x28a08
leaq 0x150(%rsp), %rdi
callq 0x28a08
leaq 0x18(%rsp), %rdi
callq 0x28a08
jmp 0x5de10
leaq 0x3a8(%rsp), %rdi
callq 0x32212
leaq 0x30(%rsp), %rdi
callq 0x29054
leaq 0x70(%rsp), %rdi
callq 0x8978
leaq 0x110(%rsp), %rdi
callq 0x8978
leaq 0x90(%rsp), %rdi
callq 0x28a08
leaq 0x50(%rsp), %rdi
callq 0x8978
leaq 0x130(%rsp), %rdi
callq 0x8978
leaq 0x168(%rsp), %rdi
callq 0x8978
leaq 0x188(%rsp), %rdi
callq 0x8978
leaq 0x208(%rsp), %rdi
callq 0x8978
leaq 0x1a8(%rsp), %rdi
callq 0x8978
xorl %eax, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x5e4f0
jmp 0x5e5af
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
jmp 0x5e4f8
movq %rax, %r14
leaq 0x228(%rsp), %rdi
callq 0x8978
leaq 0x1c8(%rsp), %rdi
callq 0x8978
jmp 0x5e5b2
jmp 0x5e5c6
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
jmp 0x5e65a
jmp 0x5e5ed
jmp 0x5e5c6
jmp 0x5e711
jmp 0x5e5c6
jmp 0x5e5c6
jmp 0x5e5ed
jmp 0x5e5c6
movq %rax, %r14
jmp 0x5e690
movq %rax, %r14
jmp 0x5e6a4
movq %rax, %r14
movl $0x200, %esi            # imm = 0x200
jmp 0x5e562
jmp 0x5e5ce
jmp 0x5e55a
jmp 0x5e5ce
movq %rax, %r14
movl $0x208, %esi            # imm = 0x208
movq %r15, %rdi
jmp 0x5e574
jmp 0x5e5ce
movq %rax, %r14
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
callq 0x84a0
jmp 0x5e6d5
jmp 0x5e5ce
movq %rax, %r14
jmp 0x5e6e2
movq %rax, %r14
jmp 0x5e6ef
movq %rax, %r14
jmp 0x5e6fc
jmp 0x5e5d8
movq %rax, %r14
jmp 0x5e66c
movq %rax, %r14
jmp 0x5e679
jmp 0x5e711
movq %rax, %r14
leaq 0x2a8(%rsp), %rdi
callq 0x289b4
jmp 0x5e65f
jmp 0x5e5ed
movq %rax, %r14
jmp 0x5e65f
movq %rax, %r14
jmp 0x5e6d5
jmp 0x5e5d8
movq %rax, %r14
leaq 0x2a8(%rsp), %rdi
jmp 0x5e67e
movq %rax, %r14
jmp 0x5e621
movq %rax, %r14
jmp 0x5e652
movq %rax, %r14
leaq 0x288(%rsp), %rdi
jmp 0x5e61c
movq %rax, %r14
jmp 0x5e614
movq %rax, %r14
leaq 0x248(%rsp), %rdi
callq 0x8978
leaq 0x268(%rsp), %rdi
callq 0x8978
leaq 0x1e8(%rsp), %rdi
callq 0x8978
jmp 0x5e638
movq %rax, %r14
jmp 0x5e645
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x8978
leaq 0xb0(%rsp), %rdi
callq 0x28a08
leaq 0x2a8(%rsp), %rdi
callq 0x8978
leaq 0xf8(%rsp), %rdi
callq 0x28a08
leaq 0x150(%rsp), %rdi
callq 0x28a08
leaq 0x18(%rsp), %rdi
callq 0x28a08
leaq 0x3a8(%rsp), %rdi
callq 0x32212
leaq 0x30(%rsp), %rdi
callq 0x29054
leaq 0x70(%rsp), %rdi
callq 0x8978
leaq 0x110(%rsp), %rdi
callq 0x8978
leaq 0x90(%rsp), %rdi
callq 0x28a08
leaq 0x50(%rsp), %rdi
callq 0x8978
leaq 0x130(%rsp), %rdi
callq 0x8978
leaq 0x168(%rsp), %rdi
callq 0x8978
leaq 0x188(%rsp), %rdi
callq 0x8978
leaq 0x208(%rsp), %rdi
callq 0x8978
leaq 0x1a8(%rsp), %rdi
callq 0x8978
movq %r14, %rdi
callq 0x8870
movq %rax, %r14
jmp 0x5e683