// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebx
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r12
xorpd %xmm0, %xmm0
xorpd %xmm3, %xmm3
cmpl %r8d, %edx
jge 0x70aa3
movslq %r14d, %rsi
movslq %r9d, %rax
movslq %ecx, %rdx
movslq %ebx, %r8
movq %rax, %rdi
imulq %rsi, %rdi
shlq $0x3, %rdx
leaq (%rdx,%rdi,8), %rdx
addq %r12, %rdx
shlq $0x3, %rax
subq %rsi, %r8
movapd 0x317e1(%rip), %xmm1    # 0xa2270
movsd (%rdx), %xmm2
andpd %xmm1, %xmm2
addsd %xmm2, %xmm3
addq %rax, %rdx
decq %r8
jne 0x70a8f
ucomisd %xmm0, %xmm3
jne 0x70aaf
jnp 0x70d93
movq 0x60(%rsp), %r13
cmpl %ebx, %r14d
jge 0x70af5
movslq %r14d, %rax
movslq %r9d, %r8
movslq %ecx, %rsi
movslq %ebx, %rdx
movq %r8, %rdi
imulq %rax, %rdi
shlq $0x3, %rsi
leaq (%rsi,%rdi,8), %rsi
addq %r12, %rsi
shlq $0x3, %r8
movsd (%rsi), %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
addq %r8, %rsi
cmpq %rax, %rdx
jne 0x70adb
movslq %r14d, %rbp
xorpd %xmm0, %xmm0
xorpd %xmm8, %xmm8
cmpl %ebx, %r14d
jge 0x70b24
movslq %r14d, %rax
movslq %ebx, %rdx
movsd (%r13,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm8
incq %rax
cmpq %rax, %rdx
jne 0x70b0c
movsd (%r13,%rbp,8), %xmm4
ucomisd %xmm0, %xmm8
jb 0x70b3c
xorps %xmm0, %xmm0
sqrtsd %xmm8, %xmm0
jmp 0x70b7e
movapd %xmm8, %xmm0
movl %r9d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movsd %xmm8, 0x20(%rsp)
movsd %xmm3, 0x18(%rsp)
movsd %xmm4, 0x10(%rsp)
callq 0xe340
movsd 0x10(%rsp), %xmm4
movsd 0x18(%rsp), %xmm3
movsd 0x20(%rsp), %xmm8
movl 0x8(%rsp), %ecx
movl 0xc(%rsp), %r9d
movapd 0x3149a(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm4, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm4, %xmm0
mulsd %xmm2, %xmm0
subsd %xmm2, %xmm4
movsd %xmm4, (%r13,%rbp,8)
mulsd %xmm2, %xmm3
movl %r9d, %eax
imull %r14d, %eax
addl %ecx, %eax
cltq
movsd %xmm3, (%r12,%rax,8)
leal 0x1(%r14), %eax
cmpl %ebx, %eax
jge 0x70c90
cltq
movslq %r9d, %r11
movslq %ecx, %rsi
movl %ebx, %edi
subl %r14d, %edi
addl $-0x2, %edi
leaq 0x2(%rdi), %rdx
andq $-0x2, %rdx
movq %rdi, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
leaq (%r12,%rsi,8), %rsi
movq %r11, %rdi
imulq %rax, %rdi
incq %rax
imulq %r11, %rax
shlq $0x4, %r11
xorl %r8d, %r8d
movdqa 0x3166a(%rip), %xmm2    # 0xa2280
movdqa 0x31672(%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, %r10d
notl %r10d
testb $0x1, %r10b
je 0x70c6c
movq $0x0, (%rsi,%rdi,8)
pxor %xmm4, %xmm5
pextrw $0x4, %xmm5, %r10d
testb $0x1, %r10b
je 0x70c84
movq $0x0, (%rsi,%rax,8)
addq $0x2, %r8
addq %r11, %rsi
cmpq %r8, %rdx
jne 0x70c26
subsd %xmm8, %xmm0
incl %ecx
cmpl %r9d, %ecx
jge 0x70d28
movslq %r14d, %rax
movslq %r9d, %r10
movslq %ecx, %rdx
movslq %ebx, %rsi
movq %r10, %rdi
imulq %rax, %rdi
leaq (,%rdx,8), %r8
leaq (%r8,%rdi,8), %rdi
addq %rdi, %r12
shlq $0x3, %r10
xorpd %xmm1, %xmm1
cmpl %ebx, %r14d
jge 0x70cef
movq %r12, %rdi
movq %rax, %r8
movsd (%rdi), %xmm2
mulsd (%r13,%r8,8), %xmm2
addsd %xmm2, %xmm1
incq %r8
addq %r10, %rdi
cmpq %r8, %rsi
jne 0x70cd5
cmpl %ebx, %r14d
jge 0x70d1c
divsd %xmm0, %xmm1
movq %r12, %rdi
movq %rax, %r8
movsd (%r13,%r8,8), %xmm2
mulsd %xmm1, %xmm2
addsd (%rdi), %xmm2
movsd %xmm2, (%rdi)
incq %r8
addq %r10, %rdi
cmpq %r8, %rsi
jne 0x70cfe
incq %rdx
addq $0x8, %r12
cmpl %r9d, %edx
jne 0x70cc6
testl %ebx, %ebx
jle 0x70d93
movl %ebx, %eax
leaq (,%rax,8), %rcx
xorl %edx, %edx
xorpd %xmm1, %xmm1
cmpl %ebx, %r14d
jge 0x70d5d
movq %rbp, %rsi
movsd (%r15,%rsi,8), %xmm2
mulsd (%r13,%rsi,8), %xmm2
addsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x70d44
cmpl %ebx, %r14d
jge 0x70d88
divsd %xmm0, %xmm1
movq %rbp, %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 0x70d69
incq %rdx
addq %rcx, %r15
cmpq %rax, %rdx
jne 0x70d38
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq