// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x24(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x60(%rsp)
movslq 0xa0(%rsp), %r13
movslq %esi, %rax
movslq %edx, %rcx
leaq 0x8(,%r13,8), %rdx
movq %rdx, 0x40(%rsp)
imulq %rax, %rdx
leaq (%rdx,%rdi), %r15
addq $0x10, %r15
movq %rdi, 0x38(%rsp)
leaq (%rdi,%rax,8), %rdx
movq %rdx, 0x58(%rsp)
leal 0x1(%rax), %edx
imull %r13d, %edx
movl %r13d, %esi
imull %eax, %esi
movl %eax, %edi
movq %rdi, 0x30(%rsp)
negq %rcx
addq %rcx, %rax
incq %rax
movq %rax, 0x50(%rsp)
xorl %ebx, %ebx
movl %edx, 0x2c(%rsp)
movslq %edx, %rax
movq 0x58(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movl %esi, 0x28(%rsp)
movslq %esi, %rcx
leaq (%rdx,%rcx,8), %rcx
movq 0x30(%rsp), %rdx
leaq (%rdx,%rbx), %r14
movsd (%rcx,%rbx,8), %xmm2
leaq 0x1(%rdx,%rbx), %rbp
movsd (%rax,%rbx,8), %xmm1
movapd %xmm1, %xmm0
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm0
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, (%rcx,%rbx,8)
andq $0x0, (%rax,%rbx,8)
xorl %r8d, %r8d
movq 0x50(%rsp), %r12
movq %r12, %rax
addq %rbx, %rax
setne %r8b
incl %r8d
movl %r13d, (%rsp)
movl %r14d, %edi
movl %ebp, %esi
movapd %xmm2, %xmm0
movq 0x38(%rsp), %rdx
movl %ebp, %ecx
callq 0x66c0f
movl 0xa8(%rsp), %eax
movl %eax, (%rsp)
movl %r14d, %edi
movl %ebp, %esi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movq 0x60(%rsp), %rdx
xorl %ecx, %ecx
movl 0x24(%rsp), %r8d
callq 0x66b9e
addq %rbx, %r12
je 0x67123
movq 0x30(%rsp), %rax
leal (%rax,%rbx), %r14d
addl $0x2, %r14d
movsd -0x8(%r15), %xmm2
movsd (%r15), %xmm1
movapd %xmm1, %xmm0
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm0
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, -0x8(%r15)
andq $0x0, (%r15)
movl %r13d, (%rsp)
movl %ebp, %edi
movl %r14d, %esi
movapd %xmm2, %xmm0
movq 0x38(%rsp), %rdx
movl %ebp, %ecx
pushq $0x2
popq %r8
callq 0x66b9e
movl %r13d, (%rsp)
movl %ebp, %edi
movl %r14d, %esi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movq 0x48(%rsp), %rdx
xorl %ecx, %ecx
movl %r13d, %r8d
callq 0x66c0f
addq 0x40(%rsp), %r15
movl 0x2c(%rsp), %edx
addl %r13d, %edx
incq %rbx
movl 0x28(%rsp), %esi
addl %r13d, %esi
jmp 0x66f9d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq