// File: /workspace/github_cpp_makefile_star2_O2/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, 0x28(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movl %edx, %ebx
movq %rdi, 0x8(%rsp)
movq 0xb0(%rsp), %rax
andq $0x0, (%rax)
movq %rsi, 0x10(%rsp)
movq 0x18(%rsi), %rbp
xorl %r14d, %r14d
testl %edx, %edx
cmovgl %edx, %r14d
subl $0x1, %r14d
jb 0x13a9e
movq %rbp, %rdi
callq 0x4240
movq %rax, %rbp
jmp 0x13a8b
movslq %ebx, %r14
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %r13
leaq 0x7(%rsp), %r15
movq %r14, 0x30(%rsp)
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rax
subq 0x30(%rsp), %rax
cmpq %rax, %r14
ja 0x13dcb
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x4360
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
pushq $-0x1
popq %rcx
callq 0x4360
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq %rdi, %rsi
movb $0x31, 0x7(%rsp)
movq %r15, %rdx
callq 0x17516
movq %r15, %rdx
movq %rax, %r15
movq 0x40(%rsp), %rbx
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
addq %rdi, %rsi
movb $0x31, 0x7(%rsp)
movq %rdx, %r12
callq 0x17516
subq %r15, %rbx
movq 0x60(%rsp), %rcx
movdqu 0x40(%rsp), %xmm0
movq %rcx, %xmm1
subq %rax, %rcx
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa %xmm0, %xmm1
movdqa 0x1658b(%rip), %xmm4    # 0x2a0e0
pand %xmm4, %xmm1
movdqa 0x1658f(%rip), %xmm5    # 0x2a0f0
por %xmm5, %xmm1
psrlq $0x20, %xmm0
movdqa 0x1658e(%rip), %xmm6    # 0x2a100
por %xmm6, %xmm0
movapd 0x16592(%rip), %xmm7    # 0x2a110
subpd %xmm7, %xmm0
addpd %xmm1, %xmm0
movq %rbx, %xmm1
movq %rax, %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 %rcx, %xmm3
movq %r15, %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 %xmm1, %xmm0
movsd %xmm2, %xmm0            # xmm0 = xmm2[0],xmm0[1]
shufpd $0x1, %xmm1, %xmm2      # xmm2 = xmm2[1],xmm1[0]
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 0x13d72
movsd %xmm2, (%rax)
movq %rbp, %rdi
callq 0x4370
movq 0x20(%rax), %rcx
movq 0x20(%rsp), %rbx
movq %rcx, (%rbx)
movq %rax, %rdi
callq 0x4240
movq %rax, %rbp
movq 0x20(%rax), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq 0x28(%rsp), %rcx
movl %r14d, (%rcx)
cmpq (%rbx), %rax
jne 0x13d7c
movq 0x2936e(%rip), %rdi     # 0x3cfc8
leaq 0x17e09(%rip), %rsi     # 0x2ba6a
callq 0x4330
movq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42e0
movq %rax, %rdi
leaq 0x19213(%rip), %rsi     # 0x2ce93
callq 0x4330
movq %rax, %rdi
leaq 0x17de8(%rip), %rsi     # 0x2ba77
callq 0x4330
movq 0x28(%rsp), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x4580
movq %rax, %rdi
leaq 0x191e6(%rip), %rsi     # 0x2ce93
callq 0x4330
movq %rax, %rdi
leaq 0x17dc6(%rip), %rsi     # 0x2ba82
callq 0x4330
movq 0x20(%rsp), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x4230
movq %rax, %rdi
leaq 0x191b8(%rip), %rsi     # 0x2ce93
callq 0x4330
movq %rax, %rdi
leaq 0x17da3(%rip), %rsi     # 0x2ba8d
callq 0x4330
movq 0x18(%rsp), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x4230
movq %rax, %rdi
leaq 0x1918a(%rip), %rsi     # 0x2ce93
callq 0x4330
movq %rax, %rdi
callq 0x41c0
movq 0x292ab(%rip), %rdi     # 0x3cfc8
leaq 0x17d74(%rip), %rsi     # 0x2ba98
callq 0x4330
movq %rax, %rdi
leaq 0x17d86(%rip), %rsi     # 0x2bab9
callq 0x4330
movq 0x10(%rsp), %rax
movq 0x18(%rax), %r15
cmpq %r13, %r15
je 0x13d86
movq 0x20(%r15), %rsi
movq 0x29277(%rip), %rdi     # 0x3cfc8
callq 0x4230
movq %rax, %rdi
leaq 0x17d5c(%rip), %rsi     # 0x2babc
callq 0x4330
movq %r15, %rdi
callq 0x4240
movq %rax, %r15
jmp 0x13d41
movq 0x8(%rsp), %rbx
movq %r12, %r15
jmp 0x13da4
movq %r12, %r15
movq 0x8(%rsp), %rbx
jmp 0x13da4
movq 0x2923b(%rip), %rdi     # 0x3cfc8
leaq 0x17d2a(%rip), %rsi     # 0x2babe
callq 0x4330
movq %r12, %r15
movq %rax, %rdi
callq 0x41c0
movq %rbp, %rdi
callq 0x4240
movq %rax, %rbp
leaq 0x58(%rsp), %rdi
callq 0x4638
leaq 0x38(%rsp), %rdi
callq 0x4638
incq %r14
jmp 0x13ab9
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x13df4
jmp 0x13de7
jmp 0x13de7
jmp 0x13de7
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4638
leaq 0x38(%rsp), %rdi
callq 0x4638
movq %rbx, %rdi
callq 0x45a0