// File: jamesgrimmett[P]orbital_determination/ex10-2_linear_least_squares.cc
// Function: inverse(std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>)
std::vector<std::vector<double> > inverse(std::vector<std::vector<double> > arr) {
  // Calculate the inverse of a 2x2 matrix

  std::vector<std::vector<double> > inv(arr[0].size(), std::vector<double>(arr[1].size()));
  
  double det = determinant(arr);

  inv[0][0] = arr[1][1]  / det;
  inv[1][1] = arr[0][0]  / det;
  inv[0][1] = -arr[1][0] / det;
  inv[1][0] = -arr[0][1] / det;

  return inv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rsi, -0x88(%rbp)
movq %rdi, %rax
movq -0x88(%rbp), %rdi
movq %rax, -0x98(%rbp)
movq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
callq 0x37a0
movq -0x88(%rbp), %rdi
movq %rax, -0x80(%rbp)
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
callq 0x37a0
movq %rax, -0x78(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x36e0
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x3f40
jmp 0x2b2b
leaq -0x45(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x3e40
movq -0x98(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0xa0(%rbp), %rcx
leaq -0x30(%rbp), %rdx
callq 0x3fb0
jmp 0x2b58
leaq -0x45(%rbp), %rdi
callq 0x3ee0
leaq -0x30(%rbp), %rdi
callq 0x3b30
leaq -0x31(%rbp), %rdi
callq 0x3780
movq -0x88(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x3b90
jmp 0x2b85
leaq -0x68(%rbp), %rdi
callq 0x35c0
movsd %xmm0, -0xc8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3cb0
movsd -0xc8(%rbp), %xmm0
movq -0x88(%rbp), %rdi
movsd %xmm0, -0x50(%rbp)
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movsd -0xc0(%rbp), %xmm0
movq -0x88(%rbp), %rdi
movsd %xmm0, (%rax)
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movsd -0xb8(%rbp), %xmm0
movq -0x88(%rbp), %rdi
movsd %xmm0, (%rax)
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movsd -0xb0(%rbp), %xmm0
movq -0x88(%rbp), %rdi
movsd %xmm0, (%rax)
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, (%rax)
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x2d9f
jmp 0x2d93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2d6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x45(%rbp), %rdi
callq 0x3ee0
leaq -0x30(%rbp), %rdi
callq 0x3b30
leaq -0x31(%rbp), %rdi
callq 0x3780
jmp 0x2daf
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x3cb0
jmp 0x2daf
movq -0x98(%rbp), %rdi
callq 0x3cb0
movq -0x90(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x1140
nopl (%rax,%rax)