// File: /workspace/github_cpp_makefile_star2_O3/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:
movq $0x0, (%rdx)
cmpq $0x2, %rsi
jl 0x18295
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
movsd %xmm0, (%rsp)
movq 0x28(%rbx), %rax
movsd 0x8(%rax,%r13,8), %xmm0
movq %r12, %rdi
callq 0x25e30
movsd (%rsp), %xmm1
movq %r12, %rdi
callq 0x25edc
incq %r13
cmpq %r13, %r14
jne 0x17fd0
xorps %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x25b97
movsd 0x1b1ce(%rip), %xmm0    # 0x331e0
movsd %xmm0, 0x30(%rsp)
testb %al, %al
je 0x18042
movsd 0x1da44(%rip), %xmm1    # 0x35a68
movsd (%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x25bd9
testb %al, %al
je 0x18049
movsd 0x1da30(%rip), %xmm0    # 0x35a70
jmp 0x18072
movsd (%rsp), %xmm0
jmp 0x180ba
movsd 0x1da1f(%rip), %xmm1    # 0x35a70
movsd (%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x25c15
testb %al, %al
movsd (%rsp), %xmm0
je 0x180ba
movsd 0x1d9f6(%rip), %xmm0    # 0x35a68
movsd %xmm0, 0x18(%rsp)
movq 0x28(%rbx), %r13
addq $0x8, %r13
movl $0x1, %edi
movq %r14, %rsi
callq 0x2897c
movl $0x1, %esi
movq %r13, %rdi
movq %rax, %rdx
movsd 0x18(%rsp), %xmm0
callq 0x28939
movsd (%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd %xmm1, 0x30(%rsp)
movq 0x28(%rbx), %rax
movsd 0x8(%rax), %xmm1
movsd %xmm1, 0x18(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x25b97
testb %al, %al
xorpd %xmm0, %xmm0
je 0x18135
leaq -0x1(%r14), %r13
xorl %ebp, %ebp
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rbx), %rax
movsd 0x10(%rax,%rbp,8), %xmm0
divsd (%rsp), %xmm0
movq %r12, %rdi
callq 0x25e43
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
incq %rbp
cmpq %rbp, %r13
jne 0x180e5
movq %r12, %rdi
callq 0x25e48
movsd (%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x25b75
testb %al, %al
je 0x18153
movq $0x0, (%r15)
jmp 0x18273
movsd 0x18(%rsp), %xmm0
movq %r12, %rdi
callq 0x25e30
movsd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm0
movq %r12, %rdi
callq 0x25e30
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
movq %r12, %rdi
callq 0x25edc
movapd %xmm0, %xmm1
movapd %xmm0, 0x40(%rsp)
xorpd 0x1b019(%rip), %xmm0    # 0x331b0
movapd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x25e43
movsd %xmm0, 0x38(%rsp)
movsd (%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movq %r12, %rdi
callq 0x25e43
addsd 0x38(%rsp), %xmm0
movq %r12, %rdi
callq 0x25e48
mulsd 0x20(%rsp), %xmm0
movapd %xmm0, (%rsp)
xorpd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm0
callq 0x25bb9
testb %al, %al
jne 0x181fb
movapd (%rsp), %xmm0
jmp 0x18208
movapd (%rsp), %xmm0
xorpd 0x1afa8(%rip), %xmm0    # 0x331b0
movapd %xmm0, %xmm2
movapd %xmm0, (%rsp)
movsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%r15)
subsd %xmm2, %xmm1
movsd 0x1afb0(%rip), %xmm0    # 0x331e0
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rbx), %r15
addq $0x10, %r15
movl $0x2, %edi
movq %r14, %rsi
callq 0x2897c
movl $0x1, %esi
movq %r15, %rdi
movq %rax, %rdx
movsd 0x20(%rsp), %xmm0
callq 0x28939
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