// File: /workspace/github_cpp_makefile_star2_O2/schneebergerlab[P]GameteBinning/asPollinator_1.0.cpp
// Function: flip_pcluster(std::map<int, POLLEN, std::less<int>, std::allocator<std::pair<int const, POLLEN>>>*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool flip_pcluster(map<int, POLLEN>* paCluster, string matGT, string patGT)
{
    /*
      struct POLLEN
      {
          string poSeq;   // seq at markers for pollen haplotype
          string poAll;   // over all, can be determined as 'M', 'P', 'MP', 'PM', or 'N'
          string poPat;   // string like MMMMMMppMMMMMMMpMMMMMMMM: indicating parental genotypes
          vector<unsigned long> mkrpos; // position of markers for this contig
      };    
    */
    if((*paCluster).size()==0) return true;
    //
    map<int, POLLEN>::iterator ppitr;
    map<int, POLLEN>::iterator ppitr_end;
    ppitr     = (*paCluster).begin();
    ppitr_end = (*paCluster).end();
    while(ppitr != ppitr_end)
    {
        POLLEN ptmp = (*ppitr).second;
        
        string poSeq = ptmp.poSeq;
        string poAll = ptmp.poAll;
        string poPat = ptmp.poPat;
        
        for(unsigned long ii = 0; ii < poPat.size(); ii ++)
        {
            if(poPat.substr(ii, 1).compare("P") == 0)
            {
                // flipping pattern
                (*ppitr).second.poPat = "M";
                (*ppitr).second.poSeq.replace(ii, 1, matGT.substr(ii, 1));
            }else
            if(poPat.substr(ii, 1).compare("M") == 0)
            {
                // flipping pattern
                (*ppitr).second.poPat = "P";
                (*ppitr).second.poSeq.replace(ii, 1, patGT.substr(ii, 1));                
            }else ;           
        }
        //
        (*ppitr).second.poAll = "M";
                
        // next paternal pollen
        ppitr ++;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
cmpq $0x0, 0x28(%rdi)
je 0xaa1d
movq %rdi, %rax
movq 0x18(%rdi), %r14
addq $0x8, %rax
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %r15
pushq $0x1
popq %r12
cmpq 0x8(%rsp), %r14
je 0xaa1d
leaq 0x28(%r14), %rsi
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, (%rsp)
callq 0xe396
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x3300
leaq 0x60(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3300
leaq 0x20(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3300
leaq 0x68(%r14), %rbx
xorl %r13d, %r13d
cmpq 0x28(%rsp), %r13
jae 0xa9cf
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3290
movq %r15, %rdi
leaq 0x9270(%rip), %rsi      # 0x13b82
callq 0x30c0
movl %eax, %ebp
movq %r15, %rdi
callq 0x3120
testl %ebp, %ebp
je 0xa98b
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3290
movq %r15, %rdi
leaq 0x9259(%rip), %rsi      # 0x13b9b
callq 0x30c0
movl %eax, %ebp
movq %r15, %rdi
callq 0x3120
testl %ebp, %ebp
jne 0xa9c7
movq %rbx, %rdi
leaq 0x9223(%rip), %rsi      # 0x13b82
callq 0x3440
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3290
movq (%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x30f0
jmp 0xa9bf
movq %rbx, %rdi
leaq 0x9206(%rip), %rsi      # 0x13b9b
callq 0x3440
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3290
movq (%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x30f0
movq %r15, %rdi
callq 0x3120
incq %r13
jmp 0xa8ea
leaq 0x48(%r14), %rdi
leaq 0x91c1(%rip), %rsi      # 0x13b9b
callq 0x3440
movq %r14, %rdi
callq 0x31c0
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x3120
leaq 0x60(%rsp), %rdi
callq 0x3120
leaq 0x80(%rsp), %rdi
callq 0x3120
leaq 0xa0(%rsp), %rdi
callq 0xe2b0
jmp 0xa88c
movb $0x1, %al
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaa5b
movq %rax, %rbx
jmp 0xaa7f
movq %rax, %rbx
jmp 0xaa72
movq %rax, %rbx
jmp 0xaa68
jmp 0xaa46
jmp 0xaa5b
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3120
jmp 0xaa5e
jmp 0xaa5b
jmp 0xaa5b
jmp 0xaa5b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3120
leaq 0x60(%rsp), %rdi
callq 0x3120
leaq 0x80(%rsp), %rdi
callq 0x3120
leaq 0xa0(%rsp), %rdi
callq 0xe2b0
movq %rbx, %rdi
callq 0x3410