// File: /workspace/github_cpp_makefile_star2_O3/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
movslq 0x40(%rsp), %r10
movl %r9d, -0x2c(%rsp)
movl %r9d, %eax
movq %rax, -0x18(%rsp)
movslq 0x38(%rsp), %rbx
movslq %esi, %r11
movslq %edx, %rax
movq %rax, -0x8(%rsp)
leaq 0x1(%r11), %rax
imulq %rbx, %rax
leaq (,%r11,8), %rdx
leaq (%rdx,%rax,8), %rdx
leaq (%rdi,%rdx), %rsi
leaq 0x8(,%rbx,8), %r12
leaq 0x2(%r11), %r9
imulq %rbx, %r9
leaq (%r8,%r9,8), %r15
leaq (%r8,%rax,8), %r8
movq %r12, -0x10(%rsp)
imulq %r11, %r12
addq %rdi, %r12
leaq (%rcx,%r11,8), %r13
shlq $0x3, %r10
movq %rdi, -0x20(%rsp)
leaq (%rdi,%rdx), %rax
addq $0x8, %rax
movq %rax, -0x28(%rsp)
movapd 0x31976(%rip), %xmm0    # 0xa2020
leaq (,%rbx,8), %rbp
movq %r11, %r9
imulq %rbx, %r9
movl %r11d, %eax
movl 0x38(%rsp), %r14d
imull %r14d, %eax
movslq %eax, %rcx
movq -0x20(%rsp), %rax
leaq (%rax,%r11,8), %rdx
movsd (%rdx,%rcx,8), %xmm2
leaq 0x1(%r11), %rax
movl %eax, %edi
imull %r14d, %edi
movslq %edi, %rdi
movsd (%rdx,%rdi,8), %xmm1
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
movsd %xmm2, (%rdx,%rcx,8)
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm1
movq $0x0, (%rdx,%rdi,8)
xorl %ecx, %ecx
movq -0x8(%rsp), %r14
cmpq %r14, %rax
sete %cl
negq %rcx
leaq (%r11,%rcx), %rdx
addq $0x3, %rdx
movapd %xmm1, %xmm2
xorpd %xmm0, %xmm2
movapd %xmm1, %xmm3
unpckhpd %xmm1, %xmm3            # xmm3 = xmm3[1],xmm1[1]
movl $0x1, %ecx
movsd (%r12,%rcx,8), %xmm4
movsd (%rsi,%rcx,8), %xmm5
movapd %xmm1, %xmm6
mulsd %xmm5, %xmm6
movapd %xmm3, %xmm7
mulsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%r12,%rcx,8)
mulsd %xmm3, %xmm5
mulsd %xmm2, %xmm4
addsd %xmm5, %xmm4
movsd %xmm4, (%rsi,%rcx,8)
leaq (%r11,%rcx), %rdi
incq %rdi
incq %rcx
cmpq %rdx, %rdi
jl 0x70742
cmpl $0x0, -0x2c(%rsp)
jle 0x707c8
movapd %xmm1, %xmm3
shufpd $0x1, %xmm2, %xmm3      # xmm3 = xmm3[1],xmm2[0]
movq %r13, %rcx
movq -0x18(%rsp), %rdx
movsd (%rcx), %xmm2
movsd 0x8(%rcx), %xmm4
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm1, %xmm4
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm3, %xmm2
addpd %xmm4, %xmm2
movupd %xmm2, (%rcx)
addq %r10, %rcx
decq %rdx
jne 0x7079f
cmpq %r14, %rax
je 0x708d7
movq -0x20(%rsp), %rcx
leaq (%rcx,%r9,8), %rcx
leaq 0x2(%r11), %r9
movupd (%rcx,%rax,8), %xmm1
movapd %xmm1, %xmm2
mulpd %xmm1, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
xorps %xmm2, %xmm2
sqrtsd %xmm3, %xmm2
movsd %xmm2, (%rcx,%rax,8)
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm1
movq $0x0, 0x10(%rcx,%r11,8)
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
movapd %xmm2, %xmm3
xorpd %xmm0, %xmm3
movapd %xmm3, %xmm4
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
movq -0x28(%rsp), %r14
movq %r14, %rdx
movsd (%rdx), %xmm5
movsd 0x8(%rdx), %xmm6
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
mulpd %xmm1, %xmm6
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
mulpd %xmm4, %xmm5
addpd %xmm6, %xmm5
shufpd $0x1, %xmm5, %xmm5      # xmm5 = xmm5[1,0]
movupd %xmm5, (%rdx)
incq %r11
addq %rbp, %rdx
cmpq %r9, %r11
jl 0x70838
cmpl $0x0, 0x38(%rsp)
jle 0x708b2
xorl %ecx, %ecx
movsd (%r8,%rcx,8), %xmm4
movsd (%r15,%rcx,8), %xmm5
movapd %xmm2, %xmm6
mulsd %xmm5, %xmm6
movapd %xmm1, %xmm7
mulsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%r8,%rcx,8)
mulsd %xmm1, %xmm5
mulsd %xmm3, %xmm4
addsd %xmm5, %xmm4
movsd %xmm4, (%r15,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x70872
movq -0x10(%rsp), %rcx
addq %rcx, %rsi
addq %rcx, %r12
addq $0x8, %r13
addq %rcx, %r14
movq %r14, -0x28(%rsp)
addq %rbp, %r15
addq %rbp, %r8
movq %rax, %r11
jmp 0x706b2
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq