// File: Pyboon[P]sage/./Eigen/src/LU/PartialPivLU.h
// Function: Eigen::internal::partial_lu_impl<std::complex<double>, 0, int>::unblocked_lu(Eigen::Block<Eigen::Map<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0>>, -1, -1, false>&, int*, int&)
static Index unblocked_lu(MatrixType& lu, PivIndex* row_transpositions, PivIndex& nb_transpositions)
  {
    typedef scalar_score_coeff_op<Scalar> Scoring;
    typedef typename Scoring::result_type Score;
    const Index rows = lu.rows();
    const Index cols = lu.cols();
    const Index size = (std::min)(rows,cols);
    nb_transpositions = 0;
    Index first_zero_pivot = -1;
    for(Index k = 0; k < size; ++k)
    {
      Index rrows = rows-k-1;
      Index rcols = cols-k-1;

      Index row_of_biggest_in_col;
      Score biggest_in_corner
        = lu.col(k).tail(rows-k).unaryExpr(Scoring()).maxCoeff(&row_of_biggest_in_col);
      row_of_biggest_in_col += k;

      row_transpositions[k] = PivIndex(row_of_biggest_in_col);

      if(biggest_in_corner != Score(0))
      {
        if(k != row_of_biggest_in_col)
        {
          lu.row(k).swap(lu.row(row_of_biggest_in_col));
          ++nb_transpositions;
        }

        // FIXME shall we introduce a safe quotient expression in cas 1/lu.coeff(k,k)
        // overflow but not the actual quotient?
        lu.col(k).tail(rrows) /= lu.coeff(k,k);
      }
      else if(first_zero_pivot==-1)
      {
        // the pivot is exactly zero, we record the index of the first pivot which is exactly 0,
        // and continue the factorization such we still have A = PLU
        first_zero_pivot = k;
      }

      if(k<rows-1)
        lu.bottomRightCorner(rrows,rcols).noalias() -= lu.col(k).tail(rrows) * lu.row(k).tail(rcols);
    }
    return first_zero_pivot;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8d0, %rsp            # imm = 0x8D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4b0c0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4b0e0
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x3e940
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq $-0x1, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x4a718
movq -0x20(%rbp), %rax
subq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
subq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x248(%rbp), %rdi
callq 0x4b100
movq -0x20(%rbp), %rdx
subq -0x40(%rbp), %rdx
leaq -0x1c8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x4b150
leaq -0x249(%rbp), %rdi
callq 0x4b200
leaq -0x118(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x249(%rbp), %rdx
callq 0x4b1b0
leaq -0x118(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x4b220
movsd %xmm0, -0x60(%rbp)
movq -0x40(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4a589
jp 0x4a589
jmp 0x4a631
movq -0x40(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x4a5d9
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x2d0(%rbp), %rdi
callq 0x4b260
movq -0x8(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0x350(%rbp), %rdi
callq 0x4b260
leaq -0x2d0(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x4b2b0
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4b380
movq %rax, -0x8d0(%rbp)
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x480(%rbp), %rdi
callq 0x4b100
movq -0x48(%rbp), %rdx
leaq -0x400(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0x4b150
movq -0x8d0(%rbp), %rsi
leaq -0x400(%rbp), %rdi
callq 0x4b400
jmp 0x4a642
cmpq $-0x1, -0x38(%rbp)
jne 0x4a640
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x4a642
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x4a705
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x710(%rbp), %rdi
callq 0x4b100
movq -0x48(%rbp), %rdx
leaq -0x690(%rbp), %rdi
leaq -0x710(%rbp), %rsi
callq 0x4b150
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x840(%rbp), %rdi
callq 0x4b260
movq -0x50(%rbp), %rdx
leaq -0x7c0(%rbp), %rdi
leaq -0x840(%rbp), %rsi
callq 0x4b4d0
leaq -0x5e0(%rbp), %rdi
leaq -0x690(%rbp), %rsi
leaq -0x7c0(%rbp), %rdx
callq 0x4b480
movq -0x8(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
leaq -0x8c8(%rbp), %rdi
callq 0x4b530
leaq -0x8c8(%rbp), %rdi
callq 0x4aaa0
movq %rax, -0x848(%rbp)
leaq -0x848(%rbp), %rdi
leaq -0x5e0(%rbp), %rsi
callq 0x4b5b0
jmp 0x4a707
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x4a4bf
movq -0x38(%rbp), %rax
addq $0x8d0, %rsp            # imm = 0x8D0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop