// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::besseljn(long, double, alglib_impl::ae_state*)
double besseljn(ae_int_t n, double x, ae_state *_state)
{
    double pkm2;
    double pkm1;
    double pk;
    double xk;
    double r;
    double ans;
    ae_int_t k;
    ae_int_t sg;
    double result;


    if( n<0 )
    {
        n = -n;
        if( n%2==0 )
        {
            sg = 1;
        }
        else
        {
            sg = -1;
        }
    }
    else
    {
        sg = 1;
    }
    if( ae_fp_less(x,0) )
    {
        if( n%2!=0 )
        {
            sg = -sg;
        }
        x = -x;
    }
    if( n==0 )
    {
        result = sg*besselj0(x, _state);
        return result;
    }
    if( n==1 )
    {
        result = sg*besselj1(x, _state);
        return result;
    }
    if( n==2 )
    {
        if( ae_fp_eq(x,0) )
        {
            result = 0;
        }
        else
        {
            result = sg*(2.0*besselj1(x, _state)/x-besselj0(x, _state));
        }
        return result;
    }
    if( ae_fp_less(x,ae_machineepsilon) )
    {
        result = 0;
        return result;
    }
    k = 53;
    pk = 2*(n+k);
    ans = pk;
    xk = x*x;
    do
    {
        pk = pk-2.0;
        ans = pk-xk/ans;
        k = k-1;
    }
    while(k!=0);
    ans = x/ans;
    pk = 1.0;
    pkm1 = 1.0/ans;
    k = n-1;
    r = 2*k;
    do
    {
        pkm2 = (pkm1*r-pk*x)/x;
        pk = pkm1;
        pkm1 = pkm2;
        r = r-2.0;
        k = k-1;
    }
    while(k!=0);
    if( ae_fp_greater(ae_fabs(pk, _state),ae_fabs(pkm1, _state)) )
    {
        ans = besselj1(x, _state)/pk;
    }
    else
    {
        ans = besselj0(x, _state)/pkm1;
    }
    result = sg*ans;
    return result;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movl %edi, %eax
andl $0x1, %eax
negq %rax
orq $0x1, %rax
movq %rdi, %r15
negq %r15
cmovsq %rdi, %r15
testq %rdi, %rdi
pushq $0x1
popq %r14
cmovsq %rax, %r14
xorpd %xmm1, %xmm1
movaps %xmm0, (%rsp)
callq 0x24239
testb %al, %al
je 0x74bf
movq %r14, %rax
negq %rax
testb $0x1, %r15b
cmovneq %rax, %r14
movapd (%rsp), %xmm0
xorpd 0x28cf3(%rip), %xmm0    # 0x301b0
jmp 0x74c4
movapd (%rsp), %xmm0
cmpq $0x2, %r15
je 0x7516
cmpq $0x1, %r15
je 0x74ed
testq %r15, %r15
jne 0x7575
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x6f42
jmp 0x74ff
cvtsi2sd %r14d, %xmm1
movsd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0x7181
movapd %xmm0, %xmm1
mulsd (%rsp), %xmm1
movapd %xmm1, %xmm0
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorpd %xmm1, %xmm1
movapd %xmm0, (%rsp)
callq 0x241f5
xorpd %xmm1, %xmm1
testb %al, %al
jne 0x7508
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x18(%rsp)
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x7181
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movapd (%rsp), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x6f42
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x18(%rsp), %xmm1
jmp 0x7508
movsd 0x29273(%rip), %xmm1    # 0x307f0
movapd %xmm0, (%rsp)
callq 0x24239
xorpd %xmm1, %xmm1
testb %al, %al
jne 0x7508
leaq 0x6a(,%r15,2), %rax
cvtsi2sd %rax, %xmm1
movapd (%rsp), %xmm5
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm2
pushq $-0x35
popq %rax
movsd 0x28e48(%rip), %xmm6    # 0x30400
movapd %xmm1, %xmm3
movapd %xmm2, %xmm4
divsd %xmm3, %xmm4
addsd %xmm6, %xmm1
movapd %xmm1, %xmm3
subsd %xmm4, %xmm3
incq %rax
jne 0x75bc
movapd %xmm5, %xmm1
divsd %xmm3, %xmm1
movsd 0x28c13(%rip), %xmm0    # 0x301f8
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
leaq -0x2(,%r15,2), %rax
decq %r15
cvtsi2sd %rax, %xmm1
movapd %xmm0, %xmm2
movapd %xmm3, %xmm0
mulsd %xmm5, %xmm2
mulsd %xmm1, %xmm3
subsd %xmm2, %xmm3
divsd %xmm5, %xmm3
addsd %xmm6, %xmm1
decq %r15
jne 0x75fd
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movsd %xmm3, 0x18(%rsp)
callq 0x2440c
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2440c
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x24279
testb %al, %al
je 0x766d
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x7181
divsd 0x28(%rsp), %xmm0
jmp 0x7680
movapd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x6f42
divsd 0x18(%rsp), %xmm0
cvtsi2sd %r14d, %xmm1
mulsd %xmm0, %xmm1
jmp 0x7508