// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/RNBasics/RNSvd.cpp
// Function: gaps::householder_zero_col(double*, double*, int, int, int, int, double*)
void householder_zero_col(RNScalar *a,RNScalar *u,int i,int j,int m,int n,RNScalar *hv)
	/* hv is a work vector, length m */
{
    RNScalar	scale,	/* a scale factor for X1 */
		sigma,		/* the norm^2 of X1 */
		snorm,		/* +/- the norm of X1 */
		f, h, s, dot;
    int k,l;

    /* we will scale X1 by its l1-norm.  squawk! */
    for (scale=0, k=i; k<m; k++) scale += ((RNScalar) fabs(REF2D(a,m,n,k,j)));

    /* if X1 is 0, no point doing anything else */
    if (!scale) return;

    /* divide out the l1-norm, and calculate sigma = |X|^2 */
    for (k=i; k<m; k++) hv[k] = REF2D(a,m,n,k,j) / scale;
    for (sigma=0, k=i; k<m; k++) sigma += hv[k]*hv[k];

    /* The householder vector is X1 +/- (|X1|,0,0,...).  We will
    ** contruct this vector in hv and use it to perform the householder
    ** transformation on the matrix.  The plus or minus on the norm
    ** is to reduce roundoff error.  */
    f = hv[i];
    snorm = ((RNScalar) ((f > 0) ? -sqrt(sigma) : sqrt(sigma)));
    h = f*snorm - sigma;	/* eqn 11.2.4 in Press et.al. */
    hv[i] = f - snorm;

    /* set the first column of a to be the (|X1|,0,...) -- this is
    ** what we would get by performing the transformation, but this
    ** way's faster */
    REF2D(a,m,n,i,j) = scale * snorm;
    for (k=i+1; k<m; k++) REF2D(a,m,n,k,j) = 0;

    /* Now perform the householder transformation on the rest of
    ** the columns.  If the householder vector is X, and -half its norm^2
    ** is h, the householder transform is P_ij : delta_ij + x_i x_j / h.
    ** We don't actually create the P matrix, we just do the calcuation.
    */
    for (k=j+1; k<n; k++) {
	for (dot=0, l=i; l<m; l++) dot += REF2D(a,m,n,l,k)*hv[l];
	s = dot/h;
	for (l=i; l<m; l++) REF2D(a,m,n,l,k) += s*hv[l];
    }

    /* Similarly, perform the householder transformation on (all)
    ** the rows of u.  Note that it's the rows of u rather than
    ** the columns, because we want U to invert what we've done to a.
    */
    for (k=0; k<m; k++) {
	for (dot=0, l=i; l<m; l++) dot += REF2D(u,m,m,k,l)*hv[l];
	s = dot/h;
	for (l=i; l<m; l++) REF2D(u,m,m,k,l) += s*hv[l];
    }
}

// Assembly:
cmpl %r8d, %edx
jge 0x6ffe0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %ebx
movq %rsi, %r15
movq %rdi, %r12
movq 0x80(%rsp), %r13
movslq %edx, %r11
movslq %r9d, %r8
movslq %ecx, %r10
movslq %ebx, %rbp
movq %r8, %rax
imulq %r11, %rax
leaq (,%r10,8), %rsi
leaq (%rsi,%rax,8), %rax
addq %rax, %rdi
leaq (,%r8,8), %r14
movq %rbp, %rsi
subq %r11, %rsi
xorpd %xmm2, %xmm2
movapd 0x3259b(%rip), %xmm0    # 0xa2270
movsd (%rdi), %xmm1
andpd %xmm0, %xmm1
addsd %xmm1, %xmm2
addq %r14, %rdi
decq %rsi
jne 0x6fcd5
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jne 0x6fcf9
jnp 0x6ffd2
cmpl %ebx, %edx
jge 0x6fd46
addq %r12, %rax
movq %r11, %rsi
movsd (%rax), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%r13,%rsi,8)
incq %rsi
addq %r14, %rax
cmpq %rsi, %rbp
jne 0x6fd03
cmpl %ebx, %edx
jge 0x6fd46
movslq %edx, %r11
xorpd %xmm8, %xmm8
movq %r11, %rax
movsd (%r13,%rax,8), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm0, %xmm8
incq %rax
cmpq %rax, %rbp
jne 0x6fd2c
jmp 0x6fd4b
xorpd %xmm8, %xmm8
movsd (%r13,%r11,8), %xmm4
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm8
movl %r9d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movq %r8, 0x10(%rsp)
jb 0x6fd75
xorps %xmm0, %xmm0
sqrtsd %xmm8, %xmm0
jmp 0x6fdd0
movapd %xmm8, %xmm0
movq %rdx, 0x40(%rsp)
movq %r11, 0x38(%rsp)
movsd %xmm8, 0x30(%rsp)
movq %r10, 0x28(%rsp)
movsd %xmm2, 0x20(%rsp)
movsd %xmm4, 0x18(%rsp)
callq 0xe340
movsd 0x18(%rsp), %xmm4
xorpd %xmm3, %xmm3
movsd 0x20(%rsp), %xmm2
movq 0x28(%rsp), %r10
movsd 0x30(%rsp), %xmm8
movl 0x8(%rsp), %ecx
movl 0xc(%rsp), %r9d
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %rdx
movapd 0x32248(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
cmpltsd %xmm4, %xmm3
andpd %xmm3, %xmm1
andnpd %xmm0, %xmm3
orpd %xmm1, %xmm3
movapd %xmm4, %xmm0
mulsd %xmm3, %xmm0
subsd %xmm3, %xmm4
movsd %xmm4, (%r13,%r11,8)
mulsd %xmm3, %xmm2
movl %r9d, %eax
imull %edx, %eax
addl %ecx, %eax
cltq
movsd %xmm2, (%r12,%rax,8)
leal 0x1(%rdx), %eax
cmpl %ebx, %eax
jge 0x6fedd
cltq
leaq (%r12,%r10,8), %rcx
movl %ebx, %esi
subl %edx, %esi
addl $-0x2, %esi
leaq 0x2(%rsi), %r10
andq $-0x2, %r10
movq %rsi, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movq 0x10(%rsp), %r8
movq %r8, %rsi
imulq %rax, %rsi
movq %r8, %rdi
shlq $0x4, %rdi
incq %rax
imulq %r8, %rax
xorl %r8d, %r8d
movdqa 0x3241d(%rip), %xmm2    # 0xa2280
movdqa 0x32425(%rip), %xmm3    # 0xa2290
pxor %xmm3, %xmm1
pcmpeqd %xmm4, %xmm4
movq %r8, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
por %xmm2, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm1, %xmm6
pcmpeqd %xmm1, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %r9d
notl %r9d
testb $0x1, %r9b
je 0x6feb9
movq $0x0, (%rcx,%rsi,8)
pxor %xmm4, %xmm5
pextrw $0x4, %xmm5, %r9d
testb $0x1, %r9b
je 0x6fed1
movq $0x0, (%rcx,%rax,8)
addq $0x2, %r8
addq %rdi, %rcx
cmpq %r8, %r10
jne 0x6fe73
subsd %xmm8, %xmm0
movl 0x8(%rsp), %eax
incl %eax
movl 0xc(%rsp), %edi
cmpl %edi, %eax
jge 0x6ff69
cltq
movq 0x10(%rsp), %rsi
imulq %r11, %rsi
leaq (,%rax,8), %rcx
leaq (%rcx,%rsi,8), %rcx
addq %rcx, %r12
cmpl %ebx, %edx
jge 0x6ff5e
xorpd %xmm1, %xmm1
movq %r12, %rcx
movq %r11, %rsi
movsd (%rcx), %xmm2
mulsd (%r13,%rsi,8), %xmm2
addsd %xmm2, %xmm1
incq %rsi
addq %r14, %rcx
cmpq %rsi, %rbp
jne 0x6ff18
cmpl %ebx, %edx
jge 0x6ff5e
divsd %xmm0, %xmm1
movq %r12, %rcx
movq %r11, %rsi
movsd (%r13,%rsi,8), %xmm2
mulsd %xmm1, %xmm2
addsd (%rcx), %xmm2
movsd %xmm2, (%rcx)
incq %rsi
addq %r14, %rcx
cmpq %rsi, %rbp
jne 0x6ff40
incq %rax
addq $0x8, %r12
cmpl %edi, %eax
jne 0x6ff0a
testl %ebx, %ebx
jle 0x6ffd2
movl %ebx, %eax
leaq (,%rax,8), %rcx
xorl %edi, %edi
cmpl %ebx, %edx
jge 0x6ffc7
xorpd %xmm1, %xmm1
movq %r11, %rsi
movsd (%r15,%rsi,8), %xmm2
mulsd (%r13,%rsi,8), %xmm2
addsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x6ff84
cmpl %ebx, %edx
jge 0x6ffc7
divsd %xmm0, %xmm1
movq %r11, %rsi
movsd (%r13,%rsi,8), %xmm2
mulsd %xmm1, %xmm2
addsd (%r15,%rsi,8), %xmm2
movsd %xmm2, (%r15,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x6ffa8
incq %rdi
addq %rcx, %r15
cmpq %rax, %rdi
jne 0x6ff79
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq