// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/RNBasics/RNSvd.cpp
// Function: gaps::bidiagonalize(double const*, int, int, double*, double*, double*)
void bidiagonalize(const RNScalar *a,int m,int n,RNScalar *u,RNScalar *b,RNScalar *v)
{
    int i,j, min=MIN(m,n);
    RNScalar *usave = u, *vsave = v, *h = ALLOC1D(MAX(m,n));

    /* we need square matrices to accumulate the transformations */
    if (min != m) u = ALLOC2D(m,m);
    if (min != n) v = ALLOC2D(n,n);

    /* start off with u and v equal to the identity, and b equal to a */
    CLEAR2D(u,m,m);
    CLEAR2D(v,n,n);
    for (i=0; i<m; i++) REF2D(u,m,m,i,i) = 1;
    for (i=0; i<n; i++) REF2D(v,n,n,i,i) = 1;
    if (b != a) COPY2D(b,m,n,a);

    /* walk down the diagonal */
    for (i = 0; i<min; i++) {
	/* zero the entries below b[i,i] */
	householder_zero_col(b,u,i,i,m,n,h);
	/* zero the entries to the right of b[i,i+1] */
	householder_zero_row(b,v,i,i+1,m,n,h);
    }
    /* when m < n (matrix wider than tall), the above
       leaves a non-0 element in the [m-1,m]th spot.
       This is the bottom superdiagonal element of an (m+1)x(m+1);
       use the clear routine to get rid of it. */
    if (min != n)
	clr_bot_supdiag_elt(b,0,min,v,m,n,n);

    /* For non-square arrays, lop off the parts we don't need */
    if (min!=m) {
	for (i=0; i<m; i++) for (j=0; j<min; j++)
	    REF2D(usave,m,min,i,j)=REF2D(u,m,m,i,j);
	FREE(u);
    }
    if (min!=n) {
	for (i=0; i<n; i++) for (j=0; j<min; j++)
	    REF2D(vsave,min,n,j,i)=REF2D(v,n,n,j,i);
	FREE(v);
    }
    FREE(h);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %r8, 0x28(%rsp)
movq %rcx, %rbp
movl %edx, %r13d
movl %esi, %r15d
movq %rdi, 0x20(%rsp)
cmpl %edx, %esi
movl %edx, %edi
cmovgl %esi, %edi
shlq $0x3, %rdi
callq 0xe5e0
movq %rax, 0x30(%rsp)
movl %r13d, %eax
movq %rbp, %rdi
cmpl %r13d, %r15d
cmovll %r15d, %eax
movl %eax, 0x14(%rsp)
jle 0x71b68
movl %r15d, %edi
imull %edi, %edi
shlq $0x3, %rdi
callq 0xe5e0
movq %rax, %rdi
movq %rbx, %r12
cmpl %r13d, %r15d
movq %rdi, 0x18(%rsp)
jge 0x71b8c
movl %r13d, %edi
imull %edi, %edi
shlq $0x3, %rdi
callq 0xe5e0
movq 0x18(%rsp), %rdi
movq %rax, %r12
movl %r15d, %edx
imull %edx, %edx
shlq $0x3, %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0xe260
movl %r13d, %edx
imull %edx, %edx
shlq $0x3, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0xe260
movq 0x18(%rsp), %rsi
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
testl %r15d, %r15d
jle 0x71bde
leal 0x1(%r15), %ecx
movl %r15d, %edx
movslq %r14d, %r14
movq %rax, (%rsi,%r14,8)
addl %ecx, %r14d
decq %rdx
jne 0x71bcf
testl %r13d, %r13d
jle 0x71bfa
leal 0x1(%r13), %ecx
movl %r13d, %edx
xorl %esi, %esi
movslq %esi, %rsi
movq %rax, (%r12,%rsi,8)
addl %ecx, %esi
decq %rdx
jne 0x71bec
movq %rbp, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
movq %r12, %r14
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %rsi
cmpq %rsi, %r12
je 0x71c2b
movl %r15d, %eax
imull %r13d, %eax
shll $0x3, %eax
movslq %eax, %rdx
movq %r12, %rdi
callq 0xe370
movl 0x14(%rsp), %ecx
testl %ecx, %ecx
movq %r15, %rbx
movq %r13, %r9
movq 0x30(%rsp), %rbp
movq %r14, 0x20(%rsp)
jle 0x71c99
xorl %r15d, %r15d
movq %rbp, (%rsp)
movq %r12, %r13
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movl %r15d, %edx
movl %r15d, %ecx
movl %ebx, %r8d
movq %r9, %r12
callq 0x70a3b
leal 0x1(%r15), %r14d
movq %rbp, (%rsp)
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movl %r15d, %edx
movl %r14d, %ecx
movl %ebx, %r8d
movl %r12d, %r9d
callq 0x70da2
movq %r12, %r9
movq %r13, %r12
movl 0x14(%rsp), %ecx
movl %r14d, %r15d
cmpl %r14d, %ecx
jne 0x71c46
cmpl %r9d, %ebx
movq %rbx, %r12
movq 0x20(%rsp), %r15
movq %r9, %r13
jge 0x71cc3
movq 0x28(%rsp), %rdi
xorl %esi, %esi
movl 0x14(%rsp), %edx
movq %r15, %rcx
movl %r13d, %r9d
callq 0x7131f
movl 0x14(%rsp), %ecx
cmpl %r13d, %r12d
movq 0x30(%rsp), %r14
movq 0x40(%rsp), %rbx
movq 0x38(%rsp), %r10
jle 0x71d32
testl %r12d, %r12d
jle 0x71d24
movl 0x14(%rsp), %eax
movl %r12d, %ecx
leaq (,%rax,8), %rdx
leaq (,%rcx,8), %rsi
xorl %edi, %edi
movq 0x18(%rsp), %r8
testl %r13d, %r13d
jle 0x71d16
xorl %r9d, %r9d
movsd (%r8,%r9,8), %xmm0
movsd %xmm0, (%r10,%r9,8)
incq %r9
cmpq %r9, %rax
jne 0x71d02
incq %rdi
addq %rdx, %r10
addq %rsi, %r8
cmpq %rcx, %rdi
jne 0x71cfa
movq 0x18(%rsp), %rdi
callq 0xe540
movl 0x14(%rsp), %ecx
cmpl %r13d, %r12d
jge 0x71d85
testl %r13d, %r13d
jle 0x71d7d
movl %r13d, %eax
movl %ecx, %ecx
leaq (,%rax,8), %rdx
xorl %esi, %esi
movq %r15, %rdi
testl %r12d, %r12d
jle 0x71d6d
movq %rcx, %r8
xorl %r9d, %r9d
movsd (%rdi,%r9), %xmm0
movsd %xmm0, (%rbx,%r9)
addq %rdx, %r9
decq %r8
jne 0x71d59
incq %rsi
addq $0x8, %rbx
addq $0x8, %rdi
cmpq %rax, %rsi
jne 0x71d4e
movq %r15, %rdi
callq 0xe540
movq %r14, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe540