// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::lngamma(double, double*, alglib_impl::ae_state*)
double lngamma(double x, double* sgngam, ae_state *_state)
{
#ifndef ALGLIB_INTERCEPTS_SPECFUNCS
    double a;
    double b;
    double c;
    double p;
    double q;
    double u;
    double w;
    double z;
    ae_int_t i;
    double logpi;
    double ls2pi;
    double tmp;
    double result;

    *sgngam = 0;

    *sgngam = 1;
    logpi = 1.14472988584940017414;
    ls2pi = 0.91893853320467274178;
    if( ae_fp_less(x,-34.0) )
    {
        q = -x;
        w = lngamma(q, &tmp, _state);
        p = ae_ifloor(q, _state);
        i = ae_round(p, _state);
        if( i%2==0 )
        {
            *sgngam = -1;
        }
        else
        {
            *sgngam = 1;
        }
        z = q-p;
        if( ae_fp_greater(z,0.5) )
        {
            p = p+1;
            z = p-q;
        }
        z = q*ae_sin(ae_pi*z, _state);
        result = logpi-ae_log(z, _state)-w;
        return result;
    }
    if( ae_fp_less(x,13) )
    {
        z = 1;
        p = 0;
        u = x;
        while(ae_fp_greater_eq(u,3))
        {
            p = p-1;
            u = x+p;
            z = z*u;
        }
        while(ae_fp_less(u,2))
        {
            z = z/u;
            p = p+1;
            u = x+p;
        }
        if( ae_fp_less(z,0) )
        {
            *sgngam = -1;
            z = -z;
        }
        else
        {
            *sgngam = 1;
        }
        if( ae_fp_eq(u,2) )
        {
            result = ae_log(z, _state);
            return result;
        }
        p = p-2;
        x = x+p;
        b = -1378.25152569120859100;
        b = -38801.6315134637840924+x*b;
        b = -331612.992738871184744+x*b;
        b = -1162370.97492762307383+x*b;
        b = -1721737.00820839662146+x*b;
        b = -853555.664245765465627+x*b;
        c = 1;
        c = -351.815701436523470549+x*c;
        c = -17064.2106651881159223+x*c;
        c = -220528.590553854454839+x*c;
        c = -1139334.44367982507207+x*c;
        c = -2532523.07177582951285+x*c;
        c = -2018891.41433532773231+x*c;
        p = x*b/c;
        result = ae_log(z, _state)+p;
        return result;
    }
    q = (x-0.5)*ae_log(x, _state)-x+ls2pi;
    if( ae_fp_greater(x,100000000) )
    {
        result = q;
        return result;
    }
    p = 1/(x*x);
    if( ae_fp_greater_eq(x,1000.0) )
    {
        q = q+((7.9365079365079365079365*0.0001*p-2.7777777777777777777778*0.001)*p+0.0833333333333333333333)/x;
    }
    else
    {
        a = 8.11614167470508450300*0.0001;
        a = -5.95061904284301438324*0.0001+p*a;
        a = 7.93650340457716943945*0.0001+p*a;
        a = -2.77777777730099687205*0.001+p*a;
        a = 8.33333333333331927722*0.01+p*a;
        q = q+a/x;
    }
    result = q;
    return result;
#else
    return _ialglib_i_lngamma(x, sgngam);
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x50, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movabsq $0x3ff0000000000000, %r15 # imm = 0x3FF0000000000000
movq %r15, (%rdi)
movsd 0x2f5dc(%rip), %xmm1    # 0x34478
movaps %xmm0, 0x20(%rsp)
callq 0x262fe
testb %al, %al
je 0x4f3d
movaps 0x2f32b(%rip), %xmm0    # 0x341e0
xorps 0x20(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x4e78
movsd %xmm0, 0x8(%rsp)
movaps 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x265d3
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x265be
xorl %ecx, %ecx
testb $0x1, %al
sete %cl
leaq 0x3162e(%rip), %rax     # 0x36530
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%r14)
movapd 0x10(%rsp), %xmm0
subsd (%rsp), %xmm0
movsd 0x2f549(%rip), %xmm1    # 0x34468
movapd %xmm0, 0x30(%rsp)
callq 0x2633e
testb %al, %al
jne 0x4fc6
movapd 0x30(%rsp), %xmm0
jmp 0x4fd9
movsd 0x2f53b(%rip), %xmm1    # 0x34480
movaps 0x20(%rsp), %xmm0
callq 0x262fe
testb %al, %al
movapd 0x20(%rsp), %xmm0
je 0x5017
movsd 0x2f243(%rip), %xmm1    # 0x341a8
callq 0x2635a
testb %al, %al
je 0x5070
movsd 0x2f226(%rip), %xmm1    # 0x341a0
xorpd %xmm2, %xmm2
addsd 0x2f24a(%rip), %xmm2    # 0x341d0
movsd %xmm2, (%rsp)
movapd %xmm2, %xmm0
addsd 0x20(%rsp), %xmm0
mulsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movsd 0x2f1fb(%rip), %xmm1    # 0x341a8
callq 0x2635a
movsd (%rsp), %xmm2
movapd 0x10(%rsp), %xmm1
testb %al, %al
jne 0x4f7e
jmp 0x5088
movsd (%rsp), %xmm0
addsd 0x2f1cd(%rip), %xmm0    # 0x341a0
addsd 0x20(%rsp), %xmm0
mulsd 0x2f48f(%rip), %xmm0    # 0x34470
movq %rbx, %rdi
callq 0x266a4
mulsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266d6
movsd 0x2f541(%rip), %xmm1    # 0x34540
subsd %xmm0, %xmm1
subsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq
movsd 0x2f469(%rip), %xmm1    # 0x34488
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq %rbx, %rdi
callq 0x266d6
mulsd 0x10(%rsp), %xmm0
movapd 0x20(%rsp), %xmm2
subsd %xmm2, %xmm0
addsd 0x2f447(%rip), %xmm0    # 0x34490
movsd %xmm0, 0x10(%rsp)
movsd 0x2f441(%rip), %xmm1    # 0x34498
movapd %xmm2, %xmm0
callq 0x2633e
testb %al, %al
je 0x510a
movsd 0x10(%rsp), %xmm1
jmp 0x5009
xorpd %xmm2, %xmm2
movsd 0x2f124(%rip), %xmm1    # 0x341a0
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm2, (%rsp)
movapd %xmm1, 0x10(%rsp)
movsd 0x2f345(%rip), %xmm1    # 0x343e0
movsd 0x8(%rsp), %xmm0
callq 0x262fe
testb %al, %al
je 0x5168
movapd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
divsd %xmm2, %xmm0
movapd %xmm0, 0x10(%rsp)
addsd 0x2f0cf(%rip), %xmm1    # 0x341a0
movsd %xmm1, (%rsp)
movapd %xmm1, %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x2f2f2(%rip), %xmm1    # 0x343e0
callq 0x262fe
movsd 0x8(%rsp), %xmm2
movsd (%rsp), %xmm1
movapd 0x10(%rsp), %xmm0
testb %al, %al
jne 0x50bf
jmp 0x5179
movapd 0x20(%rsp), %xmm0
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movsd 0x2f080(%rip), %xmm1    # 0x341a0
divsd %xmm2, %xmm1
movsd %xmm1, (%rsp)
movsd 0x2f097(%rip), %xmm1    # 0x341c8
callq 0x2635a
testb %al, %al
je 0x52b6
movsd 0x2f382(%rip), %xmm0    # 0x344c8
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
addsd 0x2f379(%rip), %xmm0    # 0x344d0
mulsd %xmm1, %xmm0
addsd 0x2f375(%rip), %xmm0    # 0x344d8
jmp 0x52f3
movapd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, (%rsp)
xorpd %xmm1, %xmm1
movapd %xmm0, 0x10(%rsp)
callq 0x262fe
testb %al, %al
je 0x51ba
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%r14)
movapd 0x10(%rsp), %xmm0
xorpd 0x2f02e(%rip), %xmm0    # 0x341e0
movapd %xmm0, 0x10(%rsp)
jmp 0x51bd
movq %r15, (%r14)
movsd 0x8(%rsp), %xmm0
movsd 0x2f215(%rip), %xmm1    # 0x343e0
callq 0x262ba
testb %al, %al
je 0x51ea
movaps 0x10(%rsp), %xmm0
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x266d6
movsd (%rsp), %xmm1
addsd 0x2f1f9(%rip), %xmm1    # 0x343f0
addsd 0x20(%rsp), %xmm1
movsd 0x2f2db(%rip), %xmm0    # 0x344e0
mulsd %xmm1, %xmm0
addsd 0x2f2d7(%rip), %xmm0    # 0x344e8
mulsd %xmm1, %xmm0
addsd 0x2f2d3(%rip), %xmm0    # 0x344f0
mulsd %xmm1, %xmm0
addsd 0x2f2cf(%rip), %xmm0    # 0x344f8
mulsd %xmm1, %xmm0
addsd 0x2f2cb(%rip), %xmm0    # 0x34500
mulsd %xmm1, %xmm0
addsd 0x2f2c7(%rip), %xmm0    # 0x34508
movapd %xmm0, %xmm2
movsd 0x2f2c3(%rip), %xmm0    # 0x34510
addsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x2f2bb(%rip), %xmm0    # 0x34518
mulsd %xmm1, %xmm0
addsd 0x2f2b7(%rip), %xmm0    # 0x34520
mulsd %xmm1, %xmm0
addsd 0x2f2b3(%rip), %xmm0    # 0x34528
mulsd %xmm1, %xmm0
addsd 0x2f2af(%rip), %xmm0    # 0x34530
mulsd %xmm1, %xmm0
addsd 0x2f2ab(%rip), %xmm0    # 0x34538
mulsd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, (%rsp)
movapd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266d6
movapd %xmm0, %xmm1
addsd (%rsp), %xmm1
jmp 0x5009
movsd 0x2f1e2(%rip), %xmm0    # 0x344a0
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
addsd 0x2f1d9(%rip), %xmm0    # 0x344a8
mulsd %xmm1, %xmm0
addsd 0x2f1d5(%rip), %xmm0    # 0x344b0
mulsd %xmm1, %xmm0
addsd 0x2f1d1(%rip), %xmm0    # 0x344b8
mulsd %xmm1, %xmm0
addsd 0x2f1cd(%rip), %xmm0    # 0x344c0
movsd 0x10(%rsp), %xmm1
divsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm1
jmp 0x5009