// File: 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 %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movsd %xmm0, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movsd 0x5011f(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x50(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0x504b2(%rip), %xmm1    # 0x553c0
callq 0x3c4c0
testb $0x1, %al
jne 0x4f1c
jmp 0x506e
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x4f32
jmp 0x503d
movsd -0x30(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c940
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c910
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x4f7d
movsd 0x50258(%rip), %xmm0    # 0x551d0
movsd %xmm0, -0x50(%rbp)
movsd -0x30(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd 0x504b7(%rip), %xmm1    # 0x55450
callq 0x3c4c0
testb $0x1, %al
jne 0x4fa4
jmp 0x4fc5
movsd 0x5005c(%rip), %xmm0    # 0x55008
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x30(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x50481(%rip), %xmm0    # 0x55458
mulsd -0x40(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3cb90
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x1bfa0
movsd -0x60(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x50426(%rip), %xmm0    # 0x55458
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x5050
movsd -0x10(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x1bfa0
movsd %xmm0, -0x40(%rbp)
movsd -0x50(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x53f5
movsd 0x4ff92(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x50128(%rip), %xmm1    # 0x551b0
callq 0x3c500
testb $0x1, %al
jne 0x5093
jmp 0x50ba
movsd -0x10(%rbp), %xmm0
movsd 0x4ff68(%rip), %xmm1    # 0x55008
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x40(%rbp), %xmm0
mulsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x507b
jmp 0x50bc
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x50cf
jmp 0x514c
movsd -0x10(%rbp), %xmm0
movsd 0x5036c(%rip), %xmm1    # 0x55448
callq 0x3c4c0
testb $0x1, %al
jne 0x50e7
jmp 0x5126
movsd -0x40(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
movsd 0x50347(%rip), %xmm2    # 0x55440
mulsd %xmm2, %xmm1
movsd 0x4ff03(%rip), %xmm2    # 0x55008
addsd %xmm2, %xmm1
mulsd -0x10(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x53f5
movsd -0x40(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x4fecb(%rip), %xmm0    # 0x55008
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0x50bc
jmp 0x514e
movsd -0x10(%rbp), %xmm0
movsd 0x5026d(%rip), %xmm1    # 0x553c8
callq 0x3c440
testb $0x1, %al
jne 0x5166
jmp 0x51e3
movsd -0x10(%rbp), %xmm0
movsd 0x502c5(%rip), %xmm1    # 0x55438
callq 0x3c440
testb $0x1, %al
jne 0x517e
jmp 0x51bd
movsd -0x40(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
movsd 0x502b0(%rip), %xmm2    # 0x55440
mulsd %xmm2, %xmm1
movsd 0x4fe6c(%rip), %xmm2    # 0x55008
addsd %xmm2, %xmm1
mulsd -0x10(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x53f5
movsd -0x40(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x4fe34(%rip), %xmm0    # 0x55008
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0x514e
movsd -0x10(%rbp), %xmm0
movsd 0x501d8(%rip), %xmm1    # 0x553c8
callq 0x3c3d0
testb $0x1, %al
jne 0x51fb
jmp 0x5214
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x53f5
movsd -0x10(%rbp), %xmm0
movsd 0x501a7(%rip), %xmm1    # 0x553c8
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x501fe(%rip), %xmm0    # 0x55430
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x501db(%rip), %xmm1    # 0x55428
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x501b4(%rip), %xmm1    # 0x55420
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x5018d(%rip), %xmm1    # 0x55418
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x50166(%rip), %xmm1    # 0x55410
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x5013f(%rip), %xmm1    # 0x55408
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fd20(%rip), %xmm1    # 0x55008
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x50107(%rip), %xmm0    # 0x55400
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x500e4(%rip), %xmm1    # 0x553f8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x500bd(%rip), %xmm1    # 0x553f0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x50096(%rip), %xmm1    # 0x553e8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x5006f(%rip), %xmm1    # 0x553e0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x50048(%rip), %xmm1    # 0x553d8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x50021(%rip), %xmm1    # 0x553d0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fc3a(%rip), %xmm1    # 0x55008
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x40(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq