// File: /workspace/github_cpp_makefile_star2_O2/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 $0x228, %rsp            # imm = 0x228
movq %r8, %rbx
movq %rcx, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, %r14
leaq 0x70(%rsp), %rsi
andl $0x0, (%rsi)
callq 0x118c2
leaq 0x8(%r14), %rcx
movq %rcx, 0x10(%rsp)
cmpq %rcx, %rax
je 0xa77d
movq %rbx, 0x30(%rsp)
leaq 0x70(%rsp), %rbx
andl $0x0, (%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xe2fa
leaq 0x110(%rsp), %rdi
movq %rax, %rsi
callq 0x3300
andl $0x0, (%rbx)
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0xe2fa
addq $0x20, %rax
leaq 0xf0(%rsp), %rdi
movq %rax, %rsi
callq 0x3300
movq %r14, 0x28(%rsp)
movq 0x18(%r14), %r12
leaq 0x150(%rsp), %rbp
leaq 0x208(%rsp), %r14
cmpq 0x10(%rsp), %r12
je 0xa70d
movl 0x20(%r12), %ebx
movq %r12, 0x8(%rsp)
leaq 0x28(%r12), %r13
leaq 0x170(%rsp), %rdi
movq %r13, %rsi
callq 0xe396
movl %ebx, 0x4(%rsp)
testl %ebx, %ebx
jle 0xa6ee
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x3300
movq %rbp, %rdi
leaq 0x9943(%rip), %rsi      # 0x13ec7
leaq 0x70(%rsp), %rdx
callq 0xe174
andq $0x0, 0x20(%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x3300
movq %r14, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x3300
movq %r14, %r12
leaq 0x1e8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
callq 0x3300
leaq 0x130(%rsp), %r14
movq %r14, %rdi
movq %r12, %r15
movq %r12, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
leaq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
callq 0xdfc7
movl %eax, %r13d
movq %rbx, %rdi
callq 0x3120
movq %r15, %rdi
callq 0x3120
movq %r14, %rdi
callq 0x3120
testb %r13b, %r13b
je 0xa71e
movq 0x8(%rsp), %rax
leaq 0x68(%rax), %rdi
movq %rbp, %rsi
callq 0x3170
movq %r12, %r14
leaq 0x1b0(%rsp), %rdi
movq %rbp, %rsi
callq 0x3170
movq 0x18(%rsp), %rax
cmpq %rax, 0x20(%rsp)
jbe 0xa67c
movl 0x4(%rsp), %eax
movl %eax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0xe396
movq 0x48(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xffe6
jmp 0xa6d2
jae 0xa6a9
movl 0x4(%rsp), %eax
movl %eax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0xe396
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xffe6
jmp 0xa6d2
movl 0x4(%rsp), %eax
movl %eax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0xe396
movq 0x40(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xffe6
leaq 0x78(%rsp), %rdi
callq 0xe2b0
movq %rbp, %rdi
callq 0x3120
leaq 0x50(%rsp), %rdi
callq 0x3120
movq 0x8(%rsp), %rdi
callq 0x31c0
movq %rax, %r12
leaq 0x170(%rsp), %rdi
callq 0xe2b0
jmp 0xa537
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0xec9a
jmp 0xa747
leaq 0x150(%rsp), %rdi
callq 0x3120
leaq 0x50(%rsp), %rdi
callq 0x3120
leaq 0x170(%rsp), %rdi
callq 0xe2b0
movq 0x8(%rsp), %r12
cmpq 0x10(%rsp), %r12
sete %bl
leaq 0xf0(%rsp), %rdi
callq 0x3120
leaq 0x110(%rsp), %rdi
callq 0x3120
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x98b8(%rip), %rdi      # 0x1403c
leaq 0x9340(%rip), %rsi      # 0x13acb
leaq 0x98cb(%rip), %rcx      # 0x1405d
movl $0x98e, %edx            # imm = 0x98E
callq 0x3190
jmp 0xa7ff
movq %rax, %rbx
jmp 0xa838
jmp 0xa7ae
jmp 0xa804
jmp 0xa7ae
jmp 0xa804
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xe2b0
jmp 0xa807
jmp 0xa804
movq %rax, %rbx
jmp 0xa7f0
movq %rax, %rbx
jmp 0xa814
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0x3120
jmp 0xa7e3
movq %rax, %rbx
jmp 0xa81e
movq %rax, %rbx
leaq 0x208(%rsp), %rdi
callq 0x3120
leaq 0x130(%rsp), %rdi
callq 0x3120
jmp 0xa807
movq %rax, %rbx
jmp 0xa82b
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x3120
leaq 0x50(%rsp), %rdi
callq 0x3120
leaq 0x170(%rsp), %rdi
callq 0xe2b0
leaq 0xf0(%rsp), %rdi
callq 0x3120
leaq 0x110(%rsp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3410