// File: /workspace/github_cpp_makefile_star2_O1/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, 0x90(%rsp)
movq %rsi, 0x98(%rsp)
cmpq $0x0, 0x28(%rdi)
je 0xf48a
movq %rdi, %rax
movq 0x18(%rdi), %r12
addq $0x8, %rax
movq %rax, 0x88(%rsp)
cmpq %rax, %r12
je 0xf48a
leaq 0x8(%rsp), %r15
leaq 0x28(%r12), %r14
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x148ea
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x16592
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x16592
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x16592
cmpq $0x0, 0x30(%rsp)
je 0xf373
leaq 0x68(%r12), %r13
xorl %ebx, %ebx
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x32b0
movq %r15, %rdi
leaq 0xa94c(%rip), %rsi      # 0x19b82
callq 0x30b0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf259
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
testl %ebp, %ebp
je 0xf2fb
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x32b0
movq %r15, %rdi
leaq 0xa91b(%rip), %rsi      # 0x19b9b
callq 0x30b0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf2a3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
testl %ebp, %ebp
jne 0xf365
movq 0x70(%r12), %rdx
movl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
leaq 0xa8c0(%rip), %rcx      # 0x19b82
callq 0x33a0
movl $0x1, %ecx
movq %r15, %rdi
movq 0x90(%rsp), %rsi
movq %rbx, %rdx
callq 0x32b0
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32d0
jmp 0xf349
movq 0x70(%r12), %rdx
movl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
leaq 0xa889(%rip), %rcx      # 0x19b9b
callq 0x33a0
movl $0x1, %ecx
movq %r15, %rdi
movq 0x98(%rsp), %rsi
movq %rbx, %rdx
callq 0x32b0
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32d0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf365
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
incq %rbx
cmpq 0x30(%rsp), %rbx
jb 0xf217
leaq 0x48(%r12), %rdi
movq 0x50(%r12), %rdx
movl $0x1, %r8d
xorl %esi, %esi
leaq 0xa80f(%rip), %rcx      # 0x19b9b
callq 0x33a0
movq %r12, %rdi
callq 0x31c0
movq %rax, %r12
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf3b8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf3d4
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf3f0
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0xf40d
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xf432
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xf457
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xf47c
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3290
cmpq 0x88(%rsp), %r12
jne 0xf17a
movb $0x1, %al
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf4dd
movq %rax, %rbx
jmp 0xf534
movq %rax, %rbx
jmp 0xf518
movq %rax, %rbx
jmp 0xf4fc
jmp 0xf4b6
jmp 0xf4dd
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf4e0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xf4e0
jmp 0xf4dd
jmp 0xf4dd
jmp 0xf4dd
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf4fc
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf518
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf534
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xa0(%rsp), %rdi
callq 0x14746
movq %rbx, %rdi
callq 0x3460