// File: /workspace/github_cpp_makefile_star2_O3/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::besselkn(long, double, alglib_impl::ae_state*)
double besselkn(ae_int_t nn, double x, ae_state *_state)
{
    double k;
    double kf;
    double nk1f;
    double nkf;
    double zn;
    double t;
    double s;
    double z0;
    double z;
    double ans;
    double fn;
    double pn;
    double pk;
    double zmn;
    double tlg;
    double tox;
    ae_int_t i;
    ae_int_t n;
    double eul;
    double result;


    eul = 5.772156649015328606065e-1;
    if( nn<0 )
    {
        n = -nn;
    }
    else
    {
        n = nn;
    }
    ae_assert(n<=31, "Overflow in BesselKN", _state);
    ae_assert(ae_fp_greater(x,0), "Domain error in BesselKN", _state);
    if( ae_fp_less_eq(x,9.55) )
    {
        ans = 0.0;
        z0 = 0.25*x*x;
        fn = 1.0;
        pn = 0.0;
        zmn = 1.0;
        tox = 2.0/x;
        if( n>0 )
        {
            pn = -eul;
            k = 1.0;
            for(i=1; i<=n-1; i++)
            {
                pn = pn+1.0/k;
                k = k+1.0;
                fn = fn*k;
            }
            zmn = tox;
            if( n==1 )
            {
                ans = 1.0/x;
            }
            else
            {
                nk1f = fn/n;
                kf = 1.0;
                s = nk1f;
                z = -z0;
                zn = 1.0;
                for(i=1; i<=n-1; i++)
                {
                    nk1f = nk1f/(n-i);
                    kf = kf*i;
                    zn = zn*z;
                    t = nk1f*zn/kf;
                    s = s+t;
                    ae_assert(ae_fp_greater(ae_maxrealnumber-ae_fabs(t, _state),ae_fabs(s, _state)), "Overflow in BesselKN", _state);
                    ae_assert(!(ae_fp_greater(tox,1.0)&&ae_fp_less(ae_maxrealnumber/tox,zmn)), "Overflow in BesselKN", _state);
                    zmn = zmn*tox;
                }
                s = s*0.5;
                t = ae_fabs(s, _state);
                ae_assert(!(ae_fp_greater(zmn,1.0)&&ae_fp_less(ae_maxrealnumber/zmn,t)), "Overflow in BesselKN", _state);
                ae_assert(!(ae_fp_greater(t,1.0)&&ae_fp_less(ae_maxrealnumber/t,zmn)), "Overflow in BesselKN", _state);
                ans = s*zmn;
            }
        }
        tlg = 2.0*ae_log(0.5*x, _state);
        pk = -eul;
        if( n==0 )
        {
            pn = pk;
            t = 1.0;
        }
        else
        {
            pn = pn+1.0/n;
            t = 1.0/fn;
        }
        s = (pk+pn-tlg)*t;
        k = 1.0;
        do
        {
            t = t*(z0/(k*(k+n)));
            pk = pk+1.0/k;
            pn = pn+1.0/(k+n);
            s = s+(pk+pn-tlg)*t;
            k = k+1.0;
        }
        while(ae_fp_greater(ae_fabs(t/s, _state),ae_machineepsilon));
        s = 0.5*s/zmn;
        if( n%2!=0 )
        {
            s = -s;
        }
        ans = ans+s;
        result = ans;
        return result;
    }
    if( ae_fp_greater(x,ae_log(ae_maxrealnumber, _state)) )
    {
        result = 0;
        return result;
    }
    k = n;
    pn = 4.0*k*k;
    pk = 1.0;
    z0 = 8.0*x;
    fn = 1.0;
    t = 1.0;
    s = t;
    nkf = ae_maxrealnumber;
    i = 0;
    do
    {
        z = pn-pk*pk;
        t = t*z/(fn*z0);
        nk1f = ae_fabs(t, _state);
        if( i>=n&&ae_fp_greater(nk1f,nkf) )
        {
            break;
        }
        nkf = nk1f;
        s = s+t;
        fn = fn+1.0;
        pk = pk+2.0;
        i = i+1;
    }
    while(ae_fp_greater(ae_fabs(t/s, _state),ae_machineepsilon));
    result = ae_exp(-x, _state)*ae_sqrt(ae_pi/(2.0*x), _state)*s;
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rdi, %r12
negq %r12
cmovsq %rdi, %r12
movaps %xmm0, 0x40(%rsp)
xorl %edi, %edi
cmpq $0x20, %r12
setb %dil
leaq 0x2bd4c(%rip), %rsi     # 0x35744
movq %rbx, %rdx
callq 0x2510e
xorps %xmm1, %xmm1
movaps 0x40(%rsp), %xmm0
callq 0x25bf9
movzbl %al, %edi
leaq 0x2bd42(%rip), %rsi     # 0x35759
movq %rbx, %rdx
callq 0x2510e
movsd 0x2a829(%rip), %xmm1    # 0x34250
movaps 0x40(%rsp), %xmm0
callq 0x25bd9
testb %al, %al
je 0x9ab2
movsd 0x2a81b(%rip), %xmm4    # 0x34258
movapd 0x40(%rsp), %xmm0
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm4
movsd 0x2978d(%rip), %xmm2    # 0x331e0
testq %r14, %r14
movapd %xmm4, 0x90(%rsp)
je 0x9c3a
movsd 0x29993(%rip), %xmm7    # 0x33400
cmpq $0x2, %r12
jb 0x9c5a
leaq -0x1(%r12), %rax
movsd 0x2a7dc(%rip), %xmm5    # 0x34260
movsd 0x29754(%rip), %xmm3    # 0x331e0
movapd %xmm3, %xmm1
movapd %xmm3, %xmm6
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm5
addsd %xmm3, %xmm1
mulsd %xmm1, %xmm6
decq %rax
jne 0x9a94
jmp 0x9c6a
movsd 0x29ba6(%rip), %xmm0    # 0x33660
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x25f91
movapd %xmm0, %xmm1
movapd 0x40(%rsp), %xmm0
callq 0x25bf9
testb %al, %al
xorpd %xmm0, %xmm0
jne 0xa081
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd 0x296fe(%rip), %xmm1    # 0x331f0
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x29b70(%rip), %xmm0    # 0x33678
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movapd 0x2b294(%rip), %xmm2    # 0x34db0
movsd 0x296bc(%rip), %xmm0    # 0x331e0
xorl %r14d, %r14d
movsd %xmm0, 0x50(%rsp)
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
mulsd %xmm3, %xmm3
movsd 0x38(%rsp), %xmm1
subsd %xmm3, %xmm1
mulsd %xmm1, %xmm0
movsd 0x60(%rsp), %xmm1
movapd %xmm2, 0x10(%rsp)
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
callq 0x25e30
movsd %xmm0, 0x28(%rsp)
cmpq %r12, %r14
jb 0x9b88
movsd 0x28(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x25bf9
testb %al, %al
jne 0x9bf1
movsd 0x50(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
addsd %xmm2, %xmm1
movapd 0x10(%rsp), %xmm0
addpd 0x2b30a(%rip), %xmm0    # 0x34eb0
movapd %xmm0, 0x10(%rsp)
incq %r14
movapd %xmm2, %xmm0
movsd %xmm1, 0x50(%rsp)
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x25e30
movsd 0x29c23(%rip), %xmm1    # 0x337f0
callq 0x25bf9
movsd 0x30(%rsp), %xmm0
movapd 0x10(%rsp), %xmm2
movsd 0x28(%rsp), %xmm1
movsd %xmm1, (%rsp)
testb %al, %al
jne 0x9b2d
movaps 0x295b8(%rip), %xmm0    # 0x331b0
xorps 0x40(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f9b
movsd %xmm0, 0x10(%rsp)
movapd 0x40(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0x29873(%rip), %xmm0    # 0x33490
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x25e48
mulsd 0x10(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
jmp 0xa081
xorpd %xmm1, %xmm1
movsd %xmm1, (%rsp)
movsd %xmm2, 0x70(%rsp)
movsd %xmm1, 0x78(%rsp)
movsd %xmm2, 0x8(%rsp)
jmp 0x9ef5
movsd 0x2a5fe(%rip), %xmm5    # 0x34260
movsd 0x29576(%rip), %xmm6    # 0x331e0
movsd %xmm5, 0x78(%rsp)
divsd %xmm0, %xmm7
cmpq $0x1, %r12
movsd %xmm6, 0x70(%rsp)
jne 0x9c9c
movsd 0x29558(%rip), %xmm1    # 0x331e0
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd %xmm7, 0x8(%rsp)
jmp 0x9ef5
movq %r14, 0x80(%rsp)
movapd 0x29504(%rip), %xmm0    # 0x331b0
xorpd %xmm4, %xmm0
movapd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movapd %xmm6, %xmm1
divsd %xmm0, %xmm1
movsd 0x29992(%rip), %xmm0    # 0x33660
divsd %xmm7, %xmm0
movsd %xmm0, 0x88(%rsp)
cmpq $0x3, %r12
movl $0x2, %r13d
cmovaeq %r12, %r13
leaq -0x1(%r12), %rbp
movsd 0x294ea(%rip), %xmm0    # 0x331e0
movl $0x1, %r14d
leaq 0x2ba41(%rip), %r15     # 0x35744
movapd %xmm0, %xmm4
movsd %xmm7, 0x8(%rsp)
movapd %xmm0, %xmm2
movsd %xmm1, (%rsp)
movapd %xmm1, %xmm3
movsd %xmm7, 0x10(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %rbp, %xmm1
divsd %xmm1, %xmm3
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
mulsd %xmm4, %xmm1
mulsd 0x60(%rsp), %xmm2
movsd %xmm2, 0x30(%rsp)
movapd %xmm2, %xmm0
movsd %xmm3, 0x28(%rsp)
mulsd %xmm3, %xmm0
movsd %xmm1, 0x50(%rsp)
divsd %xmm1, %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x25e30
movsd 0x298e6(%rip), %xmm1    # 0x33660
subsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movsd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x25e30
movaps %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
callq 0x25bf9
movzbl %al, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2510e
movsd 0x10(%rsp), %xmm0
movsd 0x29425(%rip), %xmm1    # 0x331e0
callq 0x25bf9
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
je 0x9dde
movsd 0x88(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x25bb9
xorb $0x1, %al
movzbl %al, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2510e
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm7
mulsd %xmm7, %xmm0
movsd %xmm0, 0x8(%rsp)
incq %r14
decq %rbp
cmpq %r14, %r13
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
movsd 0x50(%rsp), %xmm4
jne 0x9d20
movsd (%rsp), %xmm0
mulsd 0x29658(%rip), %xmm0    # 0x33488
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x25e30
movsd %xmm0, 0x10(%rsp)
movsd 0x29395(%rip), %xmm1    # 0x331e0
movsd 0x8(%rsp), %xmm0
callq 0x25bf9
movl %eax, %ecx
movb $0x1, %bpl
movb $0x1, %al
testb %cl, %cl
je 0x9e7c
movsd 0x297f7(%rip), %xmm0    # 0x33660
divsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x25bb9
xorb $0x1, %al
movzbl %al, %edi
leaq 0x2b8be(%rip), %rsi     # 0x35744
movq %rbx, %rdx
callq 0x2510e
movsd 0x2934a(%rip), %xmm1    # 0x331e0
movsd 0x10(%rsp), %xmm0
callq 0x25bf9
testb %al, %al
movq 0x80(%rsp), %r14
je 0x9ecc
movsd 0x297ab(%rip), %xmm0    # 0x33660
divsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x25bb9
movl %eax, %ebp
xorb $0x1, %bpl
movzbl %bpl, %edi
leaq 0x2b86d(%rip), %rsi     # 0x35744
movq %rbx, %rdx
callq 0x2510e
movsd (%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movapd 0x40(%rsp), %xmm0
xorl %ebp, %ebp
testq %r14, %r14
sete %bpl
mulsd 0x29582(%rip), %xmm0    # 0x33488
movq %rbx, %rdi
callq 0x25f91
addsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
movsd 0x292be(%rip), %xmm3    # 0x331e0
movapd %xmm3, %xmm2
movsd %xmm1, 0x60(%rsp)
divsd %xmm1, %xmm2
addsd 0x78(%rsp), %xmm2
movapd %xmm3, %xmm1
divsd 0x70(%rsp), %xmm1
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movd %ebp, %xmm1
pshufd $0x0, %xmm1, %xmm5      # xmm5 = xmm1[0,0,0,0]
pslld $0x1f, %xmm5
psrad $0x1f, %xmm5
movdqa %xmm5, %xmm1
pand 0x2af5d(%rip), %xmm5    # 0x34ec0
pandn %xmm2, %xmm1
por %xmm1, %xmm5
movsd 0x2a2ed(%rip), %xmm6    # 0x34260
movdqa %xmm5, %xmm1
addsd %xmm6, %xmm1
movsd %xmm0, 0x38(%rsp)
subsd %xmm0, %xmm1
pshufd $0xee, %xmm5, %xmm4     # xmm4 = xmm5[2,3,2,3]
mulsd %xmm1, %xmm4
movapd 0x2ad7a(%rip), %xmm0    # 0x34d10
unpcklpd 0x90(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd %xmm0, 0x40(%rsp)
movapd %xmm3, %xmm7
movapd %xmm7, %xmm1
addsd 0x60(%rsp), %xmm1
movapd %xmm7, %xmm0
mulsd %xmm1, %xmm0
movapd %xmm3, %xmm2
divsd %xmm7, %xmm2
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x40(%rsp), %xmm0
divpd %xmm1, %xmm0
addsd %xmm2, %xmm6
movsd %xmm6, 0x30(%rsp)
movdqa %xmm5, %xmm1
addpd %xmm0, %xmm1
mulpd %xmm5, %xmm0
movapd %xmm0, %xmm2
movsd %xmm1, %xmm2            # xmm2 = xmm1[0],xmm2[1]
movapd %xmm2, 0x50(%rsp)
addsd %xmm6, %xmm1
subsd 0x38(%rsp), %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulsd %xmm0, %xmm1
addsd %xmm1, %xmm4
movapd %xmm4, 0x10(%rsp)
divsd %xmm4, %xmm0
addsd %xmm3, %xmm7
movsd %xmm7, 0x28(%rsp)
movq %rbx, %rdi
callq 0x25e30
movsd 0x297c1(%rip), %xmm1    # 0x337f0
callq 0x25bf9
movsd 0x28(%rsp), %xmm7
movsd 0x30(%rsp), %xmm6
movapd 0x50(%rsp), %xmm5
movapd 0x10(%rsp), %xmm4
movsd 0x2918c(%rip), %xmm3    # 0x331e0
testb %al, %al
jne 0x9fa9
mulsd 0x29424(%rip), %xmm4    # 0x33488
divsd 0x8(%rsp), %xmm4
testb $0x1, %r12b
je 0xa078
xorpd 0x29138(%rip), %xmm4    # 0x331b0
movsd (%rsp), %xmm0
addsd %xmm4, %xmm0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq