// File: /workspace/github_cpp_makefile_star2_O3/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 0xf361
movq %rdi, %rax
movq 0x18(%rdi), %r12
addq $0x8, %rax
movq %rax, 0x88(%rsp)
cmpq %rax, %r12
je 0xf361
leaq 0x8(%rsp), %r15
leaq 0x28(%r12), %r14
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x14816
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x164ba
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x164ba
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x164ba
cmpq $0x0, 0x30(%rsp)
je 0xf24a
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 0xaa75(%rip), %rsi      # 0x19b82
callq 0x30b0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf130
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
testl %ebp, %ebp
je 0xf1d2
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x32b0
movq %r15, %rdi
leaq 0xaa44(%rip), %rsi      # 0x19b9b
callq 0x30b0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf17a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
testl %ebp, %ebp
jne 0xf23c
movq 0x70(%r12), %rdx
movl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
leaq 0xa9e9(%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 0xf220
movq 0x70(%r12), %rdx
movl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
leaq 0xa9b2(%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 0xf23c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
incq %rbx
cmpq 0x30(%rsp), %rbx
jb 0xf0ee
leaq 0x48(%r12), %rdi
movq 0x50(%r12), %rdx
movl $0x1, %r8d
xorl %esi, %esi
leaq 0xa938(%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 0xf28f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf2ab
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf2c7
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0xf2e4
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xf309
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xf32e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xf353
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3290
cmpq 0x88(%rsp), %r12
jne 0xf051
movb $0x1, %al
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf3b4
movq %rax, %rbx
jmp 0xf40b
movq %rax, %rbx
jmp 0xf3ef
movq %rax, %rbx
jmp 0xf3d3
jmp 0xf38d
jmp 0xf3b4
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf3b7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0xf3b7
jmp 0xf3b4
jmp 0xf3b4
jmp 0xf3b4
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf3d3
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf3ef
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf40b
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xa0(%rsp), %rdi
callq 0x1466e
movq %rbx, %rdi
callq 0x3460