// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::psi(double, alglib_impl::ae_state*)
double psi(double x, ae_state *_state)
{
    double p;
    double q;
    double nz;
    double s;
    double w;
    double y;
    double z;
    double polv;
    ae_int_t i;
    ae_int_t n;
    ae_int_t negative;
    double result;


    negative = 0;
    nz = 0.0;
    if( ae_fp_less_eq(x,0) )
    {
        negative = 1;
        q = x;
        p = ae_ifloor(q, _state);
        if( ae_fp_eq(p,q) )
        {
            ae_assert(ae_false, "Singularity in Psi(x)", _state);
            result = ae_maxrealnumber;
            return result;
        }
        nz = q-p;
        if( ae_fp_neq(nz,0.5) )
        {
            if( ae_fp_greater(nz,0.5) )
            {
                p = p+1.0;
                nz = q-p;
            }
            nz = ae_pi/ae_tan(ae_pi*nz, _state);
        }
        else
        {
            nz = 0.0;
        }
        x = 1.0-x;
    }
    if( ae_fp_less_eq(x,10.0)&&ae_fp_eq(x,ae_ifloor(x, _state)) )
    {
        y = 0.0;
        n = ae_ifloor(x, _state);
        for(i=1; i<=n-1; i++)
        {
            w = i;
            y = y+1.0/w;
        }
        y = y-0.57721566490153286061;
    }
    else
    {
        s = x;
        w = 0.0;
        while(ae_fp_less(s,10.0))
        {
            w = w+1.0/s;
            s = s+1.0;
        }
        if( ae_fp_less(s,1.0E17) )
        {
            z = 1.0/(s*s);
            polv = 8.33333333333333333333E-2;
            polv = polv*z-2.10927960927960927961E-2;
            polv = polv*z+7.57575757575757575758E-3;
            polv = polv*z-4.16666666666666666667E-3;
            polv = polv*z+3.96825396825396825397E-3;
            polv = polv*z-8.33333333333333333333E-3;
            polv = polv*z+8.33333333333333333333E-2;
            y = z*polv;
        }
        else
        {
            y = 0.0;
        }
        y = ae_log(s, _state)-0.5/s-y-w;
    }
    if( negative!=0 )
    {
        y = y-nz;
    }
    result = y;
    return result;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movapd %xmm0, %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
callq 0x2631e
movl %eax, %ebx
testb %al, %al
je 0x117e8
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x265d3
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0x262ba
testb %al, %al
je 0x117f3
leaq 0x25094(%rip), %rsi     # 0x36865
xorl %edi, %edi
movq %r14, %rdx
callq 0x2581c
movsd 0x22e55(%rip), %xmm0    # 0x34638
jmp 0x11a55
movsd 0x8(%rsp), %xmm0
jmp 0x1188f
movsd 0x8(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
movsd 0x22c61(%rip), %xmm1    # 0x34468
movsd %xmm0, 0x18(%rsp)
callq 0x262dc
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
testb %al, %al
je 0x11881
movsd 0x22c40(%rip), %xmm1    # 0x34468
movsd 0x18(%rsp), %xmm0
callq 0x2633e
testb %al, %al
jne 0x1183f
movsd 0x18(%rsp), %xmm0
jmp 0x11857
movsd 0x10(%rsp), %xmm1
addsd 0x22953(%rip), %xmm1    # 0x341a0
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd 0x22c11(%rip), %xmm1    # 0x34470
movsd %xmm1, 0x20(%rsp)
mulsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x266ae
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x22917(%rip), %xmm0    # 0x341a0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x22cab(%rip), %xmm1    # 0x34548
callq 0x2631e
testb %al, %al
je 0x1191d
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x265d3
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x262ba
testb %al, %al
je 0x1191d
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x265d3
cmpq $0x2, %rax
jl 0x11a5d
xorpd %xmm0, %xmm0
movl $0x1, %ecx
movsd 0x228ac(%rip), %xmm1    # 0x341a0
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
movapd %xmm1, %xmm3
divsd %xmm2, %xmm3
addsd %xmm3, %xmm0
incq %rcx
cmpq %rcx, %rax
jne 0x118f4
addsd 0x23b50(%rip), %xmm0    # 0x35468
jmp 0x11a4b
movsd 0x22c23(%rip), %xmm1    # 0x34548
movsd 0x8(%rsp), %xmm0
callq 0x262fe
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorpd %xmm2, %xmm2
testb %al, %al
je 0x1198a
movsd 0x8(%rsp), %xmm0
movsd 0x22851(%rip), %xmm3    # 0x341a0
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
addsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
addsd %xmm3, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x22bd5(%rip), %xmm1    # 0x34548
callq 0x262fe
movsd 0x10(%rsp), %xmm2
movsd 0x8(%rsp), %xmm0
testb %al, %al
jne 0x11947
jmp 0x11990
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm2, 0x10(%rsp)
movsd 0x243f4(%rip), %xmm1    # 0x35d98
callq 0x262fe
testb %al, %al
movsd 0x8(%rsp), %xmm0
je 0x11a21
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movsd 0x227dd(%rip), %xmm1    # 0x341a0
divsd %xmm2, %xmm1
movsd 0x22b09(%rip), %xmm2    # 0x344d8
movapd %xmm1, %xmm3
mulsd %xmm2, %xmm3
addsd 0x243c1(%rip), %xmm3    # 0x35da0
mulsd %xmm1, %xmm3
addsd 0x243bd(%rip), %xmm3    # 0x35da8
mulsd %xmm1, %xmm3
addsd 0x243b9(%rip), %xmm3    # 0x35db0
mulsd %xmm1, %xmm3
addsd 0x243b5(%rip), %xmm3    # 0x35db8
mulsd %xmm1, %xmm3
addsd 0x243b1(%rip), %xmm3    # 0x35dc0
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x18(%rsp)
movq %r14, %rdi
callq 0x266d6
movapd %xmm0, %xmm1
movsd 0x22a53(%rip), %xmm0    # 0x34488
divsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
subsd 0x18(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
testb %bl, %bl
je 0x11a55
subsd 0x20(%rsp), %xmm0
addq $0x28, %rsp
popq %rbx
popq %r14
retq
movsd 0x23a03(%rip), %xmm0    # 0x35468
jmp 0x11a4b