// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam2bcf.c
// Function: mean_diff_to_prob
float mean_diff_to_prob(float mdiff, int dp, int readlen)
{
    if ( dp==2 )
    {
        if ( mdiff==0 )
            return (2.0*readlen + 4.0*(readlen-1.0))/((float)readlen*readlen);
        else
            return 8.0*(readlen - 4.0*mdiff)/((float)readlen*readlen);
    }

    // This is crude empirical approximation and is not very accurate for
    // shorter read lengths (<100bp). There certainly is a room for
    // improvement.
    const float mv[24][2] = { {0,0}, {0,0}, {0,0},
        { 9.108, 4.934}, { 9.999, 3.991}, {10.273, 3.485}, {10.579, 3.160},
        {10.828, 2.889}, {11.014, 2.703}, {11.028, 2.546}, {11.244, 2.391},
        {11.231, 2.320}, {11.323, 2.138}, {11.403, 2.123}, {11.394, 1.994},
        {11.451, 1.928}, {11.445, 1.862}, {11.516, 1.815}, {11.560, 1.761},
        {11.544, 1.728}, {11.605, 1.674}, {11.592, 1.652}, {11.674, 1.613},
        {11.641, 1.570} };

    float m, v;
    if ( dp>=24 )
    {
        m = readlen/8.;
        if (dp>100) dp = 100;
        v = 1.476/(0.182*pow(dp,0.514));
        v = v*(readlen/100.);
    }
    else
    {
        m = mv[dp][0];
        v = mv[dp][1];
        m = m*readlen/100.;
        v = v*readlen/100.;
        v *= 1.2;   // allow more variability
    }
    return 1.0/(v*sqrt(2*M_PI)) * exp(-0.5*((mdiff-m)/v)*((mdiff-m)/v));
}

// Assembly:
movaps %xmm0, %xmm2
cmpl $0x2, %edi
jne 0x115a1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
cvtsi2ss %esi, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
jne 0x116c3
jp 0x116c3
movsd 0x2deec(%rip), %xmm2    # 0x3f470
addsd %xmm0, %xmm2
mulsd 0x304e0(%rip), %xmm2    # 0x41a70
addsd %xmm0, %xmm0
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
jmp 0x116e3
subq $0x18, %rsp
cmpl $0x18, %edi
jl 0x11634
cvtsi2sd %esi, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x30478(%rip), %xmm0    # 0x41a38
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
cmpl $0x64, %edi
movl $0x64, %eax
cmovbl %edi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x30458(%rip), %xmm1    # 0x41a40
movss %xmm2, (%rsp)
callq 0x3790
movss 0xc(%rsp), %xmm3
movss (%rsp), %xmm2
mulsd 0x30443(%rip), %xmm0    # 0x41a48
movsd 0x30443(%rip), %xmm1    # 0x41a50
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
divsd 0x2fcce(%rip), %xmm1    # 0x412f8
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x11670
xorps %xmm0, %xmm0
cvtsi2ss %esi, %xmm0
movslq %edi, %rax
leaq 0x3047b(%rip), %rcx     # 0x41ac0
movss (%rcx,%rax,8), %xmm3
mulss %xmm0, %xmm3
movss 0x3045e(%rip), %xmm1    # 0x41ab4
divss %xmm1, %xmm3
mulss 0x4(%rcx,%rax,8), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x303c0(%rip), %xmm0    # 0x41a30
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulsd 0x303d5(%rip), %xmm1    # 0x41a58
movsd 0x3036d(%rip), %xmm4    # 0x419f8
divsd %xmm1, %xmm4
movsd %xmm4, (%rsp)
subss %xmm3, %xmm2
divss %xmm0, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
movsd 0x30375(%rip), %xmm0    # 0x41a20
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x30e0
mulsd (%rsp), %xmm0
addq $0x18, %rsp
jmp 0x116e3
cvtss2sd %xmm2, %xmm2
mulsd 0x30391(%rip), %xmm2    # 0x41a60
addsd %xmm0, %xmm2
mulsd 0x3038d(%rip), %xmm2    # 0x41a68
divsd %xmm1, %xmm2
movapd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
retq