// File: /workspace/github_cpp_makefile_star2_O1/schneebergerlab[P]GameteBinning/asPollinator_1.0.cpp
// Function: get_pollen_allele(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, 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 get_pollen_allele(string pollenfile, 
                       map<string, map<unsigned long, ALLELE> >* mkr)
{
    //
    ifstream ifp;
    ifp.open(pollenfile.c_str(), ios::in);
    if(!ifp.good())
    {
        cout << "   Error: cannot open pollen allele count file " << pollenfile << endl;
        return false;
    }
    while(ifp.good())
    {
        string line("");
        getline(ifp, line);
        if(line.size() == 0 || line[0]=='#') continue;
        //contig	      pos     Consensus   totalcount  A	  C   G   T   -   N   ...........
        //tig00000013_pilon   14777   T           2           0   0   0   1   0   1   1.0     1.1
        vector<string> lineinfo = split_string(line, '\t');
        if(lineinfo.size() < 10) continue; // unexpected format
        string keyctg = lineinfo[0];
        // <ctg, <pos, {ref, alt}> >
        map<string, map<unsigned long, ALLELE> >::iterator ctgitr;
        ctgitr = (*mkr).find(keyctg);
        if(ctgitr == (*mkr).end() ) 
        {
            // pollen contig not in marker list
            continue;
        }
        else
        {
            //map<unsigned long, ALLELE> indMarker = (*ctgitr).second; 
            // directly update the pointers
            string                           keypos_str = lineinfo[1];
            unsigned long                        keypos = strtoul(keypos_str.c_str(), NULL, 0);
            map<unsigned long, ALLELE>::iterator positr = ( (*ctgitr).second ).find(keypos);
            if(positr == ( (*ctgitr).second ).end())
            {
                // pollen position not in marker list
                continue;
            }
            else
            {
                // find pollen genotype data for a marker
                string refb = (*positr).second.refb; // 
                string altb = (*positr).second.altb; // 
                int refpos = 4;
                if(!get_base_position(refb, &refpos)) return false;
                int altpos = 4;
                if(!get_base_position(altb, &altpos)) return false;
                unsigned long refcnt = strtoul(lineinfo[refpos].c_str(), NULL, 0);
                unsigned long altcnt = strtoul(lineinfo[altpos].c_str(), NULL, 0);
                // refb; altb; none of refb and altb found 'N'; both refb and altb found 'U'
                if(refcnt>0 && altcnt>0)
                {
                    (*positr).second.pollenb = "U";
                }
                else
                if(refcnt>0)
                {
                    (*positr).second.pollenb = refb;
                }
                else
                if(altcnt>0)
                {
                    (*positr).second.pollenb = altb;
                }
                else
                {
                    (*positr).second.pollenb = "N";
                }
            }
        }
    }
    ifp.close();
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x110(%rsp), %r14
movq %r14, %rdi
callq 0x32e0
movq (%r15), %rsi
movq %r14, %rdi
movl $0x8, %edx
callq 0x3170
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x130(%rsp,%rax)
je 0xbe09
movq 0x15224(%rip), %rdi     # 0x20fd8
leaq 0xe31b(%rip), %rsi      # 0x1a0d6
movl $0x2f, %edx
callq 0x32f0
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x15205(%rip), %rdi     # 0x20fd8
callq 0x32f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31b0
xorl %ebx, %ebx
jmp 0xc252
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x130(%rsp,%rax)
jne 0xc243
leaq 0x8(%rbx), %rax
movq %rax, 0x108(%rsp)
leaq 0xa8(%rsp), %r15
leaq 0xe8(%rsp), %r12
movq %rbx, 0x28(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xe06f(%rip), %rdx      # 0x19ec9
movq %rdx, %rsi
callq 0x16622
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3480
movl $0x2, %ebp
cmpq $0x0, 0x10(%rsp)
je 0xc203
movq 0x8(%rsp), %rax
cmpb $0x23, (%rax)
je 0xc203
movb $0x9, 0xa8(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x189c0
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rax, %rcx
movl $0x2, %ebp
cmpq $0x140, %rcx            # imm = 0x140
jb 0xc1f9
leaq 0xb8(%rsp), %rcx
movq %rcx, 0xa8(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r15, %r13
movq %r15, %rdi
callq 0x16592
movq %rbx, %rdi
movq %r13, %rsi
callq 0x16d1c
movq %rax, %r13
cmpq 0x108(%rsp), %rax
je 0xc131
movq %r12, %rbp
movq 0x70(%rsp), %rax
leaq 0x98(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x16592
movq 0x88(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x30d0
movq 0x50(%r13), %rdx
addq $0x48, %r13
movq %r13, %rcx
testq %rdx, %rdx
je 0xbf90
movq %r13, %rcx
xorl %esi, %esi
cmpq %rax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0xbf78
movq %r13, %rbx
cmpq %r13, %rcx
je 0xbfa3
cmpq 0x20(%rcx), %rax
cmovbq %r13, %rcx
movq %rcx, %rbx
cmpq %r13, %rbx
je 0xc13b
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x16592
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x16592
movl $0x4, 0x4(%rsp)
leaq 0xf8(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x16592
movq %rbp, %rdi
leaq 0x4(%rsp), %rsi
callq 0x144ed
movl %eax, %r13d
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xc04c
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
movl $0x1, %ebp
testb %r13b, %r13b
je 0xc172
movl $0x4, (%rsp)
leaq 0xd8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
callq 0x16592
movq %r13, %rdi
movq %rsp, %rsi
callq 0x144ed
movl %eax, %r13d
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xc0c1
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3290
movl $0x1, %ebp
testb %r13b, %r13b
je 0xc172
movslq 0x4(%rsp), %rax
movq 0x70(%rsp), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x30d0
movq %rax, %r13
movslq (%rsp), %rax
movq 0x70(%rsp), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x30d0
leaq 0x68(%rbx), %rdi
testq %r13, %r13
je 0xc147
testq %rax, %rax
je 0xc147
movq 0x70(%rbx), %rdx
xorl %ebp, %ebp
movl $0x1, %r8d
xorl %esi, %esi
leaq 0xd98c(%rip), %rcx      # 0x19ab6
callq 0x33a0
jmp 0xc172
movl $0x2, %ebp
jmp 0xc1d4
movl $0x2, %ebp
movq 0x28(%rsp), %rbx
jmp 0xc1af
orq %r13, %rax
je 0xc164
testq %r13, %r13
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rax
cmovneq %rax, %rsi
callq 0x3160
jmp 0xc170
leaq 0xd4a5(%rip), %rsi      # 0x19610
callq 0x3330
xorl %ebp, %ebp
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xc18e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
movq 0x28(%rsp), %rbx
je 0xc1af
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xc1d4
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xc1f9
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x70(%rsp), %rdi
callq 0x147aa
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xc21f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
testb $0x1, %bpl
jne 0xbe02
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x130(%rsp,%rax)
je 0xbe44
movb $0x1, %bl
leaq 0x110(%rsp), %rdi
callq 0x3080
leaq 0x110(%rsp), %rdi
callq 0x3090
movl %ebx, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc2c3
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xc2c6
movq 0xd8(%rsp), %rsi
jmp 0xc2b9
jmp 0xc2c3
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xc2c6
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc2c6
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xc2e7
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc2e7
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xc308
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc308
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xc334
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc334
jmp 0xc331
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xc35e
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc35e
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x147aa
jmp 0xc376
jmp 0xc373
jmp 0xc36e
movq %rax, %rbx
jmp 0xc392
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xc392
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x110(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3460