// File: DavidLBruce[P]sim3dof/Matrix/build/../../Matrix/src/Matrix.cpp
// Function: Matrix::Chol_LLt(bool&)
Matrix Matrix::Chol_LLt(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 = 0; col < row+1; ++col)
      {
        sum = 0.0;
        for (idx = 0; idx < col; ++idx)
        {
          if (row != 0)
          {
            sum += Lmat[row][idx] * Lmat[col][idx];
          }
        }

        if (row == col)
        {
          test = sqrt(Amat[row][col] - sum);
          if (test >= 0.0)
          {
            Lmat[row][col] = test;
          }
          else
          {
            posDef = false;
            Lmat = 0.0;
            return Lmat;
          }
        }
        else
        {
          Lmat[row][col] = (Amat[row][col] - sum) / Lmat[col][col];
        }
      }  // 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 0x22790
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 0xc534(%rip), %rsi      # 0x2ecb8
leaq 0xd25(%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 0x227bf
leaq -0x30(%rbp), %rdi
callq 0x234f0
movl %eax, -0xb4(%rbp)
jmp 0x227d0
movl -0xb4(%rbp), %edx
movl -0xa4(%rbp), %esi
movq -0x98(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1f2e0
jmp 0x227ed
leaq -0x30(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x21cc0
movb %al, -0xb5(%rbp)
jmp 0x22801
movb -0xb5(%rbp), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movq -0x18(%rbp), %rax
testb $0x1, (%rax)
je 0x22ab0
movl $0x0, -0x50(%rbp)
movq -0x88(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x22aae
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x50(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x22a9e
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x22926
cmpl $0x0, -0x50(%rbp)
je 0x22916
movq -0x98(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x1fe60
movq %rax, -0xc0(%rbp)
jmp 0x2288c
movq -0x98(%rbp), %rdi
movq -0xc0(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xd0(%rbp)
movl -0x34(%rbp), %esi
callq 0x1fe60
movq %rax, -0xc8(%rbp)
jmp 0x228bc
movsd -0xd0(%rbp), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x22916
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22ae6
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x1f580
jmp 0x22ae6
jmp 0x22918
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2285e
movl -0x50(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x229ed
movl -0x50(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x1fe60
movq %rax, -0xd8(%rbp)
jmp 0x22947
movq -0xd8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x58(%rbp), %xmm0
callq 0x3190
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x229b3
movq -0x98(%rbp), %rdi
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movl -0x50(%rbp), %esi
callq 0x1fe60
movq %rax, -0xe0(%rbp)
jmp 0x22999
movq -0xe0(%rbp), %rax
movsd -0xe8(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x229e8
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
leaq -0x78(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1ffd0
jmp 0x229cf
leaq -0x78(%rbp), %rdi
callq 0x1f580
movb $0x1, -0x39(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0x22abb
jmp 0x22a8e
movl -0x50(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x1fe60
movq %rax, -0xf0(%rbp)
jmp 0x22a02
movq -0x98(%rbp), %rdi
movq -0xf0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %ecx, %esi
movsd (%rax,%rcx,8), %xmm0
movsd -0x58(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
callq 0x1fe60
movq %rax, -0xf8(%rbp)
jmp 0x22a3a
movq -0x98(%rbp), %rdi
movsd -0x100(%rbp), %xmm0
movq -0xf8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
movl -0x50(%rbp), %esi
callq 0x1fe60
movq %rax, -0x108(%rbp)
jmp 0x22a76
movq -0x108(%rbp), %rax
movsd -0x110(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x22a90
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2283e
jmp 0x22aa0
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x22824
jmp 0x22ab0
movb $0x1, -0x39(%rbp)
movl $0x1, -0x7c(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x22acd
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
nopl (%rax,%rax)