// File: mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::invfdistribution(long, long, double, alglib_impl::ae_state*)
double invfdistribution(ae_int_t a,
     ae_int_t b,
     double y,
     ae_state *_state)
{
    double w;
    double result;


    ae_assert(((a>=1&&b>=1)&&ae_fp_greater(y,0))&&ae_fp_less_eq(y,1), "Domain error in InvFDistribution", _state);
    
    /*
     * Compute probability for x = 0.5
     */
    w = incompletebeta(0.5*b, 0.5*a, 0.5, _state);
    
    /*
     * If that is greater than y, then the solution w < .5
     * Otherwise, solve at 1-y to remove cancellation in (b - b*w)
     */
    if( ae_fp_greater(w,y)||ae_fp_less(y,0.001) )
    {
        w = invincompletebeta(0.5*b, 0.5*a, y, _state);
        result = (b-b*w)/(a*w);
    }
    else
    {
        w = invincompletebeta(0.5*a, 0.5*b, 1.0-y, _state);
        result = b*w/(a*(1.0-w));
    }
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
xorl %eax, %eax
cmpq $0x1, -0x8(%rbp)
movb %al, -0x31(%rbp)
jl 0x15fe1
xorl %eax, %eax
cmpq $0x1, -0x10(%rbp)
movb %al, -0x31(%rbp)
jl 0x15fe1
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c4c0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x31(%rbp)
jne 0x15fcc
jmp 0x15fe1
movsd -0x18(%rbp), %xmm0
movsd 0x3f02f(%rip), %xmm1    # 0x55008
callq 0x3c480
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
movq -0x20(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x41703(%rip), %rsi     # 0x576f8
callq 0x3b240
cvtsi2sdq -0x10(%rbp), %xmm1
movsd 0x3f448(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
cvtsi2sdq -0x8(%rbp), %xmm2
movsd 0x3f436(%rip), %xmm1    # 0x55450
mulsd %xmm2, %xmm1
movq -0x20(%rbp), %rdi
movsd 0x3f426(%rip), %xmm2    # 0x55450
callq 0xeb20
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
callq 0x3c4c0
testb $0x1, %al
jne 0x1605f
movsd -0x18(%rbp), %xmm0
movsd 0x40ab4(%rip), %xmm1    # 0x56b08
callq 0x3c440
testb $0x1, %al
jne 0x1605f
jmp 0x160dc
cvtsi2sdq -0x10(%rbp), %xmm1
movsd 0x3f3e3(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
cvtsi2sdq -0x8(%rbp), %xmm2
movsd 0x3f3d1(%rip), %xmm1    # 0x55450
mulsd %xmm2, %xmm1
movsd -0x18(%rbp), %xmm2
movq -0x20(%rbp), %rdi
callq 0xf3a0
movsd %xmm0, -0x28(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm1
cvtsi2sdq -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsi2sdq -0x8(%rbp), %xmm1
mulsd -0x28(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x16146
cvtsi2sdq -0x8(%rbp), %xmm1
movsd 0x3f366(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
cvtsi2sdq -0x10(%rbp), %xmm2
movsd 0x3f354(%rip), %xmm1    # 0x55450
mulsd %xmm2, %xmm1
movsd 0x3ef00(%rip), %xmm2    # 0x55008
subsd -0x18(%rbp), %xmm2
movq -0x20(%rbp), %rdi
callq 0xf3a0
movsd %xmm0, -0x28(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
cvtsi2sdq -0x8(%rbp), %xmm1
movsd 0x3eed4(%rip), %xmm2    # 0x55008
subsd -0x28(%rbp), %xmm2
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)