// File: /workspace/github_cpp_makefile_star2_O2/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 0x35dd
movq %rbx, 0x10(%rsp)
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movl %edx, %esi
callq 0x25b2
movl 0x18(%r14), %eax
movq (%rbx), %rcx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
cmpq %rdx, %rax
je 0x35f2
movq (%rcx), %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
addq $0x18, %rcx
jmp 0x35c8
movb $0x1, 0x31(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2708
jmp 0x3849
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x2708
pushq $0x1
popq %r9
pushq $0x2
popq %rdi
xorl %ebp, %ebp
xorpd %xmm2, %xmm2
leaq 0x78(%rsp), %r8
leaq 0x138(%rsp), %rbx
movl 0x18(%r14), %eax
cmpq %rax, %rbp
jae 0x380c
movq 0x38(%rsp), %rcx
imulq $0x18, %rbp, %r13
movq (%rcx,%r13), %rdx
movsd (%rdx,%rbp,8), %xmm0
ucomisd %xmm2, %xmm0
movl %r9d, 0xc(%rsp)
movl %edi, 0x8(%rsp)
jne 0x36b0
jp 0x36b0
movl %r9d, %edx
imulq $0x18, %rdx, %rsi
addq %rsi, %rcx
movl %edi, %r15d
cmpq %rax, %rdx
jae 0x36b0
movq (%rcx), %rsi
movsd (%rsi,%rbp,8), %xmm1
ucomisd %xmm2, %xmm1
jne 0x3677
jp 0x3677
incq %rdx
incl %r15d
addq $0x18, %rcx
jmp 0x3656
leal 0x1(%rbp), %r12d
movq %r8, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x2bd6
leaq 0x38(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x2bd6
movq 0x38(%rsp), %rax
movq (%rax,%r13), %rax
movsd (%rax,%rbp,8), %xmm0
xorpd %xmm2, %xmm2
leaq 0x78(%rsp), %r8
ucomisd %xmm2, %xmm0
jne 0x36bc
jnp 0x3820
movsd 0x4944(%rip), %xmm1     # 0x8008
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
leaq 0x1(%rbp), %r13
leaq 0x38(%rsp), %rdi
movapd %xmm1, %xmm0
movl %r13d, %esi
movq %r8, %r12
callq 0x2cc2
movq %r12, %rdi
movsd 0x20(%rsp), %xmm0
movq %r13, 0x30(%rsp)
movl %r13d, %esi
callq 0x2cc2
leaq 0xf8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl %ebp, %edx
callq 0x26aa
leaq 0xb8(%rsp), %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x26aa
leaq 0x18(%rsp), %r15
xorl %r12d, %r12d
movl 0x18(%r14), %eax
cmpq %rax, %r12
jae 0x37d1
cmpq %r12, %rbp
jne 0x3741
incq %r12
jmp 0x372a
movq 0x38(%rsp), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%rbp,8), %xmm0
xorpd 0x48b5(%rip), %xmm0     # 0x8010
movapd %xmm0, 0x20(%rsp)
movlpd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
leaq 0xf8(%rsp), %rsi
movq %r15, %rdx
callq 0x3340
incq %r12
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x2afe
movq %rbx, %rdi
callq 0x3bc8
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
leaq 0xb8(%rsp), %rsi
movq %r15, %rdx
callq 0x3340
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x2afe
movq %rbx, %rdi
callq 0x3bc8
jmp 0x372a
leaq 0xb8(%rsp), %rdi
callq 0x3bc8
leaq 0xf8(%rsp), %rdi
callq 0x3bc8
movl 0xc(%rsp), %r9d
incl %r9d
movl 0x8(%rsp), %edi
incl %edi
movq 0x30(%rsp), %rbp
xorpd %xmm2, %xmm2
leaq 0x78(%rsp), %r8
jmp 0x3619
leaq 0x78(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x2708
jmp 0x3835
movb $0x1, 0x31(%r14)
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2708
leaq 0x38(%rsp), %rdi
callq 0x3bc8
leaq 0x78(%rsp), %rdi
callq 0x3bc8
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3869
jmp 0x3869
movq %rax, %rbx
jmp 0x389c
jmp 0x3869
movq %rax, %rbx
jmp 0x3892
movq %rax, %rbx
jmp 0x3885
jmp 0x3875
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3bc8
leaq 0xf8(%rsp), %rdi
callq 0x3bc8
leaq 0x38(%rsp), %rdi
callq 0x3bc8
leaq 0x78(%rsp), %rdi
callq 0x3bc8
movq %rbx, %rdi
callq 0x21f0