// File: mouda[P]LTE_random_access-simulate/specialfunctions.cpp
// Function: alglib_impl::jacobianellipticfunctions(double, double, double*, double*, double*, double*, alglib_impl::ae_state*)
void jacobianellipticfunctions(double u,
     double m,
     double* sn,
     double* cn,
     double* dn,
     double* ph,
     ae_state *_state)
{
    ae_frame _frame_block;
    double ai;
    double b;
    double phi;
    double t;
    double twon;
    ae_vector a;
    ae_vector c;
    ae_int_t i;

    ae_frame_make(_state, &_frame_block);
    *sn = 0;
    *cn = 0;
    *dn = 0;
    *ph = 0;
    ae_vector_init(&a, 0, DT_REAL, _state, ae_true);
    ae_vector_init(&c, 0, DT_REAL, _state, ae_true);

    ae_assert(ae_fp_greater_eq(m,0)&&ae_fp_less_eq(m,1), "Domain error in JacobianEllipticFunctions: m<0 or m>1", _state);
    ae_vector_set_length(&a, 8+1, _state);
    ae_vector_set_length(&c, 8+1, _state);
    if( ae_fp_less(m,1.0e-9) )
    {
        t = ae_sin(u, _state);
        b = ae_cos(u, _state);
        ai = 0.25*m*(u-t*b);
        *sn = t-ai*b;
        *cn = b+ai*t;
        *ph = u-ai;
        *dn = 1.0-0.5*m*t*t;
        ae_frame_leave(_state);
        return;
    }
    if( ae_fp_greater_eq(m,0.9999999999) )
    {
        ai = 0.25*(1.0-m);
        b = ae_cosh(u, _state);
        t = ae_tanh(u, _state);
        phi = 1.0/b;
        twon = b*ae_sinh(u, _state);
        *sn = t+ai*(twon-u)/(b*b);
        *ph = 2.0*ae_atan(ae_exp(u, _state), _state)-1.57079632679489661923+ai*(twon-u)/b;
        ai = ai*t*phi;
        *cn = phi-ai*(twon-u);
        *dn = phi+ai*(twon+u);
        ae_frame_leave(_state);
        return;
    }
    a.ptr.p_double[0] = 1.0;
    b = ae_sqrt(1.0-m, _state);
    c.ptr.p_double[0] = ae_sqrt(m, _state);
    twon = 1.0;
    i = 0;
    while(ae_fp_greater(ae_fabs(c.ptr.p_double[i]/a.ptr.p_double[i], _state),ae_machineepsilon))
    {
        if( i>7 )
        {
            ae_assert(ae_false, "Overflow in JacobianEllipticFunctions", _state);
            break;
        }
        ai = a.ptr.p_double[i];
        i = i+1;
        c.ptr.p_double[i] = 0.5*(ai-b);
        t = ae_sqrt(ai*b, _state);
        a.ptr.p_double[i] = 0.5*(ai+b);
        b = t;
        twon = twon*2.0;
    }
    phi = twon*a.ptr.p_double[i]*u;
    do
    {
        t = c.ptr.p_double[i]*ae_sin(phi, _state)/a.ptr.p_double[i];
        b = phi;
        phi = (ae_asin(t, _state)+phi)/2.0;
        i = i-1;
    }
    while(i!=0);
    *sn = ae_sin(phi, _state);
    t = ae_cos(phi, _state);
    *cn = t;
    *dn = t/ae_cos(phi-b, _state);
    *ph = phi;
    ae_frame_leave(_state);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3b0f0
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
movl $0x1, %r8d
callq 0x3b400
movq -0x38(%rbp), %rcx
leaq -0xd8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
movl $0x1, %r8d
callq 0x3b400
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x3c500
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xe1(%rbp)
jne 0x177fe
jmp 0x17816
movsd -0x10(%rbp), %xmm0
movsd 0x3d7fd(%rip), %xmm1    # 0x55008
callq 0x3c480
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
movq -0x38(%rbp), %rdx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x3feec(%rip), %rsi     # 0x57719
callq 0x3b240
movq -0x38(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
movl $0x9, %esi
callq 0x3b620
movq -0x38(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
movl $0x9, %esi
callq 0x3b620
movsd -0x10(%rbp), %xmm0
movsd 0x3dbcf(%rip), %xmm1    # 0x55438
callq 0x3c440
testb $0x1, %al
jne 0x17877
jmp 0x1799c
movsd -0x8(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cb90
movsd %xmm0, -0x70(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cbc0
movsd %xmm0, -0x60(%rbp)
movsd 0x3eb73(%rip), %xmm0    # 0x56418
mulsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm2
movsd -0x70(%rbp), %xmm1
movsd -0x60(%rbp), %xmm3
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x70(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
movsd -0x70(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x8(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movsd 0x3db00(%rip), %xmm0    # 0x55450
mulsd -0x10(%rbp), %xmm0
mulsd -0x70(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm1, %xmm0
movsd 0x3d686(%rip), %xmm1    # 0x55008
addsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rdi
callq 0x3b030
jmp 0x17de5
movsd -0x10(%rbp), %xmm0
movsd 0x3f377(%rip), %xmm1    # 0x56d20
callq 0x3c500
testb $0x1, %al
jne 0x179b7
jmp 0x17b3a
movsd 0x3d649(%rip), %xmm1    # 0x55008
subsd -0x10(%rbp), %xmm1
movsd 0x3ea4c(%rip), %xmm0    # 0x56418
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cc50
movsd %xmm0, -0x60(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cc80
movsd %xmm0, -0x70(%rbp)
movsd 0x3d605(%rip), %xmm0    # 0x55008
divsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cc20
movaps %xmm0, %xmm1
movsd -0xf0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
subsd -0x8(%rbp), %xmm2
mulsd %xmm2, %xmm1
movsd -0x60(%rbp), %xmm2
mulsd -0x60(%rbp), %xmm2
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x8(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cdd0
movq -0x38(%rbp), %rdi
callq 0x3cd10
addsd %xmm0, %xmm0
movsd 0x3f297(%rip), %xmm1    # 0x56d28
addsd %xmm1, %xmm0
movsd -0x58(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
subsd -0x8(%rbp), %xmm2
mulsd %xmm2, %xmm1
divsd -0x60(%rbp), %xmm1
addsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x58(%rbp), %xmm0
mulsd -0x70(%rbp), %xmm0
mulsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x68(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
movsd -0x78(%rbp), %xmm2
subsd -0x8(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x68(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
movsd -0x78(%rbp), %xmm2
addsd -0x8(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rdi
callq 0x3b030
jmp 0x17de5
movq -0x80(%rbp), %rax
movsd 0x3d4c2(%rip), %xmm0    # 0x55008
movsd %xmm0, (%rax)
movsd 0x3d4b6(%rip), %xmm0    # 0x55008
subsd -0x10(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x60(%rbp)
movsd -0x10(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3c890
movq -0xb0(%rbp), %rax
movsd %xmm0, (%rax)
movsd 0x3d482(%rip), %xmm0    # 0x55008
movsd %xmm0, -0x78(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xb0(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x80(%rbp), %rax
movq -0xe0(%rbp), %rcx
divsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3c820
movsd 0x3dd4e(%rip), %xmm1    # 0x55918
callq 0x3c4c0
testb $0x1, %al
jne 0x17bd8
jmp 0x17ca8
cmpq $0x7, -0xe0(%rbp)
jle 0x17bf9
movq -0x38(%rbp), %rdx
xorl %edi, %edi
leaq 0x3fb60(%rip), %rsi     # 0x5774f
callq 0x3b240
jmp 0x17ca8
movq -0x80(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
movsd -0x58(%rbp), %xmm1
subsd -0x60(%rbp), %xmm1
movsd 0x3d81e(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movq -0xb0(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x58(%rbp), %xmm0
mulsd -0x60(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3c890
movsd %xmm0, -0x70(%rbp)
movsd -0x58(%rbp), %xmm1
addsd -0x60(%rbp), %xmm1
movsd 0x3d7dd(%rip), %xmm0    # 0x55450
mulsd %xmm1, %xmm0
movq -0x80(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x3d72f(%rip), %xmm0    # 0x553c8
mulsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x17b96
movsd -0x78(%rbp), %xmm0
movq -0x80(%rbp), %rax
movq -0xe0(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
mulsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0xb0(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cb90
movaps %xmm0, %xmm1
movsd -0xf8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq -0x80(%rbp), %rax
movq -0xe0(%rbp), %rcx
divsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x70(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3ccb0
addsd -0x68(%rbp), %xmm0
movsd 0x3d68f(%rip), %xmm1    # 0x553c8
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0xe0(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, -0xe0(%rbp)
jne 0x17cc7
movsd -0x68(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cb90
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x68(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cbc0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
movsd -0x68(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3cbc0
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x68(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rdi
callq 0x3b030
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop