// File: DavidLBruce[P]sim3dof/Matrix/build/../../Matrix/src/Matrix.cpp
// Function: Matrix::Chol_UtU(bool&)
Matrix Matrix::Chol_UtU(bool &posDef)
{
  if (rows != cols)
  {
    throw(DIMERR());
  }

  Matrix Amat = *this; 
  int    col;
  int    idx;
  Matrix Lmat(Amat.NumRows(), Amat.NumCols());
  int    row;
  double sum;
  double test;

  posDef = Amat.IsSymmetric();

  if (posDef)
  {
    for (row = 0; row < rows; ++row)
    {
      for (col = row; col < cols; ++col)
      {
        sum = 0.0;
        for (idx = 0; idx < cols-1; ++idx)
        {
          sum += Lmat[idx][row] * Lmat[idx][col];
        }

        if (row == col)
        {
          test = Amat[row][col] - sum;
          if (test > 0.0)
          {
            Lmat[row][col] = sqrt(test);
          }
          else
          {
            posDef = false;
            Lmat = 0.0;
            return Lmat;
          }
        }
        else
        {
          Lmat[row][col] = (Amat[row][col] - sum) / Lmat[row][row];
        }
      }  // end for (col = 0; col < row+1; ++col)
    }  // end for (row = 0; row < rows; ++row)
  }  // end if (posDef)

  return Lmat;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x98(%rbp)
movq %rdi, %rax
movq %rax, -0x90(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movl 0x8(%rcx), %eax
cmpl (%rcx), %eax
je 0x223a0
movl $0x8, %edi
callq 0x3110
movq %rax, %rdi
movq %rdi, -0xa0(%rbp)
xorl %esi, %esi
movl $0x8, %edx
callq 0x3130
movq -0xa0(%rbp), %rdi
callq 0x23470
movq -0xa0(%rbp), %rdi
leaq 0xc924(%rip), %rsi      # 0x2ecb8
leaq 0x1115(%rip), %rdx      # 0x234b0
callq 0x33b0
movq -0x88(%rbp), %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x1f3e0
movq -0xb0(%rbp), %rdi
movb $0x0, -0x39(%rbp)
callq 0x234d0
movl %eax, -0xa4(%rbp)
jmp 0x223cf
leaq -0x30(%rbp), %rdi
callq 0x234f0
movl %eax, -0xb4(%rbp)
jmp 0x223e0
movl -0xb4(%rbp), %edx
movl -0xa4(%rbp), %esi
movq -0x98(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1f2e0
jmp 0x223fd
leaq -0x30(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x21cc0
movb %al, -0xb5(%rbp)
jmp 0x22411
movb -0xb5(%rbp), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movq -0x18(%rbp), %rax
testb $0x1, (%rax)
je 0x226bd
movl $0x0, -0x50(%rbp)
movq -0x88(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x226bb
movl -0x50(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x88(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jge 0x226ab
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x88(%rbp), %rcx
movl -0x38(%rbp), %eax
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x22533
movq -0x98(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x1fe60
movq %rax, -0xc0(%rbp)
jmp 0x2249d
movq -0x98(%rbp), %rdi
movq -0xc0(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xd0(%rbp)
movl -0x38(%rbp), %esi
callq 0x1fe60
movq %rax, -0xc8(%rbp)
jmp 0x224cd
movsd -0xd0(%rbp), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2246e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x226f3
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x1f580
jmp 0x226f3
movl -0x50(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x225fa
movl -0x50(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x1fe60
movq %rax, -0xd8(%rbp)
jmp 0x22554
movq -0xd8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x225c0
movsd -0x60(%rbp), %xmm0
callq 0x3190
movq -0x98(%rbp), %rdi
movsd %xmm0, -0xe8(%rbp)
movl -0x50(%rbp), %esi
callq 0x1fe60
movq %rax, -0xe0(%rbp)
jmp 0x225a6
movq -0xe0(%rbp), %rax
movsd -0xe8(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x225f5
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
leaq -0x78(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1ffd0
jmp 0x225dc
leaq -0x78(%rbp), %rdi
callq 0x1f580
movb $0x1, -0x39(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0x226c8
jmp 0x2269b
movl -0x50(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x1fe60
movq %rax, -0xf0(%rbp)
jmp 0x2260f
movq -0x98(%rbp), %rdi
movq -0xf0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x58(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
movl -0x50(%rbp), %esi
callq 0x1fe60
movq %rax, -0xf8(%rbp)
jmp 0x22648
movq -0x98(%rbp), %rdi
movsd -0x100(%rbp), %xmm0
movq -0xf8(%rbp), %rax
movslq -0x50(%rbp), %rcx
movl %ecx, %esi
movsd (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
callq 0x1fe60
movq %rax, -0x108(%rbp)
jmp 0x22683
movq -0x108(%rbp), %rax
movsd -0x110(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2269d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2244d
jmp 0x226ad
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x22434
jmp 0x226bd
movb $0x1, -0x39(%rbp)
movl $0x1, -0x7c(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x226da
movq -0x98(%rbp), %rdi
callq 0x1f580
leaq -0x30(%rbp), %rdi
callq 0x1f580
movq -0x90(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x1f580
movq -0x48(%rbp), %rdi
callq 0x33d0
nopw %cs:(%rax,%rax)