// File: schneebergerlab[P]GameteBinning/asPollinator_1.0.cpp
// Function: calculate_lod(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
double calculate_lod(string patA, string patB)
{
    /* contigPollenGTSeq:
       PPPPMPPPMMPPPPM patA
       PPPMMPPMPMPPUMM patB
    */
    double lod = 0.0;
    assert(patA.size() == patB.size());
    double r   = 0.0; // count of     recombined case 
    double nr  = 0.0; // count of non-recombined case
    for(int ii=0; ii<patA.size(); ii++)
    {
        string Ageno = patA.substr(ii, 1);
        string Bgeno = patB.substr(ii, 1);
        if(Ageno.compare("U")  !=0 &&
           Bgeno.compare("U")  !=0 &&
           Ageno.compare(Bgeno)==0   )
        {
            nr ++;
        }else
        {
            r  ++;
        }
    }
    double totalEffective = r + nr;
    if(totalEffective > 0)
    {
        // recombination rate
        double theta          = r / totalEffective;
        //
        double thisNumerator;
        double thisDenominator;
        if(theta!=0  && theta!=1)
        {
            thisNumerator     = pow(theta, r) * pow(1-theta, nr);
        }else
        {
            thisNumerator     = 1;
        }
        thisDenominator       = pow(0.5, totalEffective);    
        //
        lod                   = log10(thisNumerator / thisDenominator);
    }else
    {
        lod                   = -1000.0; // cannot be determined
    }
    //
    return lod;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xc0(%rsp)
callq 0x3250
movq 0x28(%rsp), %rdi
movq %rax, 0x30(%rsp)
callq 0x3250
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jne 0x17e00
jmp 0x17e1f
leaq 0x140a8(%rip), %rdi     # 0x2beaf
leaq 0x13c55(%rip), %rsi     # 0x2ba63
movl $0x893, %edx            # imm = 0x893
leaq 0x140b0(%rip), %rcx     # 0x2beca
callq 0x3210
xorps %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xb0(%rsp)
movl $0x0, 0xac(%rsp)
movq 0x20(%rsp), %rdi
movslq 0xac(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x3250
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x17f9b
movq 0x20(%rsp), %rsi
movslq 0xac(%rsp), %rdx
leaq 0x88(%rsp), %rdi
movl $0x1, %ecx
movq %rcx, 0x10(%rsp)
callq 0x3350
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rcx
movslq 0xac(%rsp), %rdx
leaq 0x68(%rsp), %rdi
callq 0x3350
jmp 0x17eac
leaq 0x88(%rsp), %rdi
leaq 0x13b93(%rip), %rsi     # 0x2ba4e
callq 0x3100
cmpl $0x0, %eax
je 0x17f42
leaq 0x68(%rsp), %rdi
leaq 0x13b7d(%rip), %rsi     # 0x2ba4e
callq 0x3100
cmpl $0x0, %eax
je 0x17f42
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3040
movl %eax, 0xc(%rsp)
jmp 0x17ef3
movl 0xc(%rsp), %eax
cmpl $0x0, %eax
jne 0x17f42
movsd 0x1312c(%rip), %xmm0    # 0x2b030
addsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
jmp 0x17f5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
jmp 0x17f89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x31e0
jmp 0x17f89
movsd 0x130e6(%rip), %xmm0    # 0x2b030
addsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x31e0
leaq 0x88(%rsp), %rdi
callq 0x31e0
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x17e42
leaq 0x88(%rsp), %rdi
callq 0x31e0
jmp 0x180b4
movsd 0xb8(%rsp), %xmm0
addsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x50(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x18092
movsd 0xb8(%rsp), %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x17fee
jp 0x17fee
jmp 0x1804f
movsd 0x48(%rsp), %xmm0
movsd 0x13034(%rip), %xmm1    # 0x2b030
ucomisd %xmm1, %xmm0
jne 0x18006
jp 0x18006
jmp 0x1804f
movsd 0x48(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
callq 0x3550
movsd %xmm0, (%rsp)
movsd 0x13009(%rip), %xmm0    # 0x2b030
subsd 0x48(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
callq 0x3550
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x1805d
movsd 0x12fd9(%rip), %xmm0    # 0x2b030
movsd %xmm0, 0x40(%rsp)
movsd 0x50(%rsp), %xmm1
movsd 0x12fa5(%rip), %xmm0    # 0x2b010
callq 0x3550
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
callq 0x3190
movsd %xmm0, 0xc0(%rsp)
jmp 0x180a3
movsd 0x12f8e(%rip), %xmm0    # 0x2b028
movsd %xmm0, 0xc0(%rsp)
movsd 0xc0(%rsp), %xmm0
addq $0xd8, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x3560
nop