// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movq $0x0, (%rdx)
cmpq $0x2, %rsi
jge 0x185ed
movq $0x0, (%r15)
jmp 0x188c0
movq %rcx, %r12
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 0x26575
movsd (%rsp), %xmm1
movq %r12, %rdi
callq 0x26621
incq %r13
cmpq %r13, %r14
jne 0x185fc
xorps %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x262dc
movsd 0x1bb62(%rip), %xmm0    # 0x341a0
movsd %xmm0, 0x30(%rsp)
testb %al, %al
je 0x1866e
movsd 0x1e278(%rip), %xmm1    # 0x368c8
movsd (%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x2631e
testb %al, %al
je 0x18675
movsd 0x1e264(%rip), %xmm0    # 0x368d0
jmp 0x1869e
movsd (%rsp), %xmm0
jmp 0x186e6
movsd 0x1e253(%rip), %xmm1    # 0x368d0
movsd (%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x2635a
testb %al, %al
movsd (%rsp), %xmm0
je 0x186e6
movsd 0x1e22a(%rip), %xmm0    # 0x368c8
movsd %xmm0, 0x18(%rsp)
movq 0x28(%rbx), %r13
addq $0x8, %r13
movl $0x1, %edi
movq %r14, %rsi
callq 0x2923f
movl $0x1, %esi
movq %r13, %rdi
movq %rax, %rdx
movsd 0x18(%rsp), %xmm0
callq 0x291fc
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 0x262dc
testb %al, %al
xorpd %xmm0, %xmm0
je 0x1876e
cmpq $0x3, %r14
movl $0x2, %r13d
cmovgeq %r14, %r13
decq %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 0x26588
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
incq %rbp
cmpq %rbp, %r13
jne 0x1871e
movq %r12, %rdi
callq 0x2658d
movsd (%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
callq 0x262ba
testb %al, %al
je 0x1878c
movq $0x0, (%r15)
jmp 0x188ac
movsd 0x18(%rsp), %xmm0
movq %r12, %rdi
callq 0x26575
movsd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm0
movq %r12, %rdi
callq 0x26575
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
movq %r12, %rdi
callq 0x26621
movapd %xmm0, %xmm1
movapd %xmm0, 0x40(%rsp)
xorpd 0x1ba10(%rip), %xmm0    # 0x341e0
movapd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x26588
movsd %xmm0, 0x38(%rsp)
movsd (%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movq %r12, %rdi
callq 0x26588
addsd 0x38(%rsp), %xmm0
movq %r12, %rdi
callq 0x2658d
mulsd 0x20(%rsp), %xmm0
movapd %xmm0, (%rsp)
xorpd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm0
callq 0x262fe
testb %al, %al
jne 0x18834
movapd (%rsp), %xmm0
jmp 0x18841
movapd (%rsp), %xmm0
xorpd 0x1b99f(%rip), %xmm0    # 0x341e0
movapd %xmm0, %xmm2
movapd %xmm0, (%rsp)
movsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%r15)
subsd %xmm2, %xmm1
movsd 0x1b937(%rip), %xmm0    # 0x341a0
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rbx), %r15
addq $0x10, %r15
movl $0x2, %edi
movq %r14, %rsi
callq 0x2923f
movl $0x1, %esi
movq %r15, %rdi
movq %rax, %rdx
movsd 0x20(%rsp), %xmm0
callq 0x291fc
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