// File: mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::binomialcdistribution(long, long, double, alglib_impl::ae_state*)
double binomialcdistribution(ae_int_t k,
     ae_int_t n,
     double p,
     ae_state *_state)
{
    double dk;
    double dn;
    double result;


    ae_assert(ae_fp_greater_eq(p,0)&&ae_fp_less_eq(p,1), "Domain error in BinomialDistributionC", _state);
    ae_assert(k>=-1&&k<=n, "Domain error in BinomialDistributionC", _state);
    if( k==-1 )
    {
        result = 1;
        return result;
    }
    if( k==n )
    {
        result = 0;
        return result;
    }
    dn = n-k;
    if( k==0 )
    {
        if( ae_fp_less(p,0.01) )
        {
            dk = -nuexpm1(dn*nulog1p(-p, _state), _state);
        }
        else
        {
            dk = 1.0-ae_pow(1.0-p, dn, _state);
        }
    }
    else
    {
        dk = k+1;
        dk = incompletebeta(dk, dn, p, _state);
    }
    result = dk;
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c500
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x41(%rbp)
jne 0x10864
jmp 0x10879
movsd -0x20(%rbp), %xmm0
movsd 0x44797(%rip), %xmm1    # 0x55008
callq 0x3c480
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
movq -0x28(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x46d3c(%rip), %rsi     # 0x575c9
callq 0x3b240
xorl %eax, %eax
cmpq $-0x1, -0x10(%rbp)
movb %al, -0x42(%rbp)
jl 0x108ac
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
setle %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
movq -0x28(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x46d09(%rip), %rsi     # 0x575c9
callq 0x3b240
cmpq $-0x1, -0x10(%rbp)
jne 0x108e8
movsd 0x44734(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x10a14
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x10909
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x10a14
movq -0x18(%rbp), %rax
subq -0x10(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x109d1
movsd -0x20(%rbp), %xmm0
movsd 0x45b55(%rip), %xmm1    # 0x56488
callq 0x3c440
testb $0x1, %al
jne 0x1093e
jmp 0x109a0
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x20(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x28(%rbp), %rdi
callq 0x39080
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq -0x28(%rbp), %rdi
callq 0x392f0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x109cf
movsd 0x44660(%rip), %xmm0    # 0x55008
subsd -0x20(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movq -0x28(%rbp), %rdi
callq 0x3cda0
movaps %xmm0, %xmm1
movsd 0x44642(%rip), %xmm0    # 0x55008
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x10a00
movq -0x10(%rbp), %rax
addq $0x1, %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x20(%rbp), %xmm2
movq -0x28(%rbp), %rdi
callq 0xeb20
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x50, %rsp
popq %rbp
retq
nop