// File: tomfunkhouser[P]gaps/pkgs/RNBasics/RNSvd.cpp
// Function: gaps::clr_top_subdiag_elt(double*, int, int, double*, double*, int, int, int)
void clr_top_subdiag_elt(RNScalar * b,int p,int z,RNScalar * u,RNScalar * v,int m,int n,int min)
{
    int i;
    RNScalar x, r, hypot, cos, sin;

    for (i=p; ; i++) {
	/* figure out row rotation to zero out the subdiagonal element */
	x = REF2D(b,m,n,i,i);
	r = REF2D(b,m,n,i+1,i);
	hypot = fhypot(x,r);
	cos = x/hypot;
	sin = r/hypot;
	/* rotate the leading elements of the row */
	REF2D(b,m,n,i,i) = hypot;
	REF2D(b,m,n,i+1,i) = 0;
	/* rotate out the rest of the row */
	rotate_rows(i,i+1,cos,sin,b,i+1,(i+1==z)?1:2,m,n);
	/* accumulate transformation into columns of u */
	rotate_cols(i,i+1,cos,sin,u,0,m,m,min);

	/* end with a row rotation */
	if (i+1==z) break;

	/* figure out column rotation */
	x = REF2D(b,m,n,i,i+1);
	r = REF2D(b,m,n,i,i+2);
	hypot = fhypot(x,r);
	cos = x/hypot;
	sin = r/hypot;
	/* rotate the leading elements of the column */
	REF2D(b,m,n,i,i+1) = hypot;
	REF2D(b,m,n,i,i+2) = 0;
	/* rotate the rest of the column */
	rotate_cols(i+1,i+2,cos,sin,b,i+1,2,m,n);
	/* accumulate transformation into columns of v */
	rotate_rows(i+1,i+2,cos,sin,v,0,n,min,n);
    }
}

// Assembly:
subq $0x58, %rsp
movl 0x68(%rsp), %eax
movl 0x60(%rsp), %eax
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movl %edx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movl %r9d, 0x34(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
imull 0x30(%rsp), %ecx
addl 0x30(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
movl 0x30(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x30(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0xd2140
movsd %xmm0, 0x18(%rsp)
movsd 0x28(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x20(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
imull 0x30(%rsp), %ecx
addl 0x30(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
movl 0x30(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x30(%rsp), %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x30(%rsp), %edi
movl 0x30(%rsp), %esi
addl $0x1, %esi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq 0x50(%rsp), %rdx
movl 0x30(%rsp), %ecx
addl $0x1, %ecx
movl 0x30(%rsp), %r9d
addl $0x1, %r9d
movl 0x48(%rsp), %r10d
movl $0x2, %r8d
movl $0x1, %eax
cmpl %r10d, %r9d
cmovel %eax, %r8d
movl 0x34(%rsp), %r9d
movl 0x60(%rsp), %eax
movl %eax, (%rsp)
callq 0xd2b70
movl 0x30(%rsp), %edi
movl 0x30(%rsp), %esi
addl $0x1, %esi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq 0x40(%rsp), %rdx
movl 0x34(%rsp), %r8d
movl 0x34(%rsp), %r9d
movl 0x68(%rsp), %eax
xorl %ecx, %ecx
movl %eax, (%rsp)
callq 0xd2a40
movl 0x30(%rsp), %eax
addl $0x1, %eax
cmpl 0x48(%rsp), %eax
jne 0xd318c
jmp 0xd32dc
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
imull 0x30(%rsp), %ecx
movl 0x30(%rsp), %edx
addl $0x1, %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
imull 0x30(%rsp), %ecx
movl 0x30(%rsp), %edx
addl $0x2, %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0xd2140
movsd %xmm0, 0x18(%rsp)
movsd 0x28(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x20(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
imull 0x30(%rsp), %ecx
movl 0x30(%rsp), %edx
addl $0x1, %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x50(%rsp), %rax
movl 0x60(%rsp), %ecx
imull 0x30(%rsp), %ecx
movl 0x30(%rsp), %edx
addl $0x2, %edx
addl %edx, %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x30(%rsp), %edi
addl $0x1, %edi
movl 0x30(%rsp), %esi
addl $0x2, %esi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq 0x50(%rsp), %rdx
movl 0x30(%rsp), %ecx
addl $0x1, %ecx
movl 0x34(%rsp), %r9d
movl 0x60(%rsp), %eax
movl $0x2, %r8d
movl %eax, (%rsp)
callq 0xd2a40
movl 0x30(%rsp), %edi
addl $0x1, %edi
movl 0x30(%rsp), %esi
addl $0x2, %esi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq 0x38(%rsp), %rdx
movl 0x60(%rsp), %r8d
movl 0x68(%rsp), %r9d
movl 0x60(%rsp), %eax
xorl %ecx, %ecx
movl %eax, (%rsp)
callq 0xd2b70
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0xd3030
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)