// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
movsd %xmm0, 0x30(%rsp)
movsd 0x2a9b3(%rip), %xmm4    # 0x30738
mulsd %xmm0, %xmm4
movsd 0x2a467(%rip), %xmm2    # 0x301f8
movapd %xmm2, %xmm3
divsd %xmm4, %xmm3
movsd %xmm3, 0x8(%rsp)
movsd %xmm2, 0x40(%rsp)
subsd %xmm3, %xmm2
movsd %xmm2, (%rsp)
movsd %xmm1, 0x18(%rsp)
movaps %xmm1, %xmm0
callq 0x53d1
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24424
mulsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, %xmm2
movsd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, (%rsp)
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x48dc
movsd (%rsp), %xmm1
movsd %xmm0, 0x48(%rsp)
movsd 0x2a3e6(%rip), %xmm0    # 0x30200
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x2a8f8(%rip), %xmm0    # 0x30730
movsd %xmm0, 0x10(%rsp)
pushq $0xa
popq %r14
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
subq $0x1, %r14
movsd %xmm1, (%rsp)
jb 0x5fb7
movapd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x24279
testb %al, %al
jne 0x5faf
movsd (%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x24239
testb %al, %al
jne 0x5faf
movsd 0x30(%rsp), %xmm0
movsd (%rsp), %xmm1
movq %rbx, %rdi
callq 0x59ff
movsd %xmm0, 0x8(%rsp)
movsd 0x20(%rsp), %xmm1
callq 0x24239
testb %al, %al
jne 0x5faf
movsd 0x8(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
callq 0x24279
testb %al, %al
jne 0x5faf
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x24239
testb %al, %al
jne 0x5f02
movsd (%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x40(%rsp)
jmp 0x5f19
movsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x2455f
mulsd 0x50(%rsp), %xmm0
subsd (%rsp), %xmm0
subsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x2a7e0(%rip), %xmm1    # 0x30720
callq 0x24239
testb %al, %al
jne 0x5faf
movsd 0x28(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24569
xorpd 0x2a251(%rip), %xmm0    # 0x301b0
movsd 0x8(%rsp), %xmm1
subsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movapd %xmm1, %xmm0
divsd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x2a79a(%rip), %xmm1    # 0x30728
callq 0x24239
testb %al, %al
jne 0x6242
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm0, %xmm1
jmp 0x5e51
movsd 0x2a789(%rip), %xmm0    # 0x30740
movsd %xmm0, 0x8(%rsp)
movsd 0x2a76b(%rip), %xmm1    # 0x30730
movsd 0x10(%rsp), %xmm0
callq 0x241f5
testb %al, %al
je 0x6064
xorpd %xmm1, %xmm1
movsd (%rsp), %xmm0
callq 0x24259
movsd 0x2a20a(%rip), %xmm0    # 0x301f8
testb %al, %al
jne 0x5ff7
movsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x2a726(%rip), %xmm1    # 0x30730
callq 0x241f5
testb %al, %al
je 0x6064
movsd 0x8(%rsp), %xmm0
addsd 0x2a1d7(%rip), %xmm0    # 0x301f8
movsd (%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x59ff
movsd %xmm0, 0x28(%rsp)
movsd 0x18(%rsp), %xmm1
callq 0x24239
testb %al, %al
jne 0x606b
movsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x5ffc
movsd (%rsp), %xmm0
jmp 0x6082
movsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x28(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x2a3fe(%rip), %xmm4    # 0x30488
movl $0x190, %r14d           # imm = 0x190
xorl %r15d, %r15d
subq $0x1, %r14
jb 0x6247
movsd 0x10(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
subsd %xmm2, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd %xmm4, 0x48(%rsp)
movapd %xmm4, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd 0x30(%rsp), %xmm0
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x59ff
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x2a644(%rip), %xmm1    # 0x30748
callq 0x24239
testb %al, %al
jne 0x6242
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x2a613(%rip), %xmm1    # 0x30748
callq 0x24239
testb %al, %al
jne 0x6242
xorps %xmm1, %xmm1
movsd (%rsp), %xmm0
callq 0x24259
testb %al, %al
jne 0x6242
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x24295
testb %al, %al
je 0x619a
testq %r15, %r15
movsd (%rsp), %xmm0
movsd 0x48(%rsp), %xmm4
js 0x61bd
cmpq $0x2, %r15
movsd 0x8(%rsp), %xmm5
jb 0x61e6
movsd 0x2a2f8(%rip), %xmm1    # 0x30488
mulsd %xmm1, %xmm4
addsd %xmm1, %xmm4
jmp 0x6202
testq %r15, %r15
movsd (%rsp), %xmm0
movsd 0x48(%rsp), %xmm4
jle 0x61d0
movsd 0x2a2d6(%rip), %xmm4    # 0x30488
xorl %r15d, %r15d
movsd 0x8(%rsp), %xmm2
jmp 0x622e
movsd 0x2a2c3(%rip), %xmm4    # 0x30488
xorl %r15d, %r15d
movsd 0x8(%rsp), %xmm5
jmp 0x6202
cmpq $-0x2, %r15
movsd 0x8(%rsp), %xmm2
jg 0x6216
mulsd 0x2a2a4(%rip), %xmm4    # 0x30488
jmp 0x622e
movsd 0x18(%rsp), %xmm4
movsd 0x20(%rsp), %xmm2
subsd %xmm2, %xmm4
movapd %xmm5, %xmm1
subsd %xmm2, %xmm1
divsd %xmm1, %xmm4
incq %r15
movsd %xmm0, 0x38(%rsp)
movsd %xmm5, 0x40(%rsp)
jmp 0x6093
movsd 0x18(%rsp), %xmm4
subsd %xmm2, %xmm4
movsd 0x40(%rsp), %xmm1
subsd %xmm2, %xmm1
divsd %xmm1, %xmm4
decq %r15
movsd %xmm0, 0x10(%rsp)
movsd %xmm2, 0x20(%rsp)
jmp 0x6093
movsd (%rsp), %xmm0
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq