// File: /workspace/github_cpp_makefile_star2_O3/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 0x2d33f(%rip), %xmm3    # 0x33738
mulsd %xmm0, %xmm3
movsd 0x2cddb(%rip), %xmm2    # 0x331e0
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 0x5a3e
movsd %xmm0, 0x10(%rsp)
movsd 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e48
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 0x4e80
movsd 0x8(%rsp), %xmm1
movsd %xmm0, 0x50(%rsp)
movsd 0x2cd76(%rip), %xmm0    # 0x33208
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x2d28a(%rip), %xmm2    # 0x33730
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 0x25bf9
testb %al, %al
jne 0x6628
movsd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x25bb9
testb %al, %al
jne 0x6628
movsd 0x40(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %rbx, %rdi
callq 0x6070
movsd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm1
callq 0x25bb9
testb %al, %al
jne 0x6628
movsd 0x10(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x25bf9
testb %al, %al
jne 0x6628
movsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x25bb9
testb %al, %al
jne 0x656b
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x48(%rsp)
jmp 0x6583
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x38(%rsp)
movq %rbx, %rdi
callq 0x25f91
mulsd 0x58(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
subsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x2d175(%rip), %xmm1    # 0x33720
callq 0x25bb9
testb %al, %al
jne 0x6628
movsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f9b
xorpd 0x2cbe6(%rip), %xmm0    # 0x331b0
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 0x25e30
movsd 0x2d12e(%rip), %xmm1    # 0x33728
callq 0x25bb9
testb %al, %al
jne 0x68e7
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm0, %xmm1
decq %r14
movsd 0x18(%rsp), %xmm2
jne 0x64bc
jmp 0x663c
movsd 0x2d110(%rip), %xmm0    # 0x33740
movsd 0x8(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd 0x2d0da(%rip), %xmm1    # 0x33730
movapd %xmm2, %xmm0
callq 0x25b75
testb %al, %al
je 0x671e
xorpd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x25bd9
movl %eax, %ebp
movsd 0x2d0b0(%rip), %xmm1    # 0x33730
movsd 0x18(%rsp), %xmm0
callq 0x25b75
testb %al, %al
je 0x671e
movsd 0x2cb45(%rip), %xmm0    # 0x331e0
movsd %xmm0, 0x20(%rsp)
testb %bpl, %bpl
jne 0x66b2
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
addsd 0x2cb1a(%rip), %xmm1    # 0x331e0
mulsd %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x6070
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x25bb9
testb %al, %al
jne 0x68f8
movsd 0x10(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
movsd 0x2d01b(%rip), %xmm1    # 0x33730
callq 0x25b75
testb %al, %al
jne 0x66b2
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x2cd56(%rip), %xmm3    # 0x33488
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 0x6070
movsd %xmm0, 0x10(%rsp)
movsd 0x20(%rsp), %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x25e30
movsd 0x2cfa5(%rip), %xmm1    # 0x33748
callq 0x25bb9
testb %al, %al
jne 0x68e7
movsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x25e30
movsd 0x2cf74(%rip), %xmm1    # 0x33748
callq 0x25bb9
testb %al, %al
jne 0x68e7
xorps %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x25bd9
testb %al, %al
jne 0x68e7
movsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x25c15
testb %al, %al
je 0x683b
testq %r15, %r15
movsd 0x8(%rsp), %xmm0
movsd 0x50(%rsp), %xmm3
js 0x685f
cmpq $0x2, %r15
movsd 0x10(%rsp), %xmm4
jb 0x6888
movsd 0x2cc57(%rip), %xmm1    # 0x33488
mulsd %xmm1, %xmm3
addsd %xmm1, %xmm3
jmp 0x68a4
testq %r15, %r15
movsd 0x8(%rsp), %xmm0
movsd 0x50(%rsp), %xmm3
jle 0x6872
movsd 0x2cc34(%rip), %xmm3    # 0x33488
xorl %r15d, %r15d
movsd 0x10(%rsp), %xmm2
jmp 0x68cd
movsd 0x2cc21(%rip), %xmm3    # 0x33488
xorl %r15d, %r15d
movsd 0x10(%rsp), %xmm4
jmp 0x68a4
cmpq $-0x2, %r15
movsd 0x10(%rsp), %xmm2
jg 0x68b5
mulsd 0x2cc02(%rip), %xmm3    # 0x33488
jmp 0x68cd
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 0x68dc
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 0x673b
jmp 0x68ed
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 0x672a