// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl %edx, %ebx
movq %rdi, %r13
movq 0xb0(%rsp), %rax
movq $0x0, (%rax)
movq %rsi, 0x8(%rsp)
movq 0x18(%rsi), %rbp
testl %edx, %edx
jle 0x1d14c
movl %ebx, %r14d
movq %rbp, %rdi
callq 0x4230
movq %rax, %rbp
decl %r14d
jne 0x1d13c
movslq %ebx, %rcx
movq 0x8(%r13), %rax
subq %rcx, %rax
movq %rcx, 0x28(%rsp)
cmpq %rcx, %rax
jb 0x1d53d
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x30(%rsp)
movq 0x2ee4f(%rip), %r12     # 0x4bfc8
movq 0x28(%rsp), %r14
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x4360
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq $-0x1, %rcx
callq 0x4360
movq 0x60(%rsp), %rcx
testq %rcx, %rcx
je 0x1d1d1
movq 0x58(%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 0x1d1ba
jmp 0x1d1d3
xorl %eax, %eax
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %rdx
testq %rdx, %rdx
je 0x1d1ff
xorl %edi, %edi
xorl %esi, %esi
xorl %r8d, %r8d
cmpb $0x31, (%r15,%rdi)
sete %r8b
addq %r8, %rsi
incq %rdi
cmpq %rdi, %rdx
jne 0x1d1e6
jmp 0x1d201
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 0x1dedf(%rip), %xmm4    # 0x3b100
pand %xmm4, %xmm1
movdqa 0x1dee3(%rip), %xmm5    # 0x3b110
por %xmm5, %xmm1
psrlq $0x20, %xmm0
movdqa 0x1dee2(%rip), %xmm6    # 0x3b120
por %xmm6, %xmm0
movapd 0x1dee6(%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 0xb0(%rsp), %rax
ucomisd (%rax), %xmm2
jbe 0x1d4e7
movq %r13, %rbx
movsd %xmm2, (%rax)
movq %rbp, %rdi
callq 0x4370
movq 0x20(%rax), %rcx
movq 0x18(%rsp), %r13
movq %rcx, (%r13)
movq %rax, %rdi
callq 0x4230
movq %rax, %rbp
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x20(%rsp), %rcx
movl %r14d, (%rcx)
cmpq (%r13), %rax
jne 0x1d4e4
movl $0xc, %edx
movq %r12, %rdi
leaq 0x1f758(%rip), %rsi     # 0x3ca8a
callq 0x43a0
movq %rbx, %r13
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r12, %rdi
callq 0x43a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20b40(%rip), %rsi     # 0x3de9b
callq 0x43a0
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1f728(%rip), %rsi     # 0x3ca97
callq 0x43a0
movq 0x20(%rsp), %rax
movl (%rax), %esi
movq %r15, %rdi
callq 0x4580
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20b06(%rip), %rsi     # 0x3de9b
callq 0x43a0
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1f6f9(%rip), %rsi     # 0x3caa2
callq 0x43a0
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x4210
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20acb(%rip), %rsi     # 0x3de9b
callq 0x43a0
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1f6c9(%rip), %rsi     # 0x3caad
callq 0x43a0
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x4210
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x20a90(%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 0x1f672(%rip), %rsi     # 0x3cab8
callq 0x43a0
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1f67f(%rip), %rsi     # 0x3cad9
callq 0x43a0
movq 0x8(%rsp), %rax
movq 0x18(%rax), %r15
cmpq 0x30(%rsp), %r15
je 0x1d4a1
movq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x4210
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1f652(%rip), %rsi     # 0x3cadc
callq 0x43a0
movq %r15, %rdi
callq 0x4230
movq %rax, %r15
cmpq 0x30(%rsp), %rax
jne 0x1d46f
movl $0x4b, %edx
movq %r12, %rdi
leaq 0x1f62e(%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 0x38(%rsp), %r15
jmp 0x1d4e7
movq %rbx, %r13
movq %rbp, %rdi
callq 0x4230
movq %rax, %rbp
leaq 0x48(%rsp), %rax
cmpq %rax, %r15
je 0x1d50c
movq 0x48(%rsp), %rsi
incq %rsi
movq %r15, %rdi
callq 0x4340
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1d528
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x4340
incq %r14
movq 0x8(%r13), %rax
subq 0x28(%rsp), %rax
cmpq %rax, %r14
jbe 0x1d17e
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1d574
jmp 0x1d555
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x1d574
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1d590
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x4340
movq %rbx, %rdi
callq 0x45a0