// File: /workspace/github_cpp_makefile_star2_O3/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, 0x28(%rsp)
movq %rdi, %rbx
leaq 0x110(%rsp), %r13
movq %r13, %rdi
callq 0x32e0
movq (%rbx), %rsi
movq %r13, %rdi
movl $0x8, %edx
callq 0x3170
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x130(%rsp,%rax)
je 0xbd45
movq 0x152e8(%rip), %rdi     # 0x20fd8
leaq 0xe3df(%rip), %rsi      # 0x1a0d6
movl $0x2f, %edx
callq 0x32f0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x152c9(%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 0xc16c
movq 0x28(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x108(%rsp)
leaq 0x98(%rsp), %rbx
leaq 0xa8(%rsp), %r15
leaq 0xe8(%rsp), %r14
leaq 0xc8(%rsp), %r12
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xe13d(%rip), %rdx      # 0x19ec9
movq %rdx, %rsi
callq 0x16550
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3480
cmpq $0x0, 0x10(%rsp)
movl $0x2, %ebp
movq 0x8(%rsp), %rdi
je 0xc11a
cmpb $0x23, (%rdi)
je 0xc11a
movb $0x9, 0xa8(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x188a8
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rax, %rcx
movl $0x2, %ebp
cmpq $0x140, %rcx            # imm = 0x140
jb 0xc10b
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 0x164ba
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x16c48
movq %rax, %r13
cmpq 0x108(%rsp), %rax
je 0xc054
movq 0x70(%rsp), %rax
movq %rbx, 0x88(%rsp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x164ba
movq 0x88(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x30d0
movq 0x50(%r13), %rcx
movl $0x2, %ebp
testq %rcx, %rcx
je 0xc0c1
addq $0x48, %r13
movq %r13, %rbx
xorl %edx, %edx
cmpq %rax, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rbx
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0xbea7
cmpq %r13, %rbx
je 0xc0c1
cmpq 0x20(%rbx), %rax
jb 0xc0c1
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x164ba
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x164ba
movq %r14, %r13
movl $0x4, 0x4(%rsp)
leaq 0xf8(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x164ba
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x14414
movl %eax, %r13d
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xbf74
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
movl $0x1, %ebp
testb %r13b, %r13b
je 0xc089
movl $0x4, (%rsp)
leaq 0xd8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %r13
movq %r12, %rdi
callq 0x164ba
movq %r13, %rdi
movq %rsp, %rsi
callq 0x14414
movl %eax, %r13d
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xbfe4
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3290
movl $0x1, %ebp
testb %r13b, %r13b
je 0xc089
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 0xc05e
testq %rax, %rax
je 0xc05e
movq 0x70(%rbx), %rdx
xorl %ebp, %ebp
movl $0x1, %r8d
xorl %esi, %esi
leaq 0xda69(%rip), %rcx      # 0x19ab6
callq 0x33a0
jmp 0xc089
movl $0x2, %ebp
jmp 0xc0e6
orq %r13, %rax
je 0xc07b
testq %r13, %r13
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rax
cmovneq %rax, %rsi
callq 0x3160
jmp 0xc087
leaq 0xd58e(%rip), %rsi      # 0x19610
callq 0x3330
xorl %ebp, %ebp
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xc0a5
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xc0c1
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rbx
cmpq %rbx, %rdi
je 0xc0e6
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xc10b
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x70(%rsp), %rdi
callq 0x146d2
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xc131
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
testb $0x1, %bpl
jne 0xbd3e
movq 0x110(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x130(%rsp,%rax)
leaq 0x110(%rsp), %r13
je 0xbd76
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 0xc1dd
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xc1e0
movq 0xd8(%rsp), %rsi
jmp 0xc1d3
jmp 0xc1dd
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xc1e0
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc1e0
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xc201
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc201
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xc222
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc222
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xc24e
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc24e
jmp 0xc24b
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xc278
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xc278
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x146d2
jmp 0xc290
jmp 0xc28d
jmp 0xc288
movq %rax, %rbx
jmp 0xc2ac
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xc2ac
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x110(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3460