// File: /workspace/github_cpp_makefile_star2_O3/srajangarg[P]raytracer/src/core/Algebra3.hpp
// Function: Mat4::inverse() const
inline Mat4 Mat4::inverse() const    // Gauss-Jordan elimination with partial pivoting
{
  Mat4 a(*this),          // As a evolves from original mat into identity
       b(identity3D());   // b evolves from identity into inverse(a)
  int i, j, i1;

  // Loop over cols of a from left to right, eliminating above and below diag
  for (j=0; j<4; j++)   // Find largest pivot in column j among rows j..3
  {
    i1 = j;         // Row with largest pivot candidate
    for (i=j+1; i<4; i++)
      if (fabs(a.v[i].n[j]) > fabs(a.v[i1].n[j]))
        i1 = i;

    // Swap rows i1 and j in a and b to put pivot on diagonal
    swap(a.v[i1], a.v[j]);
    swap(b.v[i1], b.v[j]);

    // Scale row j to have a unit diagonal
    if (a.v[j].n[j]==0.)
      ALG3_ERROR("Mat4::inverse: singular matrix; can't invert\n");

    b.v[j] /= a.v[j].n[j];
    a.v[j] /= a.v[j].n[j];

    // Eliminate off-diagonal elems in col j of a, doing identical ops to b
    for (i=0; i<4; i++)
      if (i!=j)
      {
        b.v[i] -= a.v[i].n[j]*b.v[j];
        a.v[i] -= a.v[i].n[j]*a.v[j];
      }
  }

  return b;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x88, %rsp
movq %rsp, %rax
movups (%rsi), %xmm0
movaps %xmm0, (%rax)
movups 0x10(%rsi), %xmm0
movaps %xmm0, 0x10(%rax)
leaq 0x20(%rsp), %rcx
movups 0x20(%rsi), %xmm0
movaps %xmm0, (%rcx)
movups 0x30(%rsi), %xmm0
movaps %xmm0, 0x10(%rcx)
movups 0x40(%rsi), %xmm0
movaps %xmm0, 0x20(%rcx)
movups 0x50(%rsi), %xmm0
movaps %xmm0, 0x30(%rcx)
movups 0x60(%rsi), %xmm0
movaps %xmm0, 0x40(%rcx)
movups 0x70(%rsi), %xmm0
movaps %xmm0, 0x50(%rcx)
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
movq %rdx, 0x28(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x40(%rdi)
movq %rdx, 0x50(%rdi)
movups %xmm0, 0x58(%rdi)
movups %xmm0, 0x68(%rdi)
movq %rdx, 0x78(%rdi)
movq $-0x3, %rdx
xorl %esi, %esi
movapd 0x3e26(%rip), %xmm0     # 0x2ba00
xorpd %xmm1, %xmm1
movsd 0x3562(%rip), %xmm2     # 0x2b148
xorl %r8d, %r8d
cmpq $0x2, %r8
ja 0x27c2b
leaq (%rsp,%r8,8), %r9
movq %rdx, %r10
movq %rcx, %r11
movl %r8d, %ebx
movsd (%r11), %xmm3
andpd %xmm0, %xmm3
movslq %ebx, %r14
shlq $0x5, %r14
movsd (%r9,%r14), %xmm4
andpd %xmm0, %xmm4
ucomisd %xmm4, %xmm3
jbe 0x27c20
leal 0x4(%r10), %ebx
addq $0x20, %r11
incq %r10
jne 0x27bfc
jmp 0x27c2e
movl %r8d, %ebx
movslq %ebx, %r11
shlq $0x5, %r11
movq %r8, %r9
shlq $0x5, %r9
leaq (%rsp,%r9), %r10
movapd (%rsp,%r11), %xmm4
movapd 0x10(%rsp,%r11), %xmm3
movaps (%r10), %xmm5
movaps %xmm5, (%rsp,%r11)
movaps 0x10(%r10), %xmm5
movaps %xmm5, 0x10(%rsp,%r11)
movapd %xmm4, (%r10)
movapd %xmm3, 0x10(%r10)
movupd (%rdi,%r11), %xmm6
movupd 0x10(%rdi,%r11), %xmm5
movups (%rdi,%r9), %xmm7
movups %xmm7, (%rdi,%r11)
movups 0x10(%rdi,%r9), %xmm7
movups %xmm7, 0x10(%rdi,%r11)
movsd (%r10,%r8,8), %xmm7
ucomisd %xmm1, %xmm7
jne 0x27ca1
jnp 0x27d90
incq %r8
addq %rdi, %r9
movapd %xmm2, %xmm8
divsd %xmm7, %xmm8
unpcklpd %xmm8, %xmm8            # xmm8 = xmm8[0,0]
mulpd %xmm8, %xmm6
movupd %xmm6, (%r9)
mulpd %xmm8, %xmm5
movupd %xmm5, 0x10(%r9)
mulpd %xmm8, %xmm4
movapd %xmm4, (%r10)
mulpd %xmm8, %xmm3
movapd %xmm3, 0x10(%r10)
xorl %r11d, %r11d
cmpq %r11, %rsi
je 0x27d58
movupd (%r9), %xmm3
movsd (%rax,%r11), %xmm4
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm4, %xmm3
movupd (%rdi,%r11), %xmm5
subpd %xmm3, %xmm5
movupd 0x10(%rdi,%r11), %xmm3
movupd %xmm5, (%rdi,%r11)
movupd 0x10(%r9), %xmm5
mulpd %xmm4, %xmm5
subpd %xmm5, %xmm3
movupd %xmm3, 0x10(%rdi,%r11)
movapd (%r10), %xmm3
mulpd %xmm4, %xmm3
movapd (%rsp,%r11), %xmm5
subpd %xmm3, %xmm5
movapd 0x10(%rsp,%r11), %xmm3
movapd %xmm5, (%rsp,%r11)
mulpd 0x10(%r10), %xmm4
subpd %xmm4, %xmm3
movapd %xmm3, 0x10(%rsp,%r11)
addq $0x20, %r11
cmpq $0x80, %r11
jne 0x27ce3
addq $0x28, %rcx
incq %rdx
addq $0x20, %rsi
addq $0x8, %rax
cmpq $0x4, %r8
jne 0x27be9
movq %rdi, %rax
addq $0x88, %rsp
popq %rbx
popq %r14
retq
leaq 0x56e6(%rip), %rdi      # 0x2d47d
leaq 0x56e5(%rip), %rsi      # 0x2d483
leaq 0x56f4(%rip), %rcx      # 0x2d499
movl $0x4fc, %edx            # imm = 0x4FC
callq 0x41f0
nop