// File: /workspace/github_c_makefile_star2_O1/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 0x11202
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
cvtsi2ss %esi, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
jne 0x11324
jp 0x11324
movsd 0x2d243(%rip), %xmm2    # 0x3e428
addsd %xmm0, %xmm2
mulsd 0x2f83f(%rip), %xmm2    # 0x40a30
addsd %xmm0, %xmm0
addsd %xmm2, %xmm0
divsd %xmm1, %xmm0
jmp 0x11344
subq $0x18, %rsp
cmpl $0x18, %edi
jl 0x11295
cvtsi2sd %esi, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x2f7d7(%rip), %xmm0    # 0x409f8
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
cmpl $0x64, %edi
movl $0x64, %eax
cmovll %edi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x2f7b7(%rip), %xmm1    # 0x40a00
movss %xmm2, (%rsp)
callq 0x3790
movss 0xc(%rsp), %xmm3
movss (%rsp), %xmm2
mulsd 0x2f7a2(%rip), %xmm0    # 0x40a08
movsd 0x2f7a2(%rip), %xmm1    # 0x40a10
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
divsd 0x2f02d(%rip), %xmm1    # 0x402b8
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x112d1
xorps %xmm0, %xmm0
cvtsi2ss %esi, %xmm0
movslq %edi, %rax
leaq 0x2f7ca(%rip), %rcx     # 0x40a70
movss (%rcx,%rax,8), %xmm3
mulss %xmm0, %xmm3
movss 0x2f78d(%rip), %xmm1    # 0x40a44
divss %xmm1, %xmm3
mulss 0x4(%rcx,%rax,8), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x2f71f(%rip), %xmm0    # 0x409f0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulsd 0x2f734(%rip), %xmm1    # 0x40a18
movsd 0x2f6cc(%rip), %xmm4    # 0x409b8
divsd %xmm1, %xmm4
movsd %xmm4, (%rsp)
subss %xmm3, %xmm2
divss %xmm0, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
movsd 0x2f6d4(%rip), %xmm0    # 0x409e0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x30e0
mulsd (%rsp), %xmm0
addq $0x18, %rsp
jmp 0x11344
cvtss2sd %xmm2, %xmm2
mulsd 0x2f6f0(%rip), %xmm2    # 0x40a20
addsd %xmm0, %xmm2
mulsd 0x2f6ec(%rip), %xmm2    # 0x40a28
divsd %xmm1, %xmm2
movapd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
retq