// File: schneebergerlab[P]DrLink/detect_recombsite.cpp
// Function: get_break_pos_of_artSeq(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::map<unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>, int, unsigned long*, unsigned long*, int*, double*)
bool get_break_pos_of_artSeq(string                     artSeq, 
                             map<unsigned long, string> artSeqPos, 
                             int                        min_marker,
                             unsigned long*             leftp, 
                             unsigned long*             rightp, 
                             int*                       bpPos,
                             double*                    score)
{
    *score  = 0.0;
    map<unsigned long, string>::iterator pitr;
    pitr = artSeqPos.begin();
    int i = 0;
    while(i < min_marker)
    {
        pitr ++;
        i ++;
    }
    for(size_t mi = min_marker; mi <= artSeq.size()-min_marker; mi ++)
    {
        string strLef = artSeq.substr(0, mi); // val @ pos of 0,...,mi-1
        string strRig = artSeq.substr(mi);    // val @ pos of mi,mi+1,...
        // current break point
        size_t c1Lef = std::count(strLef.begin(), strLef.end(), '1'); // L1
        size_t c2Lef = strLef.size()-c1Lef;                           // L2
        size_t c1Rig = std::count(strRig.begin(), strRig.end(), '1'); // R1
        size_t c2Rig = strRig.size()-c1Rig;                           // R2
        
        double af1Lef = (double)c1Lef/strLef.size();
        double af2Lef = (double)c2Lef/strLef.size();
        
        double af1Rig = (double)c1Rig/strRig.size();
        double af2Rig = (double)c2Rig/strRig.size();
        
        double score1 = af1Lef * af2Rig;
        double score2 = af2Lef * af1Rig;
        
        double scotmp = score1>score2?score1:score2;
        
        if(scotmp > *score)
        {
            *score  = scotmp;
            pitr --;
            *leftp  = (*pitr).first;
            pitr ++; 
            *rightp = (*pitr).first;
            *bpPos  = mi;
            if(*rightp == *leftp)
            {
                cout << "   artSeq  ="  << artSeq    << "\n"
                     << "   mi    ="  << *bpPos  << "\n"
                     << "   leftp ="  << *leftp  << "\n"
                     << "   rightp="  << *rightp << "\n" << endl;
                cout << "   positions related to artSeq: " << "\n   ";
                for(map<unsigned long, string>::iterator itr = artSeqPos.begin(); 
                    itr != artSeqPos.end(); 
                    itr ++) 
                {
                    cout << (*itr).first << " ";
                }
                cout << "\n   Error-must-fix: molecule separated at the same position -- impossible! " 
                     << endl;
                //return false;
            }
        }
        //
        pitr ++;
    }
    return true;
}

// Assembly:
subq $0x278, %rsp            # imm = 0x278
movq %rsi, 0x110(%rsp)
movq %rdi, 0x108(%rsp)
movq 0x280(%rsp), %rax
movq %rdi, 0x270(%rsp)
movq %rsi, 0x268(%rsp)
movl %edx, 0x264(%rsp)
movq %rcx, 0x258(%rsp)
movq %r8, 0x250(%rsp)
movq %r9, 0x248(%rsp)
movq 0x280(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x240(%rsp), %rdi
callq 0x2d840
movq 0x110(%rsp), %rdi
callq 0x2d860
movq %rax, 0x238(%rsp)
movq 0x238(%rsp), %rax
movq %rax, 0x240(%rsp)
movl $0x0, 0x234(%rsp)
movl 0x234(%rsp), %eax
cmpl 0x264(%rsp), %eax
jge 0x29294
leaq 0x240(%rsp), %rdi
xorl %esi, %esi
callq 0x2da40
movq %rax, 0x228(%rsp)
movl 0x234(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x234(%rsp)
jmp 0x2925a
movslq 0x264(%rsp), %rax
movq %rax, 0x220(%rsp)
movq 0x108(%rsp), %rdi
movq 0x220(%rsp), %rax
movq %rax, 0x100(%rsp)
callq 0x5310
movq %rax, %rcx
movq 0x100(%rsp), %rax
movslq 0x264(%rsp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
ja 0x29a4e
movq 0x108(%rsp), %rsi
movq 0x220(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x200(%rsp), %rdi
callq 0x5490
movq 0x108(%rsp), %rsi
movq 0x220(%rsp), %rdx
leaq 0x1e0(%rsp), %rdi
movq $-0x1, %rcx
callq 0x5490
jmp 0x29327
leaq 0x200(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0x53c0
movq 0xf0(%rsp), %rdi
movq %rax, 0x1c0(%rsp)
callq 0x5280
movq %rax, 0x1b8(%rsp)
movb $0x31, 0x1b7(%rsp)
movq 0x1c0(%rsp), %rdi
movq 0x1b8(%rsp), %rsi
leaq 0x1b7(%rsp), %rdx
callq 0x2db90
movq %rax, 0xf8(%rsp)
jmp 0x29388
movq 0xf8(%rsp), %rax
movq %rax, 0x1c8(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x5310
movq 0x1c8(%rsp), %rcx
subq %rcx, %rax
movq %rax, 0x1a8(%rsp)
leaq 0x1e0(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x53c0
movq 0xe0(%rsp), %rdi
movq %rax, 0x198(%rsp)
callq 0x5280
movq %rax, 0x190(%rsp)
movb $0x31, 0x18f(%rsp)
movq 0x198(%rsp), %rdi
movq 0x190(%rsp), %rsi
leaq 0x18f(%rsp), %rdx
callq 0x2db90
movq %rax, 0xe8(%rsp)
jmp 0x29419
movq 0xe8(%rsp), %rax
movq %rax, 0x1a0(%rsp)
leaq 0x1e0(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x5310
movq 0x1a0(%rsp), %rcx
subq %rcx, %rax
movq %rax, 0x180(%rsp)
movq 0x1c8(%rsp), %xmm0
movaps 0x3dc6f(%rip), %xmm1    # 0x670d0
movaps %xmm1, 0xb0(%rsp)
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3dc6b(%rip), %xmm1    # 0x670e0
movaps %xmm1, 0xc0(%rsp)
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
leaq 0x200(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x5310
movsd 0x88(%rsp), %xmm0
movq 0x90(%rsp), %rdi
movaps 0xb0(%rsp), %xmm2
movaps 0xc0(%rsp), %xmm1
movq %rax, %xmm3
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
subpd %xmm1, %xmm3
movaps %xmm3, %xmm4
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm4, %xmm3
divsd %xmm3, %xmm0
movsd %xmm0, 0x178(%rsp)
movq 0x1a8(%rsp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
callq 0x5310
movsd 0x98(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
movaps 0xb0(%rsp), %xmm2
movaps 0xc0(%rsp), %xmm1
movq %rax, %xmm3
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
subpd %xmm1, %xmm3
movaps %xmm3, %xmm4
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm4, %xmm3
divsd %xmm3, %xmm0
movsd %xmm0, 0x170(%rsp)
movq 0x1a0(%rsp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
callq 0x5310
movsd 0xa0(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
movaps 0xb0(%rsp), %xmm2
movaps 0xc0(%rsp), %xmm1
movq %rax, %xmm3
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
subpd %xmm1, %xmm3
movaps %xmm3, %xmm4
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm4, %xmm3
divsd %xmm3, %xmm0
movsd %xmm0, 0x168(%rsp)
movq 0x180(%rsp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
callq 0x5310
movaps 0xb0(%rsp), %xmm3
movaps 0xc0(%rsp), %xmm2
movsd 0xd8(%rsp), %xmm0
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x160(%rsp)
movsd 0x178(%rsp), %xmm0
mulsd 0x160(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
movsd 0x170(%rsp), %xmm0
mulsd 0x168(%rsp), %xmm0
movsd %xmm0, 0x150(%rsp)
movsd 0x158(%rsp), %xmm0
ucomisd 0x150(%rsp), %xmm0
jbe 0x29696
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
jmp 0x296a8
movsd 0x150(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x148(%rsp)
movsd 0x148(%rsp), %xmm0
movq 0x280(%rsp), %rax
ucomisd (%rax), %xmm0
jbe 0x299f5
movsd 0x148(%rsp), %xmm0
movq 0x280(%rsp), %rax
movsd %xmm0, (%rax)
leaq 0x240(%rsp), %rdi
xorl %esi, %esi
callq 0x2e290
movq %rax, 0x140(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x2d890
movq (%rax), %rcx
movq 0x258(%rsp), %rax
movq %rcx, (%rax)
leaq 0x240(%rsp), %rdi
xorl %esi, %esi
callq 0x2da40
movq %rax, 0x138(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x2d890
movq (%rax), %rcx
movq 0x250(%rsp), %rax
movq %rcx, (%rax)
movq 0x220(%rsp), %rax
movl %eax, %ecx
movq 0x248(%rsp), %rax
movl %ecx, (%rax)
movq 0x250(%rsp), %rax
movq (%rax), %rax
movq 0x258(%rsp), %rcx
cmpq (%rcx), %rax
jne 0x299f3
movq 0x5b843(%rip), %rdi     # 0x84fc8
leaq 0x3f395(%rip), %rsi     # 0x68b21
callq 0x5460
movq %rax, 0x78(%rsp)
jmp 0x29798
movq 0x108(%rsp), %rsi
movq 0x78(%rsp), %rdi
callq 0x53e0
movq %rax, 0x70(%rsp)
jmp 0x297b1
movq 0x70(%rsp), %rdi
leaq 0x40775(%rip), %rsi     # 0x69f32
callq 0x5460
movq %rax, 0x68(%rsp)
jmp 0x297c9
movq 0x68(%rsp), %rdi
leaq 0x3f359(%rip), %rsi     # 0x68b2e
callq 0x5460
movq %rax, 0x60(%rsp)
jmp 0x297e1
movq 0x60(%rsp), %rdi
movq 0x248(%rsp), %rax
movl (%rax), %esi
callq 0x5790
movq %rax, 0x58(%rsp)
jmp 0x297fc
movq 0x58(%rsp), %rdi
leaq 0x4072a(%rip), %rsi     # 0x69f32
callq 0x5460
movq %rax, 0x50(%rsp)
jmp 0x29814
movq 0x50(%rsp), %rdi
leaq 0x3f319(%rip), %rsi     # 0x68b39
callq 0x5460
movq %rax, 0x48(%rsp)
jmp 0x2982c
movq 0x48(%rsp), %rdi
movq 0x258(%rsp), %rax
movq (%rax), %rsi
callq 0x50f0
movq %rax, 0x40(%rsp)
jmp 0x29848
movq 0x40(%rsp), %rdi
leaq 0x406de(%rip), %rsi     # 0x69f32
callq 0x5460
movq %rax, 0x38(%rsp)
jmp 0x29860
movq 0x38(%rsp), %rdi
leaq 0x3f2d8(%rip), %rsi     # 0x68b44
callq 0x5460
movq %rax, 0x30(%rsp)
jmp 0x29878
movq 0x30(%rsp), %rdi
movq 0x250(%rsp), %rax
movq (%rax), %rsi
callq 0x50f0
movq %rax, 0x28(%rsp)
jmp 0x29894
movq 0x28(%rsp), %rdi
leaq 0x40692(%rip), %rsi     # 0x69f32
callq 0x5460
movq %rax, 0x20(%rsp)
jmp 0x298ac
movq 0x20(%rsp), %rdi
movq 0x5b6f8(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x298bf
movq 0x5b702(%rip), %rdi     # 0x84fc8
leaq 0x3f282(%rip), %rsi     # 0x68b4f
callq 0x5460
movq %rax, 0x18(%rsp)
jmp 0x298d9
movq 0x18(%rsp), %rdi
leaq 0x3f28b(%rip), %rsi     # 0x68b70
callq 0x5460
jmp 0x298ec
movq 0x110(%rsp), %rdi
callq 0x2d860
movq %rax, 0x130(%rsp)
movq 0x110(%rsp), %rdi
callq 0x2d610
movq %rax, 0x128(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x2d5c0
testb $0x1, %al
jne 0x29934
jmp 0x299c4
leaq 0x130(%rsp), %rdi
callq 0x2d890
movq (%rax), %rsi
movq 0x5b67d(%rip), %rdi     # 0x84fc8
callq 0x50f0
movq %rax, 0x10(%rsp)
jmp 0x29957
movq 0x10(%rsp), %rdi
leaq 0x3f210(%rip), %rsi     # 0x68b73
callq 0x5460
jmp 0x2996a
jmp 0x2996c
leaq 0x130(%rsp), %rdi
xorl %esi, %esi
callq 0x2da40
movq %rax, 0x120(%rsp)
jmp 0x29901
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d8(%rsp)
movl %eax, 0x1d4(%rsp)
jmp 0x29a3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d8(%rsp)
movl %eax, 0x1d4(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x58b8
jmp 0x29a3f
movq 0x5b5fd(%rip), %rdi     # 0x84fc8
leaq 0x3f1a3(%rip), %rsi     # 0x68b75
callq 0x5460
movq %rax, 0x8(%rsp)
jmp 0x299de
movq 0x8(%rsp), %rdi
movq 0x5b5c6(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x299f1
jmp 0x299f3
jmp 0x299f5
leaq 0x240(%rsp), %rdi
xorl %esi, %esi
callq 0x2da40
movq %rax, 0x118(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x58b8
leaq 0x200(%rsp), %rdi
callq 0x58b8
movq 0x220(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x220(%rsp)
jmp 0x292a4
leaq 0x200(%rsp), %rdi
callq 0x58b8
jmp 0x29a5a
movb $0x1, %al
andb $0x1, %al
addq $0x278, %rsp            # imm = 0x278
retq
movq 0x1d8(%rsp), %rdi
callq 0x57b0
nopw (%rax,%rax)