// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::invincompletegammac(double, double, alglib_impl::ae_state*)
double invincompletegammac(double a, double y0, ae_state *_state)
{
    double igammaepsilon;
    double iinvgammabignumber;
    double x0;
    double x1;
    double x;
    double yl;
    double yh;
    double y;
    double d;
    double lgm;
    double dithresh;
    ae_int_t i;
    ae_int_t dir;
    double tmp;
    double result;


    igammaepsilon = 0.000000000000001;
    iinvgammabignumber = 4503599627370496.0;
    x0 = iinvgammabignumber;
    yl = 0;
    x1 = 0;
    yh = 1;
    dithresh = 5*igammaepsilon;
    d = 1/(9*a);
    y = 1-d-invnormaldistribution(y0, _state)*ae_sqrt(d, _state);
    x = a*y*y*y;
    lgm = lngamma(a, &tmp, _state);
    i = 0;
    while(i<10)
    {
        if( ae_fp_greater(x,x0)||ae_fp_less(x,x1) )
        {
            d = 0.0625;
            break;
        }
        y = incompletegammac(a, x, _state);
        if( ae_fp_less(y,yl)||ae_fp_greater(y,yh) )
        {
            d = 0.0625;
            break;
        }
        if( ae_fp_less(y,y0) )
        {
            x0 = x;
            yl = y;
        }
        else
        {
            x1 = x;
            yh = y;
        }
        d = (a-1)*ae_log(x, _state)-x-lgm;
        if( ae_fp_less(d,-709.78271289338399) )
        {
            d = 0.0625;
            break;
        }
        d = -ae_exp(d, _state);
        d = (y-y0)/d;
        if( ae_fp_less(ae_fabs(d/x, _state),igammaepsilon) )
        {
            result = x;
            return result;
        }
        x = x-d;
        i = i+1;
    }
    if( ae_fp_eq(x0,iinvgammabignumber) )
    {
        if( ae_fp_less_eq(x,0) )
        {
            x = 1;
        }
        while(ae_fp_eq(x0,iinvgammabignumber))
        {
            x = (1+d)*x;
            y = incompletegammac(a, x, _state);
            if( ae_fp_less(y,y0) )
            {
                x0 = x;
                yl = y;
                break;
            }
            d = d+d;
        }
    }
    d = 0.5;
    dir = 0;
    i = 0;
    while(i<400)
    {
        x = x1+d*(x0-x1);
        y = incompletegammac(a, x, _state);
        lgm = (x0-x1)/(x1+x0);
        if( ae_fp_less(ae_fabs(lgm, _state),dithresh) )
        {
            break;
        }
        lgm = (y-y0)/y0;
        if( ae_fp_less(ae_fabs(lgm, _state),dithresh) )
        {
            break;
        }
        if( ae_fp_less_eq(x,0.0) )
        {
            break;
        }
        if( ae_fp_greater_eq(y,y0) )
        {
            x1 = x;
            yh = y;
            if( dir<0 )
            {
                dir = 0;
                d = 0.5;
            }
            else
            {
                if( dir>1 )
                {
                    d = 0.5*d+0.5;
                }
                else
                {
                    d = (y0-yl)/(yh-yl);
                }
            }
            dir = dir+1;
        }
        else
        {
            x0 = x;
            yl = y;
            if( dir>0 )
            {
                dir = 0;
                d = 0.5;
            }
            else
            {
                if( dir<-1 )
                {
                    d = 0.5*d;
                }
                else
                {
                    d = (y0-yl)/(yh-yl);
                }
            }
            dir = dir-1;
        }
        i = i+1;
    }
    result = x;
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movsd %xmm0, 0x40(%rsp)
movsd 0x2e334(%rip), %xmm3    # 0x347f8
mulsd %xmm0, %xmm3
movsd 0x2dcd0(%rip), %xmm2    # 0x341a0
movapd %xmm2, %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm2, 0x48(%rsp)
subsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, 0x28(%rsp)
movaps %xmm1, %xmm0
callq 0x5a37
movsd %xmm0, 0x10(%rsp)
movsd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2658d
mulsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, %xmm2
movsd 0x40(%rsp), %xmm0
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x4e78
movsd 0x8(%rsp), %xmm1
movsd %xmm0, 0x50(%rsp)
movsd 0x2dc73(%rip), %xmm0    # 0x341d0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x2e277(%rip), %xmm2    # 0x347e8
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0xa, %r14d
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x8(%rsp)
movapd %xmm1, %xmm0
movsd %xmm2, 0x18(%rsp)
movapd %xmm2, %xmm1
callq 0x2633e
testb %al, %al
jne 0x66f3
movsd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x262fe
testb %al, %al
jne 0x66f3
movsd 0x40(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %rbx, %rdi
callq 0x60f1
movsd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm1
callq 0x262fe
testb %al, %al
jne 0x66f3
movsd 0x10(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x2633e
testb %al, %al
jne 0x66f3
movsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x262fe
testb %al, %al
jne 0x6636
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x48(%rsp)
jmp 0x664e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x38(%rsp)
movq %rbx, %rdi
callq 0x266d6
mulsd 0x58(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
subsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x2e162(%rip), %xmm1    # 0x347d8
callq 0x262fe
testb %al, %al
jne 0x66f3
movsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266e0
xorpd 0x2db4b(%rip), %xmm0    # 0x341e0
movsd 0x10(%rsp), %xmm1
subsd 0x28(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
divsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x2e11b(%rip), %xmm1    # 0x347e0
callq 0x262fe
testb %al, %al
jne 0x69b2
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm0, %xmm1
decq %r14
movsd 0x18(%rsp), %xmm2
jne 0x6587
jmp 0x6707
movsd 0x2e105(%rip), %xmm0    # 0x34800
movsd 0x8(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd 0x2e0c7(%rip), %xmm1    # 0x347e8
movapd %xmm2, %xmm0
callq 0x262ba
testb %al, %al
je 0x67e9
xorpd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x2631e
movl %eax, %ebp
movsd 0x2e09d(%rip), %xmm1    # 0x347e8
movsd 0x18(%rsp), %xmm0
callq 0x262ba
testb %al, %al
je 0x67e9
movsd 0x2da3a(%rip), %xmm0    # 0x341a0
movsd %xmm0, 0x20(%rsp)
testb %bpl, %bpl
jne 0x677d
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
addsd 0x2da0f(%rip), %xmm1    # 0x341a0
mulsd %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x60f1
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x262fe
testb %al, %al
jne 0x69c3
movsd 0x10(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
movsd 0x2e008(%rip), %xmm1    # 0x347e8
callq 0x262ba
testb %al, %al
jne 0x677d
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x2dc6b(%rip), %xmm3    # 0x34468
movl $0x190, %r14d           # imm = 0x190
xorl %r15d, %r15d
movsd 0x20(%rsp), %xmm0
movsd 0x30(%rsp), %xmm2
subsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd %xmm3, 0x50(%rsp)
movapd %xmm3, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd 0x40(%rsp), %xmm0
movsd %xmm1, 0x8(%rsp)
movq %rbx, %rdi
callq 0x60f1
movsd %xmm0, 0x10(%rsp)
movsd 0x20(%rsp), %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x2df9a(%rip), %xmm1    # 0x34808
callq 0x262fe
testb %al, %al
jne 0x69b2
movsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x2df69(%rip), %xmm1    # 0x34808
callq 0x262fe
testb %al, %al
jne 0x69b2
xorps %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x2631e
testb %al, %al
jne 0x69b2
movsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x2635a
testb %al, %al
je 0x6906
testq %r15, %r15
movsd 0x8(%rsp), %xmm0
movsd 0x50(%rsp), %xmm3
js 0x692a
cmpq $0x2, %r15
movsd 0x10(%rsp), %xmm4
jl 0x6953
movsd 0x2db6c(%rip), %xmm1    # 0x34468
mulsd %xmm1, %xmm3
addsd %xmm1, %xmm3
jmp 0x696f
testq %r15, %r15
movsd 0x8(%rsp), %xmm0
movsd 0x50(%rsp), %xmm3
jle 0x693d
movsd 0x2db49(%rip), %xmm3    # 0x34468
xorl %r15d, %r15d
movsd 0x10(%rsp), %xmm2
jmp 0x6998
movsd 0x2db36(%rip), %xmm3    # 0x34468
xorl %r15d, %r15d
movsd 0x10(%rsp), %xmm4
jmp 0x696f
cmpq $-0x2, %r15
movsd 0x10(%rsp), %xmm2
jg 0x6980
mulsd 0x2db17(%rip), %xmm3    # 0x34468
jmp 0x6998
movsd 0x28(%rsp), %xmm3
movsd 0x38(%rsp), %xmm1
subsd %xmm1, %xmm3
movapd %xmm4, %xmm2
subsd %xmm1, %xmm2
divsd %xmm2, %xmm3
incq %r15
movsd %xmm0, 0x30(%rsp)
movsd %xmm4, 0x48(%rsp)
jmp 0x69a7
movsd 0x28(%rsp), %xmm3
subsd %xmm2, %xmm3
movsd 0x48(%rsp), %xmm1
subsd %xmm2, %xmm1
divsd %xmm1, %xmm3
decq %r15
movsd %xmm0, 0x20(%rsp)
movsd %xmm2, 0x38(%rsp)
decq %r14
jne 0x6806
jmp 0x69b8
movsd 0x8(%rsp), %xmm0
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
jmp 0x67f5