// File: /workspace/github_cpp_makefile_star2_O2/schneebergerlab[P]GameteBinning/asPollinator_1.0.cpp
// Function: collect_marker_info(char const*, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::map<unsigned long, ALLELE, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, ALLELE>>>, 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::map<unsigned long, ALLELE, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, ALLELE>>>>>>*)
bool collect_marker_info(const char* file, 
                         map<string, map<unsigned long, ALLELE> >* mkr)
{
    // type of markers: snps(, 1-bp deletion and 1-bp insertion)
    cout << "   Info: reading marker info from " << file << endl;
    ifstream ifp;
    ifp.open(file);
    if(!ifp.good())
    {
        return false;
    }
    int num = 0;
    int raw = 0;
    int del = 0;
    int ins = 0;
    bool adjsnp = false; // SNPs directly next to each other
    int    nadj = 0;
    while(ifp.good())
    {
        string line("");
        getline(ifp, line);
        if(line.size()==0 || line[0]=='#') continue;
        
        /* e.g.,
	        ks	1	164393	C	G  -- snp
		ks	1	164413	AC	TA -- twp snps
		ks	1	460940  -	A  -- insertion
		ks	1	468923  T	-  -- deletion
        */
        vector<string> lineinfo = split_string(line, '\t');
        if(lineinfo[3].size() != lineinfo[4].size()) continue; // non-snps
        raw ++;
        
        if(lineinfo[3].size() > 1 && !adjsnp)
        {
            cout << "   Info: snp line will be separated, e.g, " << line << endl;
            cout << "       You will get a total number after reading all marker info. " << endl;
            adjsnp = true;
            nadj ++;
        }
        else
        if(lineinfo[3].size()>1)
        {
            nadj ++;
        }        
        //  split "double/triple/..." snps
        for(int snpi = 0; snpi < lineinfo[3].size(); snpi ++)
        {
            string ref = lineinfo[3].substr(snpi, 1);
            string alt = lineinfo[4].substr(snpi, 1);
            //
            unsigned long pos = strtoul(lineinfo[2].c_str(), NULL, 0);
            pos += snpi;
            std::stringstream sspos;
            sspos.str("");
            sspos << pos;
            //
            string        chrkey     = lineinfo[1];
            string        poskey_str = sspos.str();
            unsigned long poskey     = strtoul(poskey_str.c_str(), NULL, 0);
            string refb              = ref;
            string altb              = alt; // "GA", "G-" or "-A"
            string pollenb           = "N"; // unknown
            //
            map<string, map<unsigned long, ALLELE> >::iterator itr;
            map<string, map<unsigned long, ALLELE> >::iterator itr_end;
            itr     = (*mkr).find(chrkey);
            itr_end = (*mkr).end();
            
            if(itr == itr_end) 
            {
                ALLELE tmpallele;
                tmpallele.refb    = refb;
                tmpallele.altb    = altb;
                tmpallele.pollenb = pollenb;
                map<unsigned long, ALLELE> indMarker;
                indMarker.insert(std::pair<unsigned long, ALLELE>(poskey, tmpallele));
                // new contig
                (*mkr).insert(std::pair<string, map<unsigned long, ALLELE> >(chrkey, indMarker));
                num ++;
            } 
            else
            {
                ALLELE tmpallele;
                tmpallele.refb = refb;
                tmpallele.altb = altb;
                tmpallele.pollenb = pollenb;                
                // contig collected already with new marker position
                (*itr).second.insert(std::pair<unsigned long, ALLELE>(poskey, tmpallele));    
                num ++;                       
            }
            //
            if(alt=="-") del ++;
            if(ref=="-") ins ++;           
        }
    }
    ifp.close();
    cout << "   Info: recording " << num << " (of " << raw << ")" << " markers info done " << endl;  
    cout << "   Info: total number of \"neighboring\" snps: "     << nadj << endl;  
    cout << "   Info: total number of del markers: "              << del  << endl;
    cout << "   Info: total number of ins markers: "              << ins  << endl;
    if(num==0)
    {
        cout << "   Error: no markers found in marker file. " << endl;
        return false;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5d8, %rsp            # imm = 0x5D8
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
movq 0x13fce(%rip), %rdi     # 0x1bfd8
leaq 0xc1ca(%rip), %rsi      # 0x141db
callq 0x3260
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %rdi
callq 0x3140
leaq 0x3d0(%rsp), %r14
movq %r14, %rdi
callq 0x32b0
pushq $0x8
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3180
movq 0x3d0(%rsp), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
cmpl $0x0, 0x3f0(%rsp,%rax)
jne 0x86c0
movq 0x10(%rsp), %rcx
addq $0x8, %rcx
movq %rcx, 0xc8(%rsp)
leaq 0x1e0(%rsp), %r12
movq $0x0, 0x88(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpl $0x0, 0x3f0(%rsp,%rax)
jne 0x85bf
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
leaq 0xbe0c(%rip), %rsi      # 0x13ec7
leaq 0x248(%rsp), %rdx
callq 0xe174
leaq 0x3d0(%rsp), %rdi
movq %rbx, %rsi
callq 0x3070
cmpq $0x0, 0xb0(%rsp)
je 0x85a1
movq 0xa8(%rsp), %rax
cmpb $0x23, (%rax)
je 0x85a1
movb $0x9, 0x248(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x248(%rsp), %rdx
callq 0x11fdc
movq 0x90(%rsp), %rax
movq 0x68(%rax), %rcx
cmpq 0x88(%rax), %rcx
jne 0x8594
cmpq $0x2, %rcx
setb %al
orb 0x88(%rsp), %al
testb $0x1, %al
movl %r13d, 0x24(%rsp)
je 0x8158
xorl %eax, %eax
cmpq $0x2, %rcx
setae %al
jmp 0x81ab
movq 0x13e79(%rip), %rdi     # 0x1bfd8
leaq 0xc098(%rip), %rsi      # 0x141fe
callq 0x3260
movq %rax, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3240
movq %rax, %rdi
callq 0x3140
movq 0x13e4e(%rip), %rdi     # 0x1bfd8
leaq 0xc098(%rip), %rsi      # 0x14229
callq 0x3260
movb $0x1, %cl
movq %rcx, 0x88(%rsp)
movq %rax, %rdi
callq 0x3140
pushq $0x1
popq %rax
incl %r14d
movl %r14d, 0x1c(%rsp)
addl %eax, %ebp
movl %ebp, 0x20(%rsp)
xorl %r14d, %r14d
movq 0x90(%rsp), %rsi
cmpq %r14, 0x68(%rsi)
pushq $0x1
popq %rcx
jbe 0x8583
addq $0x60, %rsi
leaq 0x1c0(%rsp), %rdi
movq %r14, %rdx
movq %rcx, %rbx
callq 0x3290
movq 0x90(%rsp), %rsi
subq $-0x80, %rsi
leaq 0x1a0(%rsp), %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3290
movq 0x90(%rsp), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x30d0
movq %rax, %rbx
leaq 0x248(%rsp), %rdi
callq 0x31d0
movq %r12, %rdi
leaq 0xbc91(%rip), %rsi      # 0x13ec7
leaq 0x28(%rsp), %rdx
callq 0xe174
leaq 0x260(%rsp), %rdi
movq %r12, %rsi
callq 0x3340
addq %r14, %rbx
movq %r12, %rdi
callq 0x3120
leaq 0x258(%rsp), %rdi
movq %rbx, %rsi
callq 0x31b0
movq 0x90(%rsp), %rsi
addq $0x20, %rsi
leaq 0x160(%rsp), %rdi
callq 0x3300
movl %r15d, %ebp
leaq 0x180(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x3380
movq 0x180(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x30d0
movq %rax, %r15
leaq 0x140(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x3300
leaq 0x120(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x3300
leaq 0x100(%rsp), %rdi
leaq 0xb327(%rip), %rsi      # 0x13610
movq %r12, %rdx
callq 0xe174
movq 0x10(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x103e2
movq %rax, %rbx
cmpq 0xc8(%rsp), %rax
je 0x83c6
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
xorl %ecx, %ecx
movb %cl, 0x38(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
movb %cl, 0x58(%rsp)
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
movb %cl, 0x78(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x3170
leaq 0x48(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x3170
leaq 0x68(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x3170
movq %r15, 0x1e0(%rsp)
leaq 0x1e8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xe9c2
addq $0x40, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11b3a
movl %ebp, %r15d
leaq 0x1e8(%rsp), %rdi
callq 0xe676
jmp 0x84d9
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
xorl %ecx, %ecx
movb %cl, 0x38(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
movb %cl, 0x58(%rsp)
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
movb %cl, 0x78(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x3170
leaq 0x48(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x3170
leaq 0x68(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x3170
andl $0x0, 0xd8(%rsp)
andq $0x0, 0xe0(%rsp)
leaq 0xd8(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq %rax, 0xf0(%rsp)
andq $0x0, 0xf8(%rsp)
movq %r15, 0x1e0(%rsp)
leaq 0x1e8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xe9c2
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11b3a
movl %ebp, %r15d
leaq 0x1e8(%rsp), %rdi
callq 0xe676
movq %r12, %rdi
leaq 0x160(%rsp), %rsi
movq %rbx, %rdx
callq 0xe62a
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x11cda
movq %r12, %rdi
callq 0xe660
movq %rbx, %rdi
callq 0xef26
leaq 0x28(%rsp), %rdi
callq 0xe676
leaq 0x1a0(%rsp), %rbp
movq %rbp, %rdi
leaq 0xb754(%rip), %r13      # 0x13c49
movq %r13, %rsi
callq 0xe695
movzbl %al, %eax
addl %eax, 0xc(%rsp)
leaq 0x1c0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe695
movzbl %al, %eax
addl %eax, %r15d
leaq 0x100(%rsp), %rdi
callq 0x3120
leaq 0x120(%rsp), %rdi
callq 0x3120
leaq 0x140(%rsp), %rdi
callq 0x3120
leaq 0x180(%rsp), %rdi
callq 0x3120
leaq 0x160(%rsp), %rdi
callq 0x3120
leaq 0x248(%rsp), %rdi
callq 0x31f0
movq %rbp, %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3120
incq %r14
jmp 0x81bc
movl 0x24(%rsp), %r13d
addl %r14d, %r13d
movl 0x20(%rsp), %ebp
movl 0x1c(%rsp), %r14d
leaq 0x90(%rsp), %rdi
callq 0xe2d8
leaq 0xa8(%rsp), %rdi
callq 0x3120
movq 0x3d0(%rsp), %rax
movq -0x18(%rax), %rax
jmp 0x809b
leaq 0x3d0(%rsp), %rdi
callq 0x3080
movq 0x13a05(%rip), %rdi     # 0x1bfd8
leaq 0xbc92(%rip), %rsi      # 0x1426c
callq 0x3260
movq %rax, %rdi
movl %r13d, %esi
callq 0x33f0
leaq 0xbc8f(%rip), %rsi      # 0x14280
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
movl %r14d, %esi
callq 0x33f0
leaq 0xba50(%rip), %rsi      # 0x1405b
movq %rax, %rdi
callq 0x3260
leaq 0xbc6c(%rip), %rsi      # 0x14286
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3140
movq 0x139a7(%rip), %rdi     # 0x1bfd8
leaq 0xbc62(%rip), %rsi      # 0x1429a
callq 0x3260
movq %rax, %rdi
movl %ebp, %esi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movq 0x13982(%rip), %rdi     # 0x1bfd8
leaq 0xbc6b(%rip), %rsi      # 0x142c8
callq 0x3260
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movq 0x1395b(%rip), %rdi     # 0x1bfd8
leaq 0xbc6b(%rip), %rsi      # 0x142ef
callq 0x3260
movq %rax, %rdi
movl %r15d, %esi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movb $0x1, %bl
testl %r13d, %r13d
jne 0x86c0
movq 0x1392e(%rip), %rdi     # 0x1bfd8
leaq 0xbc65(%rip), %rsi      # 0x14316
callq 0x3260
movq %rax, %rdi
callq 0x3140
xorl %ebx, %ebx
leaq 0x3d0(%rsp), %rdi
callq 0x30a0
movl %ebx, %eax
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x86f4
jmp 0x86ec
jmp 0x876a
jmp 0x86f4
movq %rax, %rbx
jmp 0x880d
movq %rax, %rbx
jmp 0x881a
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
callq 0xe660
jmp 0x8725
jmp 0x8710
movq %rax, %rbx
jmp 0x8725
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0xe676
leaq 0xd0(%rsp), %rdi
callq 0xef26
jmp 0x878e
jmp 0x878b
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0xe676
jmp 0x878e
movq %rax, %rbx
jmp 0x87b2
jmp 0x875b
jmp 0x875b
movq %rax, %rbx
jmp 0x87cc
movq %rax, %rbx
jmp 0x8798
movq %rax, %rbx
jmp 0x87d9
movq %rax, %rbx
jmp 0x87a5
movq %rax, %rbx
jmp 0x87bf
movq %rax, %rbx
jmp 0x8800
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
jmp 0x87d4
movq %rax, %rbx
jmp 0x87e6
movq %rax, %rbx
jmp 0x87f3
jmp 0x878b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xe676
leaq 0x100(%rsp), %rdi
callq 0x3120
leaq 0x120(%rsp), %rdi
callq 0x3120
leaq 0x140(%rsp), %rdi
callq 0x3120
leaq 0x180(%rsp), %rdi
callq 0x3120
leaq 0x160(%rsp), %rdi
callq 0x3120
leaq 0x248(%rsp), %rdi
callq 0x31f0
leaq 0x1a0(%rsp), %rdi
callq 0x3120
leaq 0x1c0(%rsp), %rdi
callq 0x3120
leaq 0x90(%rsp), %rdi
callq 0xe2d8
leaq 0xa8(%rsp), %rdi
callq 0x3120
leaq 0x3d0(%rsp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x3410