// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movsd 0x4dc87(%rip), %xmm0    # 0x557b8
movsd %xmm0, -0x28(%rbp)
movsd 0x4dc92(%rip), %xmm0    # 0x557d0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x4d4a3(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x58(%rbp)
movsd 0x4dc6e(%rip), %xmm0    # 0x557e0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x4dc54(%rip), %xmm1    # 0x557d8
mulsd -0x10(%rbp), %xmm1
movsd 0x4d477(%rip), %xmm0    # 0x55008
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x4d466(%rip), %xmm0    # 0x55008
subsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x6870
movsd %xmm0, -0xa0(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c890
movsd -0xa8(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xa0(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x10(%rbp), %xmm0
mulsd -0x60(%rbp), %xmm0
mulsd -0x60(%rbp), %xmm0
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x20(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x5530
movsd %xmm0, -0x70(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0xa, -0x80(%rbp)
jge 0x7e45
movsd -0x48(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
callq 0x3c4c0
testb $0x1, %al
jne 0x7c78
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7c78
jmp 0x7c8a
movsd 0x4db68(%rip), %xmm0    # 0x557e8
movsd %xmm0, -0x68(%rbp)
jmp 0x7e45
movsd -0x10(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movq -0x20(%rbp), %rdi
callq 0x7580
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7cca
movsd -0x60(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
callq 0x3c4c0
testb $0x1, %al
jne 0x7cca
jmp 0x7cdc
movsd 0x4db16(%rip), %xmm0    # 0x557e8
movsd %xmm0, -0x68(%rbp)
jmp 0x7e45
movsd -0x60(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7cf1
jmp 0x7d07
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x7d1b
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x4d2e0(%rip), %xmm1    # 0x55008
subsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm2
movsd -0xb0(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
subsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd 0x4da38(%rip), %xmm1    # 0x557c0
callq 0x3c440
testb $0x1, %al
jne 0x7d93
jmp 0x7da5
movsd 0x4da4d(%rip), %xmm0    # 0x557e8
movsd %xmm0, -0x68(%rbp)
jmp 0x7e45
movsd -0x68(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cdd0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
divsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
divsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd -0x28(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7e06
jmp 0x7e25
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x8155
movsd -0x48(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x7c45
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x7e5d
jmp 0x7f01
movsd -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c480
testb $0x1, %al
jne 0x7e70
jmp 0x7e7d
movsd 0x4d190(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x48(%rbp)
jmp 0x7e7f
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0x7e94
jmp 0x7eff
movsd 0x4d16c(%rip), %xmm0    # 0x55008
addsd -0x68(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movq -0x20(%rbp), %rdi
callq 0x7580
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7ed8
jmp 0x7eee
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x7eff
movsd -0x68(%rbp), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x7e7f
jmp 0x7f01
movsd 0x4d547(%rip), %xmm0    # 0x55450
movsd %xmm0, -0x68(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0x190, -0x80(%rbp)     # imm = 0x190
jge 0x813b
movsd -0x40(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
movsd -0x38(%rbp), %xmm2
subsd -0x40(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movq -0x20(%rbp), %rdi
callq 0x7580
movsd %xmm0, -0x60(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
addsd -0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd -0x78(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7fa3
jmp 0x7fa8
jmp 0x813b
movsd -0x60(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd -0x78(%rbp), %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x7fda
jmp 0x7fdf
jmp 0x813b
movsd -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c480
testb $0x1, %al
jne 0x7ff2
jmp 0x7ff7
jmp 0x813b
movsd -0x60(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
callq 0x3c500
testb $0x1, %al
jne 0x800f
jmp 0x80a3
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
cmpq $0x0, -0x88(%rbp)
jge 0x8047
movq $0x0, -0x88(%rbp)
movsd 0x4d410(%rip), %xmm0    # 0x55450
movsd %xmm0, -0x68(%rbp)
jmp 0x808c
cmpq $0x1, -0x88(%rbp)
jle 0x806d
movsd -0x68(%rbp), %xmm0
movsd 0x4d3f2(%rip), %xmm1    # 0x55450
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x808a
movsd -0x18(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
subsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x808c
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x812a
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
cmpq $0x0, -0x88(%rbp)
jle 0x80db
movq $0x0, -0x88(%rbp)
movsd 0x4d37c(%rip), %xmm0    # 0x55450
movsd %xmm0, -0x68(%rbp)
jmp 0x8118
cmpq $-0x1, -0x88(%rbp)
jge 0x80f9
movsd 0x4d363(%rip), %xmm0    # 0x55450
mulsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x8116
movsd -0x18(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
subsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x8118
movq -0x88(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x7f21
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)