// File: mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::ibetaf_incompletebetaps(double, double, double, double, alglib_impl::ae_state*)
static double ibetaf_incompletebetaps(double a,
     double b,
     double x,
     double maxgam,
     ae_state *_state)
{
    double s;
    double t;
    double u;
    double v;
    double n;
    double t1;
    double z;
    double ai;
    double sg;
    double result;


    ai = 1.0/a;
    u = (1.0-b)*x;
    v = u/(a+1.0);
    t1 = v;
    t = u;
    n = 2.0;
    s = 0.0;
    z = ae_machineepsilon*ai;
    while(ae_fp_greater(ae_fabs(v, _state),z))
    {
        u = (n-b)*x/n;
        t = t*u;
        v = t/(a+n);
        s = s+v;
        n = n+1.0;
    }
    s = s+t1;
    s = s+ai;
    u = a*ae_log(x, _state);
    if( ae_fp_less(a+b,maxgam)&&ae_fp_less(ae_fabs(u, _state),ae_log(ae_maxrealnumber, _state)) )
    {
        t = gammafunction(a+b, _state)/(gammafunction(a, _state)*gammafunction(b, _state));
        s = s*t*ae_pow(x, a, _state);
    }
    else
    {
        t = lngamma(a+b, &sg, _state)-lngamma(a, &sg, _state)-lngamma(b, &sg, _state)+u+ae_log(s, _state);
        if( ae_fp_less(t,ae_log(ae_minrealnumber, _state)) )
        {
            s = 0.0;
        }
        else
        {
            s = ae_exp(t, _state);
        }
    }
    result = s;
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movsd %xmm2, -0x18(%rbp)
movsd %xmm3, -0x20(%rbp)
movq %rdi, -0x28(%rbp)
movsd 0x3861d(%rip), %xmm0    # 0x55008
divsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x3860b(%rip), %xmm0    # 0x55008
subsd -0x10(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd 0x385ef(%rip), %xmm1    # 0x55008
addsd -0x8(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x38985(%rip), %xmm0    # 0x553c8
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x38ec0(%rip), %xmm0    # 0x55918
mulsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x3c820
movsd -0x60(%rbp), %xmm1
callq 0x3c4c0
testb $0x1, %al
jne 0x1ca80
jmp 0x1cae6
movsd -0x50(%rbp), %xmm0
subsd -0x10(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
addsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x38531(%rip), %xmm0    # 0x55008
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x1ca62
movsd -0x30(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x8(%rbp), %xmm0
addsd -0x10(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x1cb4a
jmp 0x1cc27
movsd -0x40(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x88(%rbp)
movq -0x28(%rbp), %rdi
movsd 0x38c3c(%rip), %xmm0    # 0x557a8
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0x88(%rbp), %xmm0
callq 0x3c440
testb $0x1, %al
jne 0x1cb8a
jmp 0x1cc27
movsd -0x8(%rbp), %xmm0
addsd -0x10(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x4ed0
movsd %xmm0, -0x98(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x4ed0
movsd %xmm0, -0xa0(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x4ed0
movsd -0xa0(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x98(%rbp), %xmm0
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x18(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
movq -0x28(%rbp), %rdi
callq 0x3cda0
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x1cd12
movsd -0x8(%rbp), %xmm0
addsd -0x10(%rbp), %xmm0
movq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x5530
movsd %xmm0, -0xc0(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x5530
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x5530
movaps %xmm0, %xmm1
movsd -0xb8(%rbp), %xmm0
subsd %xmm1, %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
movsd 0x39750(%rip), %xmm0    # 0x56428
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
callq 0x3c440
testb $0x1, %al
jne 0x1ccf3
jmp 0x1ccfd
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x1cd10
movsd -0x38(%rbp), %xmm0
movq -0x28(%rbp), %rdi
callq 0x3cdd0
movsd %xmm0, -0x30(%rbp)
jmp 0x1cd12
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)