// File: /workspace/github_cpp_makefile_star2_O1/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), %esi
movl 0x1c(%r14), %edx
cmpl %edx, %esi
jne 0x3ce8
leaq 0x78(%rsp), %rdi
callq 0x2704
movl 0x18(%r14), %eax
testq %rax, %rax
je 0x39db
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 0x39c8
movq %rbx, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x2870
movl 0x18(%r14), %eax
testl %eax, %eax
je 0x3cd4
movl $0x2, 0x4(%rsp)
movl $0x18, %ecx
movq %rcx, 0x10(%rsp)
xorl %r15d, %r15d
leaq 0xb8(%rsp), %r12
leaq 0x18(%rsp), %r13
movq 0x38(%rsp), %rcx
leaq (%r15,%r15,2), %rbp
movq (%rcx,%rbp,8), %rdx
movsd (%rdx,%r15,8), %xmm0
ucomisd 0x55da(%rip), %xmm0     # 0x9010
jne 0x3a9f
jp 0x3a9f
leaq 0x1(%r15), %rsi
movl %eax, %edx
cmpq %rdx, %rsi
jae 0x3a9f
addq 0x10(%rsp), %rcx
negl %eax
movl 0x4(%rsp), %edx
movl %edx, %ebx
movq (%rcx), %rdx
movsd (%rdx,%r15,8), %xmm0
ucomisd 0x55ad(%rip), %xmm0     # 0x9010
jne 0x3a7d
jp 0x3a7d
addq $0x18, %rcx
leal (%rax,%rbx), %edx
incl %edx
movl %ebx, %edi
incl %edi
movl %edi, %ebx
cmpl $0x1, %edx
jne 0x3a52
jmp 0x3a9f
leaq 0x78(%rsp), %rdi
movl %ebx, %edx
movq %rsi, 0x20(%rsp)
callq 0x2e78
movq 0x20(%rsp), %rsi
leaq 0x38(%rsp), %rdi
movl %ebx, %edx
callq 0x2e78
movq 0x38(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r15,8), %xmm1
ucomisd 0x555a(%rip), %xmm1     # 0x9010
jne 0x3abe
jnp 0x3cfa
movsd 0x5542(%rip), %xmm0     # 0x9008
divsd %xmm1, %xmm0
movl 0x50(%rsp), %ecx
cmpq %rcx, %r15
jae 0x3af6
movl 0x54(%rsp), %ecx
testq %rcx, %rcx
je 0x3afb
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x3ade
jmp 0x3afb
movb $0x1, 0x69(%rsp)
movl 0x90(%rsp), %eax
cmpq %rax, %r15
jae 0x3b36
movl 0x94(%rsp), %eax
testq %rax, %rax
je 0x3b3e
movq 0x78(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x3b1e
jmp 0x3b3e
movb $0x1, 0xa9(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl %r15d, %edx
callq 0x2808
leaq 0xf8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
movl %r15d, %edx
callq 0x2808
cmpl $0x0, 0x18(%r14)
je 0x3ca0
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x3c90
movq 0x38(%rsp), %rax
leaq (%rbx,%rbx,2), %rbp
movq (%rax,%rbp,8), %rax
movsd (%rax,%r15,8), %xmm0
xorpd 0x5487(%rip), %xmm0     # 0x9020
movapd %xmm0, 0x20(%rsp)
movlpd %xmm0, 0x18(%rsp)
movq %r12, %rdi
leaq 0x138(%rsp), %rsi
movq %r13, %rdx
callq 0x3702
movl 0x50(%rsp), %eax
cmpq %rax, %rbx
jb 0x3bd2
cmpl $0x1, 0xd0(%rsp)
jne 0x3bd2
movb $0x1, 0x69(%rsp)
jmp 0x3c08
movl 0x54(%rsp), %eax
testq %rax, %rax
je 0x3c08
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 0x3bf1
movq %r12, %rdi
callq 0x4106
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
leaq 0xf8(%rsp), %rsi
movq %r13, %rdx
callq 0x3702
movl 0x90(%rsp), %eax
cmpq %rax, %rbx
jb 0x3c4f
cmpl $0x1, 0xd0(%rsp)
jne 0x3c4f
movb $0x1, 0xa9(%rsp)
jmp 0x3c88
movl 0x94(%rsp), %eax
testq %rax, %rax
je 0x3c88
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 0x3c71
movq %r12, %rdi
callq 0x4106
incq %rbx
movl 0x18(%r14), %eax
cmpq %rax, %rbx
jb 0x3b75
incq %r15
leaq 0xf8(%rsp), %rdi
callq 0x4106
leaq 0x138(%rsp), %rdi
callq 0x4106
movl 0x18(%r14), %eax
incl 0x4(%rsp)
addq $0x18, 0x10(%rsp)
cmpq %rax, %r15
jb 0x3a1b
leaq 0x78(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2870
jmp 0x3d0f
movb $0x1, 0x31(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2870
jmp 0x3d23
movb $0x1, 0x31(%r14)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2870
leaq 0x38(%rsp), %rdi
callq 0x4106
leaq 0x78(%rsp), %rdi
callq 0x4106
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3d48
jmp 0x3d48
movq %rax, %rbx
jmp 0x3d76
jmp 0x3d48
movq %rax, %rbx
jmp 0x3d5f
movq %rax, %rbx
jmp 0x3d6c
jmp 0x3d4f
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x4106
leaq 0x138(%rsp), %rdi
callq 0x4106
leaq 0x38(%rsp), %rdi
callq 0x4106
leaq 0x78(%rsp), %rdi
callq 0x4106
movq %rbx, %rdi
callq 0x21f0