// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
callq 0x24259
movl %eax, %ebx
testb %al, %al
je 0x10aee
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x24468
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0x241f5
testb %al, %al
je 0x10af9
leaq 0x21f1e(%rip), %rsi     # 0x329f5
xorl %edi, %edi
movq %r14, %rdx
callq 0x238ca
movsd 0x1fb77(%rip), %xmm0    # 0x30660
jmp 0x10d2e
movsd 0x8(%rsp), %xmm0
jmp 0x10b95
movsd 0x8(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
movsd 0x1f97b(%rip), %xmm1    # 0x30488
movsd %xmm0, 0x20(%rsp)
callq 0x24217
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
testb %al, %al
je 0x10b87
movsd 0x1f95a(%rip), %xmm1    # 0x30488
movsd 0x20(%rsp), %xmm0
callq 0x24279
testb %al, %al
jne 0x10b45
movsd 0x20(%rsp), %xmm0
jmp 0x10b5d
movsd 0x10(%rsp), %xmm1
addsd 0x1f6a5(%rip), %xmm1    # 0x301f8
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd 0x1f92b(%rip), %xmm1    # 0x30490
movsd %xmm1, 0x18(%rsp)
mulsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x24537
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x1f669(%rip), %xmm0    # 0x301f8
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x1f9cd(%rip), %xmm1    # 0x30570
callq 0x24259
testb %al, %al
je 0x10c0a
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x24468
cvtsi2sd %rax, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x241f5
testb %al, %al
je 0x10c0a
movsd 0x8(%rsp), %xmm0
movq %r14, %rdi
callq 0x24468
pushq $0x1
popq %rcx
xorpd %xmm0, %xmm0
movsd 0x1f60d(%rip), %xmm1    # 0x301f8
cmpq %rax, %rcx
jge 0x10d1c
cvtsi2sd %rcx, %xmm2
movapd %xmm1, %xmm3
divsd %xmm2, %xmm3
addsd %xmm3, %xmm0
incq %rcx
jmp 0x10beb
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x1f948(%rip), %xmm1    # 0x30570
callq 0x24239
testb %al, %al
je 0x10c61
movsd 0x1f5bf(%rip), %xmm2    # 0x301f8
movapd %xmm2, %xmm0
movsd 0x8(%rsp), %xmm3
divsd %xmm3, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
addsd %xmm2, %xmm3
movapd %xmm3, %xmm0
jmp 0x10c1a
movsd 0x20c47(%rip), %xmm1    # 0x318b0
movsd 0x8(%rsp), %xmm0
callq 0x24239
xorpd %xmm3, %xmm3
testb %al, %al
movsd 0x8(%rsp), %xmm0
je 0x10cea
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x1f566(%rip), %xmm2    # 0x301f8
divsd %xmm1, %xmm2
movsd 0x1f862(%rip), %xmm1    # 0x30500
movapd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd 0x20c0a(%rip), %xmm3    # 0x318b8
mulsd %xmm2, %xmm3
addsd 0x20c06(%rip), %xmm3    # 0x318c0
mulsd %xmm2, %xmm3
addsd 0x20c02(%rip), %xmm3    # 0x318c8
mulsd %xmm2, %xmm3
addsd 0x20bfe(%rip), %xmm3    # 0x318d0
mulsd %xmm2, %xmm3
addsd 0x20bfa(%rip), %xmm3    # 0x318d8
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x20(%rsp)
movq %r14, %rdi
callq 0x2455f
movapd %xmm0, %xmm1
movsd 0x1f7a4(%rip), %xmm0    # 0x304a8
divsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
subsd 0x20(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
jmp 0x10d24
addsd 0x2053c(%rip), %xmm0    # 0x31260
testb %bl, %bl
je 0x10d2e
subsd 0x18(%rsp), %xmm0
addq $0x28, %rsp
popq %rbx
popq %r14
retq