// File: /workspace/github_cpp_makefile_star2_O1/schneebergerlab[P]GameteBinning/asPollinator_1.0.cpp
// Function: cluster_pollens(std::map<int, POLLEN, std::less<int>, std::allocator<std::pair<int const, POLLEN>>>, std::map<int, POLLEN, std::less<int>, std::allocator<std::pair<int const, POLLEN>>>*, std::map<int, POLLEN, std::less<int>, std::allocator<std::pair<int const, POLLEN>>>*, std::map<int, POLLEN, std::less<int>, std::allocator<std::pair<int const, POLLEN>>>*, std::map<int, POLLEN, std::less<int>, std::allocator<std::pair<int const, POLLEN>>>*)
bool cluster_pollens(map<int, POLLEN>  pollens, 
                     map<int, POLLEN>* maCluster,
                     map<int, POLLEN>* paCluster,
                     map<int, POLLEN>* unCluster,
                     map<int, POLLEN>* pollens_updated)
{
    // idea: using initial haplotypes related to a contig as backbone, 
    //       1.color   pollen genotypes
    //       2.cluster pollen genotypes
    //       3.correct haplotypes
    assert(pollens.find(0) != pollens.end());
    string matGT = pollens[0].poSeq; // maternal backbone
    string patGT = pollens[0].poAll; // paternal backbone
    //
    // map<int, POLLEN> maCluster; // close to maternal GT
    // map<int, POLLEN> paCluster; // close to paternal GT
    // map<int, POLLEN> unCluster; // not informative 
    //
    map<int, POLLEN>::iterator pollenitr;
    map<int, POLLEN>::iterator pollenitr_end;
    pollenitr        = pollens.begin();
    pollenitr_end    = pollens.end();
    while(pollenitr != pollenitr_end)
    {
        int     pid  = (*pollenitr).first;
        POLLEN ptmp  = (*pollenitr).second;
        if(pid>0)
        {
            string        pollenGT = ((*pollenitr).second).poSeq;
            string        pattern  = "";                   
            unsigned long matscore = 0; 
            unsigned long patscore = 0;
            if( !get_similarty(matGT,
                               patGT,
                               pollenGT,
                               &pattern,
                               &matscore,
                               &patscore) )
            {
                return false;
            }
            // updating attribute pattern of pollen
            ((*pollenitr).second).poPat = pattern;
            // setting  attribute pattern of pollen
            ptmp.poPat = pattern;  
            //
            if(matscore  > patscore)
            {
                (*maCluster).insert(std::pair<int, POLLEN>(pid, ptmp));
            }
            else
            if(matscore  < patscore)
            {
                (*paCluster).insert(std::pair<int, POLLEN>(pid, ptmp));
            }else
            if(matscore == patscore)
            {
                (*unCluster).insert(std::pair<int, POLLEN>(pid, ptmp));
            }else ;
        }
        pollenitr ++;
    }
    // get pattern inserted in pollen data - new
    (*pollens_updated) = pollens;
    //
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %r8, %r15
movq %rcx, 0x188(%rsp)
movq %rdx, 0x190(%rsp)
movq %rsi, 0x198(%rsp)
movq 0x10(%rdi), %rcx
movq %rdi, 0x8(%rsp)
leaq 0x8(%rdi), %r14
movq %r14, %rax
testq %rcx, %rcx
je 0xea18
movq %r14, %rax
movl 0x20(%rcx), %edx
testl %edx, %edx
cmovnsq %rcx, %rax
shrl $0x1f, %edx
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0xea02
movq %r14, %rcx
cmpq %r14, %rax
je 0xea2b
cmpl $0x0, 0x20(%rax)
cmovgq %r14, %rax
movq %rax, %rcx
cmpq %r14, %rcx
je 0xefb5
xorl %ebp, %ebp
leaq 0x60(%rsp), %rbx
movl %ebp, (%rbx)
movq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x14806
leaq 0x150(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x140(%rsp), %rdi
callq 0x16592
movl %ebp, (%rbx)
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
callq 0x14806
leaq 0x130(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq 0x120(%rsp), %rdi
callq 0x16592
movq %r15, 0x180(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rbx
cmpq %r14, %rbx
sete %bpl
je 0xee78
leaq 0x160(%rsp), %r15
movl 0x20(%rbx), %r12d
leaq 0x28(%rbx), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x148ea
testl %r12d, %r12d
jle 0xedd4
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x16592
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0xb3ad(%rip), %rdx      # 0x19ec9
movq %rdx, %rsi
callq 0x16622
xorl %eax, %eax
movq %rax, 0x58(%rsp)
movq %rax, 0x50(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x140(%rsp), %rsi
movq 0x148(%rsp), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %rdi
callq 0x16592
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x120(%rsp), %rsi
movq 0x128(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x16592
leaq 0x170(%rsp), %rax
movq %rax, 0x160(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
movq %r15, %r13
movq %r15, %rdi
callq 0x16592
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movq %r13, %rdx
leaq 0x10(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x50(%rsp), %r9
callq 0x1440d
movl %eax, %r13d
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0xec07
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xec2c
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0xec51
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x3290
testb %r13b, %r13b
je 0xee8f
leaq 0x68(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3160
leaq 0x1e0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3160
movq 0x58(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpq %rcx, %rax
jbe 0xecb4
movl %r12d, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x148ea
movq 0x198(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x16878
jmp 0xed10
jae 0xece1
movl %r12d, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x148ea
movq 0x190(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x16878
jmp 0xed10
jne 0xed93
movl %r12d, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x148ea
movq 0x188(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x16878
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0xed2d
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xed52
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xed77
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xed93
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xedaf
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xedcb
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
testb %r13b, %r13b
je 0xeec7
movq %rbx, %rdi
callq 0x31c0
movq %rax, %rbx
movq 0x200(%rsp), %rdi
testq %rdi, %rdi
je 0xedfc
movq 0x210(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x1e0(%rsp), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0xee21
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x1c0(%rsp), %rdi
leaq 0x1d0(%rsp), %rax
cmpq %rax, %rdi
je 0xee46
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0xee6b
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x3290
cmpq %r14, %rbx
sete %bpl
jne 0xeac9
movq 0x180(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x154be
jmp 0xef53
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xeeab
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xeec7
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x200(%rsp), %rdi
testq %rdi, %rdi
je 0xeee4
movq 0x210(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x1e0(%rsp), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0xef09
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x1c0(%rsp), %rdi
leaq 0x1d0(%rsp), %rax
cmpq %rax, %rdi
je 0xef2e
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0xef53
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0xef78
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0xef9d
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x3290
andb $0x1, %bpl
movl %ebp, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb082(%rip), %rdi      # 0x1a03e
leaq 0xab08(%rip), %rsi      # 0x19acb
leaq 0xb095(%rip), %rcx      # 0x1a05f
movl $0x98e, %edx            # imm = 0x98E
callq 0x3180
jmp 0xf08e
jmp 0xefef
jmp 0xf093
jmp 0xefef
jmp 0xf093
movq %rax, %rbx
jmp 0xf100
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x14666
jmp 0xf096
jmp 0xf093
movq %rax, %rbx
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0xf033
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xf033
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xf05d
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xf05d
movq %rax, %rbx
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0xf096
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xf096
movq %rax, %rbx
jmp 0xf0b2
movq %rax, %rbx
jmp 0xf0ce
movq %rax, %rbx
jmp 0xf0db
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xf0b2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xf0ce
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x1a0(%rsp), %rdi
callq 0x14746
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0xf100
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0xf125
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3460