// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::gammafunction(double, alglib_impl::ae_state*)
double gammafunction(double x, ae_state *_state)
{
#ifndef ALGLIB_INTERCEPTS_SPECFUNCS
    double p;
    double pp;
    double q;
    double qq;
    double z;
    ae_int_t i;
    double sgngam;
    double result;


    sgngam = 1;
    q = ae_fabs(x, _state);
    if( ae_fp_greater(q,33.0) )
    {
        if( ae_fp_less(x,0.0) )
        {
            p = ae_ifloor(q, _state);
            i = ae_round(p, _state);
            if( i%2==0 )
            {
                sgngam = -1;
            }
            z = q-p;
            if( ae_fp_greater(z,0.5) )
            {
                p = p+1;
                z = q-p;
            }
            z = q*ae_sin(ae_pi*z, _state);
            z = ae_fabs(z, _state);
            z = ae_pi/(z*gammafunc_gammastirf(q, _state));
        }
        else
        {
            z = gammafunc_gammastirf(x, _state);
        }
        result = sgngam*z;
        return result;
    }
    z = 1;
    while(ae_fp_greater_eq(x,3))
    {
        x = x-1;
        z = z*x;
    }
    while(ae_fp_less(x,0))
    {
        if( ae_fp_greater(x,-0.000000001) )
        {
            result = z/((1+0.5772156649015329*x)*x);
            return result;
        }
        z = z/x;
        x = x+1;
    }
    while(ae_fp_less(x,2))
    {
        if( ae_fp_less(x,0.000000001) )
        {
            result = z/((1+0.5772156649015329*x)*x);
            return result;
        }
        z = z/x;
        x = x+1.0;
    }
    if( ae_fp_eq(x,2) )
    {
        result = z;
        return result;
    }
    x = x-2.0;
    pp = 1.60119522476751861407E-4;
    pp = 1.19135147006586384913E-3+x*pp;
    pp = 1.04213797561761569935E-2+x*pp;
    pp = 4.76367800457137231464E-2+x*pp;
    pp = 2.07448227648435975150E-1+x*pp;
    pp = 4.94214826801497100753E-1+x*pp;
    pp = 9.99999999999999996796E-1+x*pp;
    qq = -2.31581873324120129819E-5;
    qq = 5.39605580493303397842E-4+x*qq;
    qq = -4.45641913851797240494E-3+x*qq;
    qq = 1.18139785222060435552E-2+x*qq;
    qq = 3.58236398605498653373E-2+x*qq;
    qq = -2.34591795718243348568E-1+x*qq;
    qq = 7.14304917030273074085E-2+x*qq;
    qq = 1.00000000000000000320+x*qq;
    result = z*pp/qq;
    return result;
#else
    return _ialglib_i_gammafunction(x);
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movsd %xmm0, 0x8(%rsp)
callq 0x26575
movsd 0x2f981(%rip), %xmm1    # 0x343d0
movsd %xmm0, 0x10(%rsp)
callq 0x2633e
testb %al, %al
je 0x4ada
xorps %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x262fe
testb %al, %al
je 0x4b36
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x265d3
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x265be
xorl %r14d, %r14d
testb $0x1, %al
sete %r14b
leaq 0x31a88(%rip), %r15     # 0x36530
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movsd 0x2f9ac(%rip), %xmm1    # 0x34468
movsd %xmm0, 0x18(%rsp)
callq 0x2633e
testb %al, %al
jne 0x4d3a
movsd 0x18(%rsp), %xmm0
jmp 0x4d52
movsd 0x2f6c6(%rip), %xmm1    # 0x341a8
movsd 0x8(%rsp), %xmm0
callq 0x2635a
movsd 0x2f6ab(%rip), %xmm1    # 0x341a0
testb %al, %al
je 0x4b51
movsd 0x8(%rsp), %xmm0
addsd 0x2f6c9(%rip), %xmm0    # 0x341d0
movsd %xmm0, 0x8(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x2f689(%rip), %xmm1    # 0x341a8
callq 0x2635a
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
testb %al, %al
jne 0x4aff
jmp 0x4b57
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x1321b
movsd 0x2f654(%rip), %xmm1    # 0x341a0
jmp 0x4dac
movsd 0x8(%rsp), %xmm0
movsd %xmm1, 0x10(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm0, 0x8(%rsp)
callq 0x262fe
testb %al, %al
je 0x4bb9
movsd 0x8(%rsp), %xmm0
movsd 0x2f85a(%rip), %xmm1    # 0x343d8
callq 0x2633e
testb %al, %al
jne 0x4c3b
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
addsd 0x2f5f7(%rip), %xmm2    # 0x341a0
xorpd %xmm1, %xmm1
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
jmp 0x4b67
movsd 0x2f81f(%rip), %xmm1    # 0x343e0
movsd 0x8(%rsp), %xmm0
callq 0x262fe
testb %al, %al
je 0x4c19
movsd 0x8(%rsp), %xmm0
movsd 0x2f80a(%rip), %xmm1    # 0x343e8
callq 0x262fe
testb %al, %al
jne 0x4c3b
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
addsd 0x2f59b(%rip), %xmm1    # 0x341a0
movsd %xmm1, 0x8(%rsp)
movapd %xmm1, %xmm0
movsd 0x2f7c9(%rip), %xmm1    # 0x343e0
jmp 0x4bc7
movsd 0x2f7bf(%rip), %xmm1    # 0x343e0
movsd 0x8(%rsp), %xmm0
callq 0x262ba
testb %al, %al
je 0x4c6c
movsd 0x10(%rsp), %xmm0
jmp 0x4db0
movsd 0x2f81d(%rip), %xmm0    # 0x34460
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm0
addsd 0x2f54b(%rip), %xmm0    # 0x341a0
mulsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x4db0
movsd 0x8(%rsp), %xmm3
addsd 0x2f776(%rip), %xmm3    # 0x343f0
movsd 0x2f776(%rip), %xmm0    # 0x343f8
mulsd %xmm3, %xmm0
addsd 0x2f772(%rip), %xmm0    # 0x34400
mulsd %xmm3, %xmm0
addsd 0x2f76e(%rip), %xmm0    # 0x34408
mulsd %xmm3, %xmm0
addsd 0x2f76a(%rip), %xmm0    # 0x34410
mulsd %xmm3, %xmm0
addsd 0x2f766(%rip), %xmm0    # 0x34418
mulsd %xmm3, %xmm0
addsd 0x2f762(%rip), %xmm0    # 0x34420
movsd 0x2f762(%rip), %xmm1    # 0x34428
mulsd %xmm3, %xmm1
addsd 0x2f75e(%rip), %xmm1    # 0x34430
mulsd %xmm3, %xmm1
addsd 0x2f75a(%rip), %xmm1    # 0x34438
mulsd %xmm3, %xmm1
addsd 0x2f756(%rip), %xmm1    # 0x34440
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm1
addsd 0x2f74e(%rip), %xmm1    # 0x34448
movsd 0x2f49e(%rip), %xmm2    # 0x341a0
mulsd %xmm3, %xmm1
addsd 0x2f742(%rip), %xmm1    # 0x34450
addsd %xmm2, %xmm0
mulsd %xmm3, %xmm1
addsd 0x2f73a(%rip), %xmm1    # 0x34458
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm2
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
jmp 0x4db0
movsd 0x8(%rsp), %xmm1
addsd 0x2f458(%rip), %xmm1    # 0x341a0
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd (%r15,%r14,8), %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd 0x2f70a(%rip), %xmm0    # 0x34470
movq %rbx, %rdi
callq 0x266a4
mulsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x1321b
movsd 0x8(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm0
movsd 0x2f6cc(%rip), %xmm2    # 0x34470
divsd %xmm0, %xmm2
movapd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq