// File: 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 %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jge 0xa931
xorl %eax, %eax
subq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0xa927
movq $0x1, -0x60(%rbp)
jmp 0xa92f
movq $-0x1, -0x60(%rbp)
jmp 0xa939
movq $0x1, -0x60(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c440
testb $0x1, %al
jne 0xa94c
jmp 0xa98b
movq -0x10(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0xa96a
xorl %eax, %eax
subq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movsd -0x18(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xa9cb
cvtsi2sdq -0x60(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x9f50
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xac93
cmpq $0x1, -0x10(%rbp)
jne 0xaa0b
cvtsi2sdq -0x60(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0xa3e0
movaps %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xac93
cmpq $0x2, -0x10(%rbp)
jne 0xaaa2
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c3d0
testb $0x1, %al
jne 0xaa29
jmp 0xaa33
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0xaa93
cvtsi2sdq -0x60(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0xa3e0
movaps %xmm0, %xmm1
movsd 0x4a971(%rip), %xmm0    # 0x553c8
mulsd %xmm1, %xmm0
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x9f50
movsd -0x88(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x80(%rbp), %xmm0
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xac93
movsd -0x18(%rbp), %xmm0
movsd 0x4ae69(%rip), %xmm1    # 0x55918
callq 0x3c440
testb $0x1, %al
jne 0xaaba
jmp 0xaad1
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xac93
movq $0x35, -0x58(%rbp)
movq -0x10(%rbp), %rax
addq -0x58(%rbp), %rax
shlq %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
movsd 0x4a8b4(%rip), %xmm1    # 0x553c8
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
divsd -0x50(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x58(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xab07
movsd -0x18(%rbp), %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x4a4a9(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x38(%rbp)
movsd 0x4a49c(%rip), %xmm0    # 0x55008
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shlq %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x48(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
mulsd -0x18(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x48(%rbp), %xmm0
movsd 0x4a7d7(%rip), %xmm1    # 0x553c8
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x58(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xab93
movsd -0x38(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movsd %xmm0, -0x90(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x3c820
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
callq 0x3c4c0
testb $0x1, %al
jne 0xac47
jmp 0xac61
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0xa3e0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0xac79
movsd -0x18(%rbp), %xmm0
movq -0x20(%rbp), %rdi
callq 0x9f50
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
cvtsi2sdq -0x60(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)