// File: /workspace/github_cpp_makefile_star2_O2/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 0x2947c(%rip), %rsi     # 0x32734
movq %rbx, %rdx
callq 0x238ca
xorps %xmm1, %xmm1
movaps 0x40(%rsp), %xmm0
callq 0x24279
movzbl %al, %edi
leaq 0x29472(%rip), %rsi     # 0x32749
movq %rbx, %rdx
callq 0x238ca
movsd 0x27f69(%rip), %xmm1    # 0x31250
movaps 0x40(%rsp), %xmm0
callq 0x24259
testb %al, %al
je 0x9374
movsd 0x27f5b(%rip), %xmm4    # 0x31258
movapd 0x40(%rsp), %xmm0
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm4
movsd 0x26ee5(%rip), %xmm2    # 0x301f8
testq %r14, %r14
movapd %xmm4, 0x90(%rsp)
je 0x9536
movsd 0x270cb(%rip), %xmm1    # 0x303f8
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
leaq -0x1(%r12), %rax
movsd 0x27f1c(%rip), %xmm6    # 0x31260
movsd 0x26eac(%rip), %xmm3    # 0x301f8
movapd %xmm3, %xmm5
movapd %xmm3, %xmm1
subq $0x1, %rax
jb 0x94fc
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm6
addsd %xmm3, %xmm1
mulsd %xmm1, %xmm5
jmp 0x9354
movsd 0x272e4(%rip), %xmm0    # 0x30660
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2455f
movapd %xmm0, %xmm1
movapd 0x40(%rsp), %xmm0
callq 0x24279
testb %al, %al
xorpd %xmm0, %xmm0
jne 0x9909
cvtsi2sd %r12, %xmm0
movsd 0x26e36(%rip), %xmm1    # 0x301e8
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movsd 0x272b0(%rip), %xmm0    # 0x30678
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movapd 0x289d4(%rip), %xmm2    # 0x31db0
movsd 0x26e14(%rip), %xmm0    # 0x301f8
xorl %r14d, %r14d
movsd %xmm0, 0x50(%rsp)
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
mulsd %xmm3, %xmm3
movsd 0x70(%rsp), %xmm1
subsd %xmm3, %xmm1
mulsd %xmm1, %xmm0
movsd 0x60(%rsp), %xmm1
movapd %xmm2, 0x10(%rsp)
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
callq 0x2440c
movsd %xmm0, 0x30(%rsp)
cmpq %r12, %r14
jb 0x9449
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x24279
testb %al, %al
jne 0x94b3
movsd 0x50(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
addsd %xmm2, %xmm1
movapd 0x10(%rsp), %xmm0
addpd 0x28a39(%rip), %xmm0    # 0x31ea0
movapd %xmm0, 0x10(%rsp)
incq %r14
movapd %xmm2, %xmm0
movsd %xmm1, 0x50(%rsp)
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd 0x27362(%rip), %xmm1    # 0x307f0
callq 0x24279
movsd 0x38(%rsp), %xmm0
movapd 0x10(%rsp), %xmm2
movsd 0x30(%rsp), %xmm1
movsd %xmm1, 0x28(%rsp)
testb %al, %al
jne 0x93ed
movaps 0x26cf6(%rip), %xmm0    # 0x301b0
xorps 0x40(%rsp), %xmm0
movq %rbx, %rdi
callq 0x24569
movsd %xmm0, 0x10(%rsp)
movapd 0x40(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0x26fb1(%rip), %xmm0    # 0x30490
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x24424
mulsd 0x10(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
jmp 0x9909
movsd %xmm6, 0x80(%rsp)
cmpq $0x1, %r12
movsd %xmm5, 0x88(%rsp)
jne 0x955b
movsd 0x26cdc(%rip), %xmm1    # 0x301f8
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, (%rsp)
jmp 0x977a
xorps %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm2, 0x88(%rsp)
movsd %xmm1, 0x80(%rsp)
movsd %xmm2, (%rsp)
jmp 0x977a
cvtsi2sd %r12, %xmm0
divsd %xmm0, %xmm5
movapd 0x26c44(%rip), %xmm0    # 0x301b0
xorpd %xmm4, %xmm0
movapd %xmm0, 0x70(%rsp)
movsd 0x270e2(%rip), %xmm1    # 0x30660
movsd 0x10(%rsp), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
leaq -0x1(%r12), %rax
pushq $0x1
popq %r13
movsd 0x26c59(%rip), %xmm2    # 0x301f8
leaq 0x2918e(%rip), %r15     # 0x32734
movapd %xmm2, %xmm3
movapd %xmm5, %xmm1
movsd %xmm0, (%rsp)
movq %rax, %rbp
subq $0x1, %rbp
jb 0x96b2
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm5
cvtsi2sd %r13, %xmm0
mulsd %xmm0, %xmm2
mulsd 0x70(%rsp), %xmm3
movsd %xmm3, 0x30(%rsp)
movapd %xmm3, %xmm0
movsd %xmm5, 0x38(%rsp)
mulsd %xmm5, %xmm0
movsd %xmm2, 0x50(%rsp)
divsd %xmm2, %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %rbx, %rdi
callq 0x2440c
movsd 0x27050(%rip), %xmm1    # 0x30660
subsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2440c
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
callq 0x24279
movzbl %al, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x238ca
movsd 0x10(%rsp), %xmm0
movsd 0x26ba6(%rip), %xmm1    # 0x301f8
callq 0x24279
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
je 0x9671
movsd 0x60(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x24239
xorb $0x1, %al
movzbl %al, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x238ca
movsd (%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
incq %r13
movq %rbp, %rax
movsd 0x8(%rsp), %xmm1
movsd 0x38(%rsp), %xmm5
movsd 0x30(%rsp), %xmm3
movsd 0x50(%rsp), %xmm2
jmp 0x95b6
mulsd 0x26dce(%rip), %xmm1    # 0x30488
movsd %xmm1, 0x8(%rsp)
movapd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2440c
movsd %xmm0, 0x10(%rsp)
movsd 0x26b1e(%rip), %xmm1    # 0x301f8
movsd (%rsp), %xmm0
callq 0x24279
movl %eax, %ecx
movb $0x1, %bpl
movb $0x1, %al
testb %cl, %cl
je 0x9709
movsd 0x26f69(%rip), %xmm0    # 0x30660
divsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x24239
xorb $0x1, %al
movzbl %al, %edi
leaq 0x29021(%rip), %rsi     # 0x32734
movq %rbx, %rdx
callq 0x238ca
movsd 0x26ad5(%rip), %xmm1    # 0x301f8
movsd 0x10(%rsp), %xmm0
callq 0x24279
testb %al, %al
je 0x9750
movsd 0x26f26(%rip), %xmm0    # 0x30660
divsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x24239
movl %eax, %ebp
xorb $0x1, %bpl
movzbl %bpl, %edi
leaq 0x28fd9(%rip), %rsi     # 0x32734
movq %rbx, %rdx
callq 0x238ca
movsd 0x8(%rsp), %xmm0
mulsd (%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movapd 0x40(%rsp), %xmm0
xorl %ebp, %ebp
testq %r14, %r14
sete %bpl
mulsd 0x26cfd(%rip), %xmm0    # 0x30488
movq %rbx, %rdi
callq 0x2455f
addsd %xmm0, %xmm0
cvtsi2sd %r12, %xmm1
movsd 0x26a54(%rip), %xmm3    # 0x301f8
movapd %xmm3, %xmm2
movsd %xmm1, 0x70(%rsp)
divsd %xmm1, %xmm2
addsd 0x80(%rsp), %xmm2
movapd %xmm3, %xmm1
divsd 0x88(%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 0x286c5(%rip), %xmm5    # 0x31eb0
pandn %xmm2, %xmm1
por %xmm1, %xmm5
movsd 0x27a65(%rip), %xmm6    # 0x31260
movdqa %xmm5, %xmm1
addsd %xmm6, %xmm1
movsd %xmm0, 0x28(%rsp)
subsd %xmm0, %xmm1
pshufd $0xee, %xmm5, %xmm4     # xmm4 = xmm5[2,3,2,3]
mulsd %xmm1, %xmm4
movapd 0x284f2(%rip), %xmm0    # 0x31d10
unpcklpd 0x90(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd %xmm0, 0x60(%rsp)
movapd %xmm3, %xmm7
movapd %xmm7, %xmm1
addsd 0x70(%rsp), %xmm1
movapd %xmm7, %xmm0
mulsd %xmm1, %xmm0
movapd %xmm3, %xmm2
divsd %xmm7, %xmm2
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x60(%rsp), %xmm0
divpd %xmm1, %xmm0
addsd %xmm2, %xmm6
movsd %xmm6, 0x38(%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 0x28(%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, 0x30(%rsp)
movq %rbx, %rdi
callq 0x2440c
movsd 0x26f39(%rip), %xmm1    # 0x307f0
callq 0x24279
movsd 0x30(%rsp), %xmm7
movsd 0x38(%rsp), %xmm6
movapd 0x50(%rsp), %xmm5
movapd 0x10(%rsp), %xmm4
movsd 0x2691c(%rip), %xmm3    # 0x301f8
testb %al, %al
jne 0x9831
mulsd 0x26b9c(%rip), %xmm4    # 0x30488
divsd (%rsp), %xmm4
testb $0x1, %r12b
je 0x98ff
xorpd 0x268b1(%rip), %xmm4    # 0x301b0
movsd 0x8(%rsp), %xmm0
addsd %xmm4, %xmm0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq