// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/alglibinternal.cpp
// Function: alglib_impl::generatereflection(alglib_impl::ae_vector*, long, double*, alglib_impl::ae_state*)
void generatereflection(/* Real    */ ae_vector* x,
     ae_int_t n,
     double* tau,
     ae_state *_state)
{
    ae_int_t j;
    double alpha;
    double xnorm;
    double v;
    double beta;
    double mx;
    double s;

    *tau = 0;

    if( n<=1 )
    {
        *tau = 0;
        return;
    }
    
    /*
     * Scale if needed (to avoid overflow/underflow during intermediate
     * calculations).
     */
    mx = 0;
    for(j=1; j<=n; j++)
    {
        mx = ae_maxreal(ae_fabs(x->ptr.p_double[j], _state), mx, _state);
    }
    s = 1;
    if( ae_fp_neq(mx,0) )
    {
        if( ae_fp_less_eq(mx,ae_minrealnumber/ae_machineepsilon) )
        {
            s = ae_minrealnumber/ae_machineepsilon;
            v = 1/s;
            ae_v_muld(&x->ptr.p_double[1], 1, ae_v_len(1,n), v);
            mx = mx*v;
        }
        else
        {
            if( ae_fp_greater_eq(mx,ae_maxrealnumber*ae_machineepsilon) )
            {
                s = ae_maxrealnumber*ae_machineepsilon;
                v = 1/s;
                ae_v_muld(&x->ptr.p_double[1], 1, ae_v_len(1,n), v);
                mx = mx*v;
            }
        }
    }
    
    /*
     * XNORM = DNRM2( N-1, X, INCX )
     */
    alpha = x->ptr.p_double[1];
    xnorm = 0;
    if( ae_fp_neq(mx,0) )
    {
        for(j=2; j<=n; j++)
        {
            xnorm = xnorm+ae_sqr(x->ptr.p_double[j]/mx, _state);
        }
        xnorm = ae_sqrt(xnorm, _state)*mx;
    }
    if( ae_fp_eq(xnorm,0) )
    {
        
        /*
         * H  =  I
         */
        *tau = 0;
        x->ptr.p_double[1] = x->ptr.p_double[1]*s;
        return;
    }
    
    /*
     * general case
     */
    mx = ae_maxreal(ae_fabs(alpha, _state), ae_fabs(xnorm, _state), _state);
    beta = -mx*ae_sqrt(ae_sqr(alpha/mx, _state)+ae_sqr(xnorm/mx, _state), _state);
    if( ae_fp_less(alpha,0) )
    {
        beta = -beta;
    }
    *tau = (beta-alpha)/beta;
    v = 1/(alpha-beta);
    ae_v_muld(&x->ptr.p_double[2], 1, ae_v_len(2,n), v);
    x->ptr.p_double[1] = beta;
    
    /*
     * Scale back outputs
     */
    x->ptr.p_double[1] = x->ptr.p_double[1]*s;
}

// Assembly:
andq $0x0, (%rdx)
cmpq $0x2, %rsi
jl 0x1715e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
xorl %r13d, %r13d
cmpq %r13, %r14
movsd %xmm0, (%rsp)
je 0x16ed4
movq 0x28(%rbx), %rax
movsd 0x8(%rax,%r13,8), %xmm0
movq %r12, %rdi
callq 0x2440c
movsd (%rsp), %xmm1
movq %r12, %rdi
callq 0x244b6
incq %r13
jmp 0x16ea5
xorps %xmm1, %xmm1
callq 0x24217
movsd 0x19314(%rip), %xmm0    # 0x301f8
movsd %xmm0, 0x30(%rsp)
testb %al, %al
je 0x16f85
movsd 0x1bb5e(%rip), %xmm1    # 0x32a58
movsd (%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x24259
testb %al, %al
je 0x16f18
movsd 0x1bb4a(%rip), %xmm0    # 0x32a60
jmp 0x16f3c
movsd 0x1bb40(%rip), %xmm1    # 0x32a60
movsd (%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x24295
testb %al, %al
je 0x16f85
movsd 0x1bb1c(%rip), %xmm0    # 0x32a58
movsd %xmm0, 0x18(%rsp)
movq 0x28(%rbx), %r13
addq $0x8, %r13
pushq $0x1
popq %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x26b4d
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movsd 0x18(%rsp), %xmm0
callq 0x26b08
movsd (%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd %xmm1, 0x30(%rsp)
jmp 0x16f8a
movsd (%rsp), %xmm0
movq 0x28(%rbx), %rax
movsd 0x8(%rax), %xmm1
movsd %xmm1, 0x18(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x24217
testb %al, %al
xorpd %xmm0, %xmm0
je 0x17005
pushq $0x2
popq %r13
cmpq %r14, %r13
jg 0x16ff0
movq 0x28(%rbx), %rax
movsd %xmm0, 0x20(%rsp)
movsd (%rax,%r13,8), %xmm0
divsd (%rsp), %xmm0
movq %r12, %rdi
callq 0x2441f
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
incq %r13
jmp 0x16fb3
movq %r12, %rdi
callq 0x24424
movsd (%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x241f5
testb %al, %al
je 0x17020
andq $0x0, (%r15)
jmp 0x1713c
movsd 0x18(%rsp), %xmm0
movq %r12, %rdi
callq 0x2440c
movsd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm0
movq %r12, %rdi
callq 0x2440c
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
movq %r12, %rdi
callq 0x244b6
movapd %xmm0, %xmm1
movapd %xmm0, 0x40(%rsp)
xorpd 0x1914c(%rip), %xmm0    # 0x301b0
movapd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x2441f
movsd %xmm0, 0x38(%rsp)
movsd (%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movq %r12, %rdi
callq 0x2441f
addsd 0x38(%rsp), %xmm0
movq %r12, %rdi
callq 0x24424
mulsd 0x20(%rsp), %xmm0
movapd %xmm0, (%rsp)
xorpd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm0
callq 0x24239
testb %al, %al
jne 0x170c8
movapd (%rsp), %xmm0
jmp 0x170d5
movapd (%rsp), %xmm0
xorpd 0x190db(%rip), %xmm0    # 0x301b0
movapd %xmm0, %xmm2
movapd %xmm0, (%rsp)
movsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%r15)
subsd %xmm2, %xmm1
movsd 0x190fb(%rip), %xmm0    # 0x301f8
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rbx), %r15
addq $0x10, %r15
pushq $0x2
popq %rdi
movq %r14, %rsi
callq 0x26b4d
pushq $0x1
popq %rsi
movq %r15, %rdi
movq %rax, %rdx
movsd 0x20(%rsp), %xmm0
callq 0x26b08
movq 0x28(%rbx), %rax
movapd (%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x28(%rbx), %rax
movsd 0x30(%rsp), %xmm0
mulsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq