// File: /workspace/github_cpp_makefile_star2_O1/bothaynahazem[P]AsuMathLabG13/Matrix2017.cpp
// Function: Matrix::getInverse()
Matrix Matrix::getInverse() //inverse=(1/determinant)*transpose of cofactor matrix
{
	if(type=="complex")
	{

	if (nRows != nColumns) //inverse can only be done on square matrices
		throw("Invalid Matrix Dimension");
	Matrix n=*this;
Matrix m("complex",nRows, nColumns); //cofactor matrix
	complex<double> det_value = n.getcDeterminant(); //determinant value of the matrix

	if (det_value==0.0)
        {
		Matrix s("complex",nRows,nColumns,MI_VALUE,NAN);
		return s;
	}


	double sign_c =1;
	double sign_r=1;

	for (int iR = 0;iR<m.nRows;iR++)
    {
        sign_c=sign_r;
		for (int iC = 0;iC<m.nColumns;iC++)
		{
			m.cvalues[iR][iC] = sign_c * n.getCofactor(iR, iC).getcDeterminant();//getting detreminant values of cofactor matrix
			sign_c *=-1;//following sign rule in matrices
		}
        sign_r*=-1;
    }
	m=m.getTranspose();//transpose of cofactor matrix
	m *= (1.0 / det_value);
	return m;
 }

 if(type!="complex")
 {
 if (nRows != nColumns) //inverse can only be done on square matrices
	 throw("Invalid Matrix Dimension");
 Matrix n=*this;
 Matrix m(nRows, nColumns); //cofactor matrix
 double det_value = n.getDeterminant(); //determinant value of the matrix

 if (det_value==0.0)
        {
		Matrix s(nRows,nColumns,MI_VALUE,NAN);
		return s;
	}

 int sign_c =1;
 int sign_r=1;

 for (int iR = 0;iR<m.nRows;iR++)
	 {
			 sign_c=sign_r;
	 for (int iC = 0;iC<m.nColumns;iC++)
	 {
		 m.values[iR][iC] = sign_c * n.getCofactor(iR, iC).getDeterminant();//getting detreminant values of cofactor matrix
		 sign_c *=-1;//following sign rule in matrices
	 }
			 sign_r*=-1;
	 }
 m=m.getTranspose();//transpose of cofactor matrix
 m *= (1.0 / det_value);
 return m;
 }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rsi), %r15
leaq 0x4710(%rip), %rsi      # 0x111f5
movq %r15, %rdi
callq 0x30e0
testl %eax, %eax
je 0xcb77
leaq 0x46f9(%rip), %rsi      # 0x111f5
movq %r15, %rdi
callq 0x30e0
movl (%r14), %eax
cmpl 0x4(%r14), %eax
jne 0xcf65
leaq -0x150(%rbp), %rdi
movq %r14, %rsi
callq 0xa4f6
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq -0x68(%rbp), %rdi
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
callq 0xa1a2
leaq -0x150(%rbp), %rdi
callq 0xd896
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xccae
jp 0xccae
movl (%r14), %esi
movl 0x4(%r14), %edx
movsd 0x4603(%rip), %xmm0     # 0x11168
movq %rbx, %rdi
movl $0x4, %ecx
callq 0xa1a2
jmp 0xcf3b
movl (%r14), %eax
cmpl 0x4(%r14), %eax
jne 0xcf65
leaq -0x150(%rbp), %rdi
movq %r14, %rsi
callq 0xa4f6
leaq -0xd0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x4650(%rip), %rsi      # 0x111f5
leaq 0x4650(%rip), %rdx      # 0x111fc
leaq -0xe0(%rbp), %rdi
callq 0x9334
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq -0x68(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorl %r8d, %r8d
callq 0x10518
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0xcbf5
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3300
leaq -0x150(%rbp), %rdi
callq 0xdab8
movsd %xmm1, -0x98(%rbp)
xorpd %xmm2, %xmm2
movsd %xmm0, -0xa0(%rbp)
ucomisd %xmm2, %xmm0
jne 0xcdec
jp 0xcdec
movsd -0x98(%rbp), %xmm1
ucomisd %xmm2, %xmm1
jne 0xcdec
jp 0xcdec
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x45a6(%rip), %rsi      # 0x111f5
leaq 0x45a6(%rip), %rdx      # 0x111fc
leaq -0xc0(%rbp), %rdi
callq 0x9334
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq -0xc0(%rbp), %rsi
movsd 0x44f0(%rip), %xmm0     # 0x11168
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movl $0x4, %r8d
callq 0x10518
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0xcf3b
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3300
jmp 0xcf3b
movsd %xmm0, -0x80(%rbp)
movq %rbx, -0x30(%rbp)
cmpl $0x0, -0x68(%rbp)
jle 0xcd45
movl $0x1, -0x90(%rbp)
xorl %r14d, %r14d
leaq -0x118(%rbp), %r15
leaq -0x150(%rbp), %r12
cmpl $0x0, -0x64(%rbp)
jle 0xcd33
xorl %r13d, %r13d
movl -0x90(%rbp), %ebx
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl %r13d, %ecx
callq 0xd6a0
movq %r15, %rdi
callq 0xd896
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
mulsd %xmm1, %xmm0
movq -0x60(%rbp), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
movq %r15, %rdi
callq 0xa0be
negl %ebx
incq %r13
movslq -0x64(%rbp), %rax
cmpq %rax, %r13
jl 0xcceb
negl -0x90(%rbp)
incq %r14
movslq -0x68(%rbp), %rax
cmpq %rax, %r14
jl 0xccdc
leaq -0x118(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xe742
leaq -0x68(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa54e
movq -0x30(%rbp), %rbx
leaq -0x188(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xa4f6
leaq -0x188(%rbp), %rdi
callq 0xa0be
leaq -0x118(%rbp), %rdi
callq 0xa0be
movslq -0x68(%rbp), %rax
testq %rax, %rax
jle 0xcddb
movsd 0x43b6(%rip), %xmm0     # 0x11158
divsd -0x80(%rbp), %xmm0
movl -0x64(%rbp), %ecx
movq -0x60(%rbp), %rdx
xorl %esi, %esi
testl %ecx, %ecx
jle 0xcdd3
movq (%rdx,%rsi,8), %rdi
xorl %r8d, %r8d
movsd (%rdi,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rcx
jne 0xcdbb
incq %rsi
cmpq %rax, %rsi
jne 0xcdb0
leaq -0x68(%rbp), %rsi
movq %rbx, %rdi
callq 0xa710
jmp 0xcf3b
movq %rbx, -0x30(%rbp)
cmpl $0x0, -0x68(%rbp)
jle 0xceb9
movsd 0x4356(%rip), %xmm0     # 0x11158
movapd %xmm0, -0x80(%rbp)
xorl %r14d, %r14d
leaq -0x118(%rbp), %r15
leaq -0x150(%rbp), %r12
cmpl $0x0, -0x64(%rbp)
jle 0xce97
movl $0x8, %ebx
xorl %r13d, %r13d
movapd -0x80(%rbp), %xmm0
movapd %xmm0, -0x90(%rbp)
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl %r13d, %ecx
callq 0xd6a0
movq %r15, %rdi
callq 0xdab8
movapd -0x90(%rbp), %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movq -0x58(%rbp), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, -0x8(%rax,%rbx)
movsd %xmm1, (%rax,%rbx)
movq %r15, %rdi
callq 0xa0be
movapd -0x90(%rbp), %xmm0
xorpd 0x4339(%rip), %xmm0     # 0x111c0
incq %r13
movslq -0x64(%rbp), %rax
addq $0x10, %rbx
cmpq %rax, %r13
jl 0xce2b
movapd -0x80(%rbp), %xmm0
xorpd 0x431c(%rip), %xmm0     # 0x111c0
movapd %xmm0, -0x80(%rbp)
incq %r14
movslq -0x68(%rbp), %rax
cmpq %rax, %r14
jl 0xce18
leaq -0x118(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xe742
leaq -0x68(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa54e
movq -0x30(%rbp), %rbx
leaq -0x1c0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xa4f6
leaq -0x1c0(%rbp), %rdi
callq 0xa0be
leaq -0x118(%rbp), %rdi
callq 0xa0be
movsd 0x424b(%rip), %xmm0     # 0x11158
xorpd %xmm1, %xmm1
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm3
callq 0x31f0
leaq -0x68(%rbp), %rdi
callq 0xc6f0
leaq -0x68(%rbp), %rsi
movq %rbx, %rdi
callq 0xa710
leaq -0x68(%rbp), %rdi
callq 0xa0be
leaq -0x150(%rbp), %rdi
callq 0xa0be
movq %rbx, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x3170
leaq 0x4368(%rip), %rcx      # 0x112de
movq %rcx, (%rax)
movq 0x9040(%rip), %rsi      # 0x15fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x34d0
jmp 0xcfe9
jmp 0xcfe9
jmp 0xcfe9
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0xcffd
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3300
jmp 0xcffd
jmp 0xcfe9
jmp 0xcfe9
jmp 0xcfe9
jmp 0xcfee
jmp 0xcfe9
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0xd006
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3300
jmp 0xd006
jmp 0xcfde
jmp 0xcfee
movq %rax, %rbx
jmp 0xd006
jmp 0xcfe9
jmp 0xcfe9
jmp 0xcfee
movq %rax, %rbx
jmp 0xcffd
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0xa0be
leaq -0x68(%rbp), %rdi
callq 0xa0be
leaq -0x150(%rbp), %rdi
callq 0xa0be
movq %rbx, %rdi
callq 0x3520