// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movl %edx, %ebx
movq %rdi, %r13
movq 0xa0(%rsp), %rax
movq $0x0, (%rax)
movq %rsi, (%rsp)
movq 0x18(%rsi), %rbp
testl %edx, %edx
jle 0x1d1d9
movl %ebx, %r14d
movq %rbp, %rdi
callq 0x4230
movq %rax, %rbp
decl %r14d
jne 0x1d1c9
movslq %ebx, %rcx
movq 0x8(%r13), %rax
subq %rcx, %rax
movq %rcx, 0x20(%rsp)
cmpq %rcx, %rax
jb 0x1d5b1
movq (%rsp), %rax
leaq 0x8(%rax), %rbx
movq 0x2edc8(%rip), %r12     # 0x4bfc8
movq 0x20(%rsp), %r14
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x4360
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq $-0x1, %rcx
callq 0x4360
movq 0x50(%rsp), %rcx
testq %rcx, %rcx
je 0x1d258
movq 0x48(%rsp), %rdx
xorl %esi, %esi
xorl %eax, %eax
xorl %edi, %edi
cmpb $0x31, (%rdx,%rsi)
sete %dil
addq %rdi, %rax
incq %rsi
cmpq %rsi, %rcx
jne 0x1d241
jmp 0x1d25a
xorl %eax, %eax
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0x1d287
movq 0x28(%rsp), %rdi
xorl %r8d, %r8d
xorl %esi, %esi
xorl %r9d, %r9d
cmpb $0x31, (%rdi,%r8)
sete %r9b
addq %r9, %rsi
incq %r8
cmpq %r8, %rdx
jne 0x1d26e
jmp 0x1d289
xorl %esi, %esi
movq %rdx, %xmm1
subq %rsi, %rdx
movq %rcx, %xmm0
subq %rax, %rcx
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa %xmm0, %xmm1
movdqa 0x1de57(%rip), %xmm4    # 0x3b100
pand %xmm4, %xmm1
movdqa 0x1de5b(%rip), %xmm5    # 0x3b110
por %xmm5, %xmm1
psrlq $0x20, %xmm0
movdqa 0x1de5a(%rip), %xmm6    # 0x3b120
por %xmm6, %xmm0
movapd 0x1de5e(%rip), %xmm7    # 0x3b130
subpd %xmm7, %xmm0
addpd %xmm1, %xmm0
movq %rcx, %xmm1
movq %rsi, %xmm2
punpcklqdq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0]
movdqa %xmm1, %xmm2
pand %xmm4, %xmm2
por %xmm5, %xmm2
psrlq $0x20, %xmm1
por %xmm6, %xmm1
subpd %xmm7, %xmm1
addpd %xmm2, %xmm1
divpd %xmm0, %xmm1
movq %rdx, %xmm3
movq %rax, %xmm2
punpcklqdq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0]
movdqa %xmm2, %xmm3
pand %xmm4, %xmm3
por %xmm5, %xmm3
psrlq $0x20, %xmm2
por %xmm6, %xmm2
subpd %xmm7, %xmm2
addpd %xmm3, %xmm2
divpd %xmm0, %xmm2
movapd %xmm2, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
mulpd %xmm0, %xmm2
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
maxsd %xmm0, %xmm2
movq 0xa0(%rsp), %rax
ucomisd (%rax), %xmm2
jbe 0x1d559
movsd %xmm2, (%rax)
movq %rbp, %rdi
callq 0x4370
movq 0x20(%rax), %rcx
movq 0x10(%rsp), %r15
movq %rcx, (%r15)
movq %rax, %rdi
callq 0x4230
movq %rax, %rbp
movq 0x20(%rax), %rax
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rsp), %rcx
movl %r14d, (%rcx)
cmpq (%r15), %rax
jne 0x1d559
movl $0xc, %edx
movq %r12, %rdi
leaq 0x1f6d5(%rip), %rsi     # 0x3ca8a
callq 0x43a0
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %r12, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20abf(%rip), %rsi     # 0x3de9b
callq 0x43a0
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1f6a7(%rip), %rsi     # 0x3ca97
callq 0x43a0
movq 0x18(%rsp), %rax
movl (%rax), %esi
movq %r15, %rdi
callq 0x4580
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20a85(%rip), %rsi     # 0x3de9b
callq 0x43a0
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1f678(%rip), %rsi     # 0x3caa2
callq 0x43a0
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x4210
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20a4a(%rip), %rsi     # 0x3de9b
callq 0x43a0
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1f648(%rip), %rsi     # 0x3caad
callq 0x43a0
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x4210
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20a0f(%rip), %rsi     # 0x3de9b
callq 0x43a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movl $0x20, %edx
movq %r12, %rdi
leaq 0x1f5f1(%rip), %rsi     # 0x3cab8
callq 0x43a0
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1f5fe(%rip), %rsi     # 0x3cad9
callq 0x43a0
movq (%rsp), %rax
movq 0x18(%rax), %r15
cmpq %rbx, %r15
je 0x1d51d
movq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x4210
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1f5d4(%rip), %rsi     # 0x3cadc
callq 0x43a0
movq %r15, %rdi
callq 0x4230
movq %rax, %r15
cmpq %rbx, %rax
jne 0x1d4ed
movl $0x4b, %edx
movq %r12, %rdi
leaq 0x1f5b2(%rip), %rsi     # 0x3cade
callq 0x43a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r12, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq %rbp, %rdi
callq 0x4230
movq %rax, %rbp
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1d580
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1d59c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4340
incq %r14
movq 0x8(%r13), %rax
subq 0x20(%rsp), %rax
cmpq %rax, %r14
jbe 0x1d205
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1d5e8
jmp 0x1d5c9
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1d5e8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1d604
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4340
movq %rbx, %rdi
callq 0x45a0