// File: /workspace/github_cpp_makefile_star2_O3/hitc8494[P]Matrix/matrix.cpp
// Function: Matrix::inv()
Matrix Matrix::inv(){
  if( _m == _n ){
    //*****Create a matching identity matrix to mirror our row operations.
    Matrix identity( _m, _n );
    for( uint i = 0; i < _m; i++ ) 
      identity._data[i][i] = 1;
    
    Matrix result = *this;
    //*****For each leading 1...
    for( uint i = 0; i < _m; i++ ){
      //*****Put a leading nonzero in the current row.
      if( result._data[i][i] == 0 ){
	for( uint j = i+1; j < _m; j++ ){
	  if( result._data[j][i] != 0 ){
	    identity.SWITCHRows( i+1, j+1 );
	    result.SWITCHRows( i+1, j+1 );
	    break;
	  }
	}
      }
      if( result._data[i][i] == 0 ){ //All 0s in the column. No inverse possible.
	_error = 1;
	return *this;
      }
      //*****Multiply current row by 1/value to give it a leading 1.
      double value = result._data[i][i];
      result.MULTIPLYRow( 1/value, i+1 );
      identity.MULTIPLYRow( 1/value, i+1 );
      //*****Clean the column so the leading 1 is the only number in the column.
      Matrix res( result, i );
      Matrix ide( identity, i );
      for( uint j = 0; j < _m; j++ ){
	if( i != j ){
	  double coeff = result._data[j][i];
	  result.ADDToRow( (res*-coeff), j+1 );
	  identity.ADDToRow( (ide*-coeff), j+1 );
	}
      }
    }
    return identity;
  }
  else {
    _error = 1;
    return *this;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %r14
movq %rdi, %rbx
movl 0x18(%rsi), %edx
cmpl 0x1c(%rsi), %edx
jne 0x3cdd
leaq 0x78(%rsp), %rdi
movl %edx, %esi
callq 0x26dc
movl 0x18(%r14), %eax
testq %rax, %rax
je 0x39c4
movq 0x78(%rsp), %rcx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq (%rcx), %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
addq $0x18, %rcx
cmpq %rdx, %rax
jne 0x39b1
movq %rbx, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x2848
movl 0x18(%r14), %ecx
testl %ecx, %ecx
je 0x3cc9
movl $0x2, 0x4(%rsp)
movl $0x18, %eax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
leaq 0xb8(%rsp), %r12
leaq 0x18(%rsp), %r13
movq 0x38(%rsp), %rdx
leaq (%r15,%r15,2), %rax
movq %rax, 0x20(%rsp)
movq (%rdx,%rax,8), %rax
movsd (%rax,%r15,8), %xmm0
ucomisd 0x5624(%rip), %xmm0     # 0x9048
jne 0x3a9b
jp 0x3a9b
leaq 0x1(%r15), %rbp
movl %ecx, %esi
cmpq %rsi, %rbp
jae 0x3a9b
addq 0x10(%rsp), %rdx
negl %ecx
movl 0x4(%rsp), %esi
movl %esi, %ebx
movq (%rdx), %rsi
movsd (%rsi,%r15,8), %xmm1
ucomisd 0x55f7(%rip), %xmm1     # 0x9048
jne 0x3a6b
jp 0x3a6b
addq $0x18, %rdx
leal (%rcx,%rbx), %esi
incl %esi
movl %ebx, %edi
incl %edi
movl %edi, %ebx
cmpl $0x1, %esi
jne 0x3a40
jmp 0x3a9b
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2e5e
leaq 0x38(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2e5e
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%r15,8), %xmm0
ucomisd 0x55a5(%rip), %xmm0     # 0x9048
jne 0x3aab
jnp 0x3cef
movsd 0x558d(%rip), %xmm1     # 0x9040
divsd %xmm0, %xmm1
movl 0x50(%rsp), %ecx
cmpq %rcx, %r15
jae 0x3ae3
movl 0x54(%rsp), %ecx
testq %rcx, %rcx
je 0x3ae8
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x3acb
jmp 0x3ae8
movb $0x1, 0x69(%rsp)
movl 0x90(%rsp), %eax
cmpq %rax, %r15
jae 0x3b28
movl 0x94(%rsp), %eax
testq %rax, %rax
je 0x3b30
movq 0x78(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x3b10
jmp 0x3b30
movb $0x1, 0xa9(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl %r15d, %edx
callq 0x27e0
leaq 0xf8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
movl %r15d, %edx
callq 0x27e0
movl 0x18(%r14), %eax
testl %eax, %eax
je 0x3c95
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x3c87
movq 0x38(%rsp), %rax
leaq (%rbx,%rbx,2), %rbp
movq (%rax,%rbp,8), %rax
movsd (%rax,%r15,8), %xmm0
xorpd 0x54a4(%rip), %xmm0     # 0x9030
movapd %xmm0, 0x20(%rsp)
movlpd %xmm0, 0x18(%rsp)
movq %r12, %rdi
leaq 0x138(%rsp), %rsi
movq %r13, %rdx
callq 0x36ec
movl 0x50(%rsp), %eax
cmpq %rax, %rbx
jb 0x3bc5
cmpl $0x1, 0xd0(%rsp)
jne 0x3bc5
movb $0x1, 0x69(%rsp)
jmp 0x3bfb
movl 0x54(%rsp), %eax
testq %rax, %rax
je 0x3bfb
movq 0x38(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq 0xb8(%rsp), %rdx
movq (%rdx), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
addsd (%rdx,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x3be4
movq %r12, %rdi
callq 0x410a
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
leaq 0xf8(%rsp), %rsi
movq %r13, %rdx
callq 0x36ec
movl 0x90(%rsp), %eax
cmpq %rax, %rbx
jb 0x3c42
cmpl $0x1, 0xd0(%rsp)
jne 0x3c42
movb $0x1, 0xa9(%rsp)
jmp 0x3c7b
movl 0x94(%rsp), %eax
testq %rax, %rax
je 0x3c7b
movq 0x78(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq 0xb8(%rsp), %rdx
movq (%rdx), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
addsd (%rdx,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x3c64
movq %r12, %rdi
callq 0x410a
movl 0x18(%r14), %eax
incq %rbx
movl %eax, %ecx
cmpq %rcx, %rbx
jb 0x3b68
incq %r15
leaq 0xf8(%rsp), %rdi
callq 0x410a
leaq 0x138(%rsp), %rdi
callq 0x410a
movl 0x18(%r14), %ecx
incl 0x4(%rsp)
addq $0x18, 0x10(%rsp)
cmpq %rcx, %r15
jb 0x3a04
leaq 0x78(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2848
jmp 0x3d04
movb $0x1, 0x31(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2848
jmp 0x3d18
movb $0x1, 0x31(%r14)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2848
leaq 0x38(%rsp), %rdi
callq 0x410a
leaq 0x78(%rsp), %rdi
callq 0x410a
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3d3d
jmp 0x3d3d
movq %rax, %rbx
jmp 0x3d6b
jmp 0x3d3d
movq %rax, %rbx
jmp 0x3d54
movq %rax, %rbx
jmp 0x3d61
jmp 0x3d44
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x410a
leaq 0x138(%rsp), %rdi
callq 0x410a
leaq 0x38(%rsp), %rdi
callq 0x410a
leaq 0x78(%rsp), %rdi
callq 0x410a
movq %rbx, %rdi
callq 0x21f0
nop