// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rdi, %r12
negq %r12
cmovsq %rdi, %r12
movaps %xmm0, 0x30(%rsp)
xorl %edi, %edi
cmpq $0x20, %r12
setb %dil
leaq 0x2ca38(%rip), %rsi     # 0x365a4
movq %rbx, %rdx
callq 0x2581c
xorps %xmm1, %xmm1
movaps 0x30(%rsp), %xmm0
callq 0x2633e
movzbl %al, %edi
leaq 0x2ca2e(%rip), %rsi     # 0x365b9
movq %rbx, %rdx
callq 0x2581c
movsd 0x2b8bd(%rip), %xmm1    # 0x35458
movaps 0x30(%rsp), %xmm0
callq 0x2631e
testb %al, %al
je 0x9c23
movsd 0x2b8af(%rip), %xmm4    # 0x35460
movapd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm4
movsd 0x2a5d9(%rip), %xmm2    # 0x341a0
testq %r14, %r14
movapd %xmm4, 0x70(%rsp)
je 0x9dcb
movsd 0x2a802(%rip), %xmm7    # 0x343e0
cmpq $0x2, %r12
jb 0x9deb
leaq -0x1(%r12), %rax
movsd 0x2b873(%rip), %xmm5    # 0x35468
movsd 0x2a5a3(%rip), %xmm3    # 0x341a0
movapd %xmm3, %xmm1
movapd %xmm3, %xmm6
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm5
addsd %xmm3, %xmm1
mulsd %xmm1, %xmm6
decq %rax
jne 0x9c05
jmp 0x9dfb
movsd 0x2aa0d(%rip), %xmm0    # 0x34638
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x266d6
movapd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm0
callq 0x2633e
testb %al, %al
xorpd %xmm0, %xmm0
jne 0xa1ee
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd 0x2a54d(%rip), %xmm1    # 0x341b0
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movsd 0x2a9d7(%rip), %xmm0    # 0x34650
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x2a513(%rip), %xmm1    # 0x341a0
xorl %r14d, %r14d
movapd %xmm1, %xmm0
movsd %xmm1, 0x18(%rsp)
movapd %xmm1, %xmm3
movapd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm2
movsd 0x70(%rsp), %xmm1
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x50(%rsp), %xmm1
movsd %xmm3, 0x8(%rsp)
mulsd %xmm3, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
callq 0x26575
movsd %xmm0, 0x28(%rsp)
cmpq %r12, %r14
jb 0x9cff
movsd 0x28(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x2633e
testb %al, %al
jne 0x9d82
movsd 0x18(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
addsd %xmm2, %xmm1
movsd 0x8(%rsp), %xmm0
addsd 0x2a483(%rip), %xmm0    # 0x341a0
movsd %xmm0, 0x8(%rsp)
movsd 0x20(%rsp), %xmm0
addsd 0x2a6af(%rip), %xmm0    # 0x343e0
movsd %xmm0, 0x20(%rsp)
incq %r14
movapd %xmm2, %xmm0
movsd %xmm1, 0x18(%rsp)
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x26575
movsd 0x2abc8(%rip), %xmm1    # 0x34920
callq 0x2633e
movsd 0x20(%rsp), %xmm2
movsd 0x8(%rsp), %xmm3
movsd 0x40(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd %xmm1, (%rsp)
testb %al, %al
jne 0x9ca2
movaps 0x2a457(%rip), %xmm0    # 0x341e0
xorps 0x30(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266e0
movsd %xmm0, 0x8(%rsp)
movapd 0x30(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0x2a6c2(%rip), %xmm0    # 0x34470
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2658d
mulsd 0x8(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
jmp 0xa1ee
xorpd %xmm1, %xmm1
movsd %xmm1, (%rsp)
movsd %xmm2, 0x60(%rsp)
movsd %xmm1, 0x68(%rsp)
movsd %xmm2, 0x10(%rsp)
jmp 0xa086
movsd 0x2b675(%rip), %xmm5    # 0x35468
movsd 0x2a3a5(%rip), %xmm6    # 0x341a0
movsd %xmm5, 0x68(%rsp)
divsd %xmm0, %xmm7
cmpq $0x1, %r12
movsd %xmm6, 0x60(%rsp)
jne 0x9e2d
movsd 0x2a387(%rip), %xmm1    # 0x341a0
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd %xmm7, 0x10(%rsp)
jmp 0xa086
movq %r14, 0x88(%rsp)
movapd 0x2a3a3(%rip), %xmm0    # 0x341e0
xorpd %xmm4, %xmm0
movapd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movapd %xmm6, %xmm1
divsd %xmm0, %xmm1
movsd 0x2a7d9(%rip), %xmm0    # 0x34638
divsd %xmm7, %xmm0
movsd %xmm0, 0x90(%rsp)
cmpq $0x3, %r12
movl $0x2, %r13d
cmovaeq %r12, %r13
leaq -0x1(%r12), %rbp
movsd 0x2a319(%rip), %xmm0    # 0x341a0
movl $0x1, %r14d
leaq 0x2c710(%rip), %r15     # 0x365a4
movapd %xmm0, %xmm4
movsd %xmm7, 0x10(%rsp)
movapd %xmm0, %xmm2
movsd %xmm1, (%rsp)
movapd %xmm1, %xmm3
movsd %xmm7, 0x8(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %rbp, %xmm1
divsd %xmm1, %xmm3
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
mulsd %xmm4, %xmm1
mulsd 0x50(%rsp), %xmm2
movsd %xmm2, 0x20(%rsp)
movapd %xmm2, %xmm0
movsd %xmm3, 0x40(%rsp)
mulsd %xmm3, %xmm0
movsd %xmm1, 0x28(%rsp)
divsd %xmm1, %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x26575
movsd 0x2a72d(%rip), %xmm1    # 0x34638
subsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x26575
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
callq 0x2633e
movzbl %al, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2581c
movsd 0x8(%rsp), %xmm0
movsd 0x2a254(%rip), %xmm1    # 0x341a0
callq 0x2633e
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
je 0x9f6f
movsd 0x90(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x262fe
xorb $0x1, %al
movzbl %al, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2581c
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm7
mulsd %xmm7, %xmm0
movsd %xmm0, 0x10(%rsp)
incq %r14
decq %rbp
cmpq %r14, %r13
movsd 0x20(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
jne 0x9eb1
movsd (%rsp), %xmm0
mulsd 0x2a4a7(%rip), %xmm0    # 0x34468
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x26575
movsd %xmm0, 0x8(%rsp)
movsd 0x2a1c4(%rip), %xmm1    # 0x341a0
movsd 0x10(%rsp), %xmm0
callq 0x2633e
movl %eax, %ecx
movb $0x1, %bpl
movb $0x1, %al
testb %cl, %cl
je 0xa00d
movsd 0x2a63e(%rip), %xmm0    # 0x34638
divsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x262fe
xorb $0x1, %al
movzbl %al, %edi
leaq 0x2c58d(%rip), %rsi     # 0x365a4
movq %rbx, %rdx
callq 0x2581c
movsd 0x2a179(%rip), %xmm1    # 0x341a0
movsd 0x8(%rsp), %xmm0
callq 0x2633e
testb %al, %al
movq 0x88(%rsp), %r14
je 0xa05d
movsd 0x2a5f2(%rip), %xmm0    # 0x34638
divsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x262fe
movl %eax, %ebp
xorb $0x1, %bpl
movzbl %bpl, %edi
leaq 0x2c53c(%rip), %rsi     # 0x365a4
movq %rbx, %rdx
callq 0x2581c
movsd (%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
movapd 0x30(%rsp), %xmm0
mulsd 0x2a3da(%rip), %xmm0    # 0x34468
movq %rbx, %rdi
callq 0x266d6
movsd 0x2a102(%rip), %xmm3    # 0x341a0
movapd %xmm3, %xmm5
testq %r14, %r14
je 0xa0b1
movapd %xmm3, %xmm5
divsd 0x60(%rsp), %xmm5
xorps %xmm2, %xmm2
cvtsi2sd %r12, %xmm2
addsd %xmm0, %xmm0
movsd 0x2b3a3(%rip), %xmm7    # 0x35468
movapd %xmm7, %xmm8
movsd 0x68(%rsp), %xmm1
je 0xa0e1
movapd %xmm3, %xmm8
divsd %xmm2, %xmm8
addsd %xmm1, %xmm8
movapd %xmm8, %xmm6
addsd %xmm7, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm5, %xmm6
movsd %xmm0, 0x50(%rsp)
movsd %xmm2, 0x30(%rsp)
movapd %xmm3, %xmm4
addsd %xmm2, %xmm4
movapd %xmm3, %xmm1
movapd 0x70(%rsp), %xmm2
mulsd %xmm4, %xmm1
divsd %xmm1, %xmm2
movsd 0x2a07f(%rip), %xmm9    # 0x341a0
movapd %xmm9, %xmm1
divsd %xmm3, %xmm1
addsd %xmm1, %xmm7
movsd %xmm7, 0x28(%rsp)
movapd %xmm9, %xmm1
divsd %xmm4, %xmm1
addsd %xmm1, %xmm8
movsd %xmm8, 0x18(%rsp)
mulsd %xmm2, %xmm5
movsd %xmm5, 0x20(%rsp)
movapd %xmm7, %xmm1
addsd %xmm8, %xmm1
subsd %xmm0, %xmm1
mulsd %xmm5, %xmm1
addsd %xmm1, %xmm6
movapd %xmm6, 0x40(%rsp)
movapd %xmm5, %xmm0
divsd %xmm6, %xmm0
addsd %xmm9, %xmm3
movsd %xmm3, 0x8(%rsp)
movq %rbx, %rdi
callq 0x26575
movsd 0x2a78f(%rip), %xmm1    # 0x34920
callq 0x2633e
movsd 0x18(%rsp), %xmm8
movsd 0x28(%rsp), %xmm7
movsd 0x30(%rsp), %xmm2
movapd 0x40(%rsp), %xmm6
movsd 0x20(%rsp), %xmm5
movsd 0x50(%rsp), %xmm0
movsd 0x8(%rsp), %xmm3
testb %al, %al
jne 0xa0fe
mulsd 0x2a297(%rip), %xmm6    # 0x34468
divsd 0x10(%rsp), %xmm6
testb $0x1, %r12b
je 0xa1e5
xorpd 0x29ffb(%rip), %xmm6    # 0x341e0
movsd (%rsp), %xmm0
addsd %xmm6, %xmm0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq