// File: 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 %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movsd %xmm0, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
movsd 0x4faa9(%rip), %xmm0    # 0x55008
movsd %xmm0, (%rax)
movsd 0x4ff05(%rip), %xmm0    # 0x55470
movsd %xmm0, -0x70(%rbp)
movsd 0x4fef0(%rip), %xmm0    # 0x55468
movsd %xmm0, -0x78(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x4fed6(%rip), %xmm1    # 0x55460
callq 0x3c440
testb $0x1, %al
jne 0x5598
jmp 0x56f8
movsd -0x10(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x5530
movsd %xmm0, -0x58(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c940
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c910
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x5620
movq -0x18(%rbp), %rax
movsd 0x4fbb6(%rip), %xmm0    # 0x551d0
movsd %xmm0, (%rax)
jmp 0x5630
movq -0x18(%rbp), %rax
movsd 0x4f9dc(%rip), %xmm0    # 0x55008
movsd %xmm0, (%rax)
movsd -0x48(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd 0x4fe04(%rip), %xmm1    # 0x55450
callq 0x3c4c0
testb $0x1, %al
jne 0x5657
jmp 0x5678
movsd 0x4f9a9(%rip), %xmm0    # 0x55008
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
subsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd 0x4fdcb(%rip), %xmm0    # 0x55458
mulsd -0x60(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cb90
movaps %xmm0, %xmm1
movsd -0x98(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
subsd %xmm1, %xmm0
subsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x5c06
movsd -0x10(%rbp), %xmm0
movsd 0x4fd73(%rip), %xmm1    # 0x55478
callq 0x3c440
testb $0x1, %al
jne 0x5713
jmp 0x5a37
movsd 0x4f8ed(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x60(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd 0x4fa71(%rip), %xmm1    # 0x551b0
callq 0x3c500
testb $0x1, %al
jne 0x574a
jmp 0x5780
movsd -0x40(%rbp), %xmm0
movsd 0x4f8b1(%rip), %xmm1    # 0x55008
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x60(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x5732
jmp 0x5782
movsd -0x50(%rbp), %xmm0
movsd 0x4fc39(%rip), %xmm1    # 0x553c8
callq 0x3c440
testb $0x1, %al
jne 0x579a
jmp 0x57cc
movsd -0x60(%rbp), %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x4f857(%rip), %xmm0    # 0x55008
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x5782
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0x57df
jmp 0x5812
movq -0x18(%rbp), %rax
movsd 0x4f9e5(%rip), %xmm0    # 0x551d0
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x5822
movq -0x18(%rbp), %rax
movsd 0x4f7ea(%rip), %xmm0    # 0x55008
movsd %xmm0, (%rax)
movsd -0x50(%rbp), %xmm0
movsd 0x4fb99(%rip), %xmm1    # 0x553c8
callq 0x3c3d0
testb $0x1, %al
jne 0x583a
jmp 0x5862
movsd -0x60(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x5c06
movsd -0x40(%rbp), %xmm0
movsd 0x4fb59(%rip), %xmm1    # 0x553c8
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x4fc91(%rip), %xmm0    # 0x55520
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fc6e(%rip), %xmm1    # 0x55518
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fc47(%rip), %xmm1    # 0x55510
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fc20(%rip), %xmm1    # 0x55508
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fbf9(%rip), %xmm1    # 0x55500
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fbd2(%rip), %xmm1    # 0x554f8
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x4f6d1(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fb9e(%rip), %xmm1    # 0x554f0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fb77(%rip), %xmm1    # 0x554e8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fb50(%rip), %xmm1    # 0x554e0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fb29(%rip), %xmm1    # 0x554d8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fb02(%rip), %xmm1    # 0x554d0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4fadb(%rip), %xmm1    # 0x554c8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x5c06
movsd -0x10(%rbp), %xmm0
movsd 0x4fa0c(%rip), %xmm1    # 0x55450
subsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3cd70
movaps %xmm0, %xmm2
movsd -0xa0(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x4f9dc(%rip), %xmm1    # 0x55480
callq 0x3c4c0
testb $0x1, %al
jne 0x5aaf
jmp 0x5ace
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x5c06
movsd -0x10(%rbp), %xmm1
mulsd -0x10(%rbp), %xmm1
movsd 0x4f528(%rip), %xmm0    # 0x55008
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x4f6d2(%rip), %xmm1    # 0x551c8
callq 0x3c500
testb $0x1, %al
jne 0x5b01
jmp 0x5b4b
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd 0x4f9a5(%rip), %xmm2    # 0x554b8
mulsd %xmm2, %xmm1
movsd 0x4f9a1(%rip), %xmm2    # 0x554c0
addsd %xmm2, %xmm1
movsd -0x40(%rbp), %xmm2
mulsd %xmm2, %xmm1
movsd 0x4f97c(%rip), %xmm2    # 0x554b0
addsd %xmm2, %xmm1
divsd -0x10(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x5bec
movsd 0x4f955(%rip), %xmm0    # 0x554a8
movsd %xmm0, -0x28(%rbp)
movsd -0x40(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4f932(%rip), %xmm1    # 0x554a0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x40(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4f90b(%rip), %xmm1    # 0x55498
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x40(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4f8e4(%rip), %xmm1    # 0x55490
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x40(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x4f8bd(%rip), %xmm1    # 0x55488
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
divsd -0x10(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)