// File: 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:
subq $0x208, %rsp            # imm = 0x208
movq %rsi, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq %rdi, 0x1f8(%rsp)
movq %rsi, 0x1f0(%rsp)
movq %rdx, 0x1e8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x19740
cmpq $0x0, %rax
jne 0x11469
movb $0x1, 0x207(%rsp)
jmp 0x118b4
leaq 0x1e0(%rsp), %rdi
callq 0x19200
leaq 0x1d8(%rsp), %rdi
callq 0x19200
movq 0x1f8(%rsp), %rdi
callq 0x19220
movq %rax, 0x1d0(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x1e0(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x19250
movq %rax, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
leaq 0x1e0(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x19280
testb $0x1, %al
jne 0x114eb
jmp 0x118ac
leaq 0x1e0(%rsp), %rdi
callq 0x192a0
movq %rax, %rsi
addq $0x8, %rsi
leaq 0x150(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x192c0
movq 0x38(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x3160
jmp 0x11525
leaq 0x170(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x3160
jmp 0x1153c
leaq 0x190(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x3160
jmp 0x11553
movq $0x0, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x3250
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x11807
movq 0xd8(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl $0x1, %ecx
callq 0x3350
jmp 0x115ae
leaq 0xb8(%rsp), %rdi
leaq 0x1a55d(%rip), %rsi     # 0x2bb1a
callq 0x3100
movl %eax, 0x2c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x31e0
movl 0x2c(%rsp), %eax
cmpl $0x0, %eax
jne 0x116f8
leaq 0x1e0(%rsp), %rdi
callq 0x192a0
movq %rax, %rdi
addq $0x48, %rdi
leaq 0x1a538(%rip), %rsi     # 0x2bb33
callq 0x3440
jmp 0x11602
leaq 0x1e0(%rsp), %rdi
callq 0x192a0
movq 0x40(%rsp), %rsi
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0xd8(%rsp), %rdx
movq %rdx, 0x20(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x1, %ecx
callq 0x3350
jmp 0x1163e
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
movl $0x1, %edx
leaq 0x98(%rsp), %rcx
callq 0x3130
jmp 0x1165c
leaq 0x98(%rsp), %rdi
callq 0x31e0
jmp 0x117ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x1189d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x11890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x11883
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x11876
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x31e0
jmp 0x11876
movq 0xd8(%rsp), %rdx
leaq 0x78(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl $0x1, %ecx
callq 0x3350
jmp 0x11719
leaq 0x78(%rsp), %rdi
leaq 0x1a40e(%rip), %rsi     # 0x2bb33
callq 0x3100
movl %eax, 0x14(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x31e0
movl 0x14(%rsp), %eax
cmpl $0x0, %eax
jne 0x117e8
leaq 0x1e0(%rsp), %rdi
callq 0x192a0
movq %rax, %rdi
addq $0x48, %rdi
leaq 0x1a3ba(%rip), %rsi     # 0x2bb1a
callq 0x3440
jmp 0x11767
leaq 0x1e0(%rsp), %rdi
callq 0x192a0
movq 0x48(%rsp), %rsi
addq $0x8, %rax
movq %rax, (%rsp)
movq 0xd8(%rsp), %rdx
movq %rdx, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
movl $0x1, %ecx
callq 0x3350
jmp 0x1179f
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
movl $0x1, %edx
leaq 0x58(%rsp), %rcx
callq 0x3130
jmp 0x117b9
leaq 0x58(%rsp), %rdi
callq 0x31e0
jmp 0x117ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x31e0
jmp 0x11876
jmp 0x117ea
jmp 0x117ec
jmp 0x117ee
movq 0xd8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
jmp 0x1155f
leaq 0x1e0(%rsp), %rdi
callq 0x192a0
movq %rax, %rdi
addq $0x28, %rdi
leaq 0x1a311(%rip), %rsi     # 0x2bb33
callq 0x3440
jmp 0x11829
leaq 0x1e0(%rsp), %rdi
xorl %esi, %esi
callq 0x193a0
movq %rax, 0x50(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x31e0
leaq 0x100(%rsp), %rdi
callq 0x31e0
leaq 0x130(%rsp), %rdi
callq 0x31e0
leaq 0x150(%rsp), %rdi
callq 0x18df0
jmp 0x114cd
leaq 0xe0(%rsp), %rdi
callq 0x31e0
leaq 0x100(%rsp), %rdi
callq 0x31e0
leaq 0x130(%rsp), %rdi
callq 0x31e0
leaq 0x150(%rsp), %rdi
callq 0x18df0
jmp 0x118c5
movb $0x1, 0x207(%rsp)
movb 0x207(%rsp), %al
andb $0x1, %al
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x128(%rsp), %rdi
callq 0x3560
nopw %cs:(%rax,%rax)