// File: /workspace/github_cpp_makefile_star2_O2/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 0x42e6(%rip), %rsi      # 0xf1f5
movq %r15, %rdi
callq 0x795a
testb %al, %al
je 0xb017
movl (%r14), %eax
cmpl 0x4(%r14), %eax
jne 0xb306
leaq -0x108(%rbp), %rdi
movq %r14, %rsi
callq 0x8daa
leaq 0x42b3(%rip), %rsi      # 0xf1f5
leaq -0x148(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x7844
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq -0x88(%rbp), %rdi
leaq -0x148(%rbp), %rsi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorl %r8d, %r8d
callq 0xe29a
leaq -0x148(%rbp), %rdi
callq 0x3170
leaq -0x108(%rbp), %rdi
callq 0xbdf6
movsd %xmm0, -0xd0(%rbp)
movsd %xmm1, -0xc8(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0xb09a
jp 0xb09a
ucomisd %xmm2, %xmm1
jne 0xb09a
jp 0xb09a
leaq 0x4228(%rip), %rsi      # 0xf1f5
leaq -0x128(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x7844
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq -0x128(%rbp), %rsi
pushq $0x4
popq %r8
movsd 0x416e(%rip), %xmm0     # 0xf168
xorpd %xmm1, %xmm1
movq %rbx, %rdi
callq 0xe29a
leaq -0x128(%rbp), %rdi
callq 0x3170
jmp 0xb2d9
leaq 0x41d7(%rip), %rsi      # 0xf1f5
movq %r15, %rdi
callq 0x78c0
movl (%r14), %eax
cmpl 0x4(%r14), %eax
jne 0xb306
leaq -0x108(%rbp), %rdi
movq %r14, %rsi
callq 0x8daa
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq -0x88(%rbp), %rdi
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
callq 0x8ace
leaq -0x108(%rbp), %rdi
callq 0xbbca
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xb1e5
jp 0xb1e5
movl (%r14), %esi
movl 0x4(%r14), %edx
pushq $0x4
popq %rcx
movsd 0x40db(%rip), %xmm0     # 0xf168
movq %rbx, %rdi
callq 0x8ace
jmp 0xb2d9
movq %rbx, -0x30(%rbp)
movsd 0x40b2(%rip), %xmm0     # 0xf158
movapd %xmm0, -0x40(%rbp)
xorl %r14d, %r14d
leaq -0xc0(%rbp), %r15
leaq -0x108(%rbp), %r12
movslq -0x88(%rbp), %rax
cmpq %rax, %r14
jge 0xb159
pushq $0x8
popq %rbx
xorl %r13d, %r13d
movapd -0x40(%rbp), %xmm0
movapd %xmm0, -0x50(%rbp)
movslq -0x84(%rbp), %rax
cmpq %rax, %r13
jge 0xb13f
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl %r13d, %ecx
callq 0xba04
movq %r15, %rdi
callq 0xbdf6
movapd -0x50(%rbp), %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movq -0x78(%rbp), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, -0x8(%rax,%rbx)
movsd %xmm1, (%rax,%rbx)
movq %r15, %rdi
callq 0x8a24
movapd -0x50(%rbp), %xmm0
xorpd 0x408a(%rip), %xmm0     # 0xf1c0
incq %r13
addq $0x10, %rbx
jmp 0xb0d7
movapd -0x40(%rbp), %xmm0
xorpd 0x4074(%rip), %xmm0     # 0xf1c0
movapd %xmm0, -0x40(%rbp)
incq %r14
jmp 0xb0bc
leaq -0xc0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xc8b6
leaq -0x1b8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x9e42
movq -0x30(%rbp), %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x8a24
leaq -0xc0(%rbp), %r14
movq %r14, %rdi
callq 0x8a24
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r14)
leaq -0xc0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xe5ab
leaq -0x88(%rbp), %rdi
callq 0xab72
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x8f98
jmp 0xb2d9
movsd %xmm0, -0x40(%rbp)
movq %rbx, -0x30(%rbp)
pushq $0x1
popq %rax
movl %eax, -0x50(%rbp)
xorl %r14d, %r14d
leaq -0xc0(%rbp), %r15
leaq -0x108(%rbp), %r12
movslq -0x88(%rbp), %rax
cmpq %rax, %r14
jge 0xb269
xorl %r13d, %r13d
movl -0x50(%rbp), %ebx
movslq -0x84(%rbp), %rax
cmpq %rax, %r13
jge 0xb261
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl %r13d, %ecx
callq 0xba04
movq %r15, %rdi
callq 0xbbca
cvtsi2sd %ebx, %xmm1
mulsd %xmm1, %xmm0
movq -0x80(%rbp), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
movq %r15, %rdi
callq 0x8a24
negl %ebx
incq %r13
jmp 0xb217
negl -0x50(%rbp)
incq %r14
jmp 0xb205
leaq -0xc0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xc8b6
leaq -0x180(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x9e42
movq -0x30(%rbp), %rbx
leaq -0x180(%rbp), %rdi
callq 0x8a24
leaq -0xc0(%rbp), %rdi
callq 0x8a24
movsd 0x3e9e(%rip), %xmm0     # 0xf158
divsd -0x40(%rbp), %xmm0
leaq -0x88(%rbp), %r14
movq %r14, %rdi
callq 0xab2c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8f98
leaq -0x88(%rbp), %rdi
callq 0x8a24
leaq -0x108(%rbp), %rdi
callq 0x8a24
movq %rbx, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x8
popq %rdi
callq 0x31a0
leaq 0x3fc9(%rip), %rcx      # 0xf2de
movq %rcx, (%rax)
movq 0x8ca9(%rip), %rsi      # 0x13fc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x34e0
jmp 0xb37b
jmp 0xb36a
jmp 0xb37b
jmp 0xb37b
jmp 0xb36a
jmp 0xb37b
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x3170
jmp 0xb37e
jmp 0xb37b
jmp 0xb37b
jmp 0xb37b
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
callq 0x3170
jmp 0xb38a
jmp 0xb35f
movq %rax, %rbx
jmp 0xb38a
jmp 0xb37b
jmp 0xb36a
jmp 0xb37b
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x8a24
jmp 0xb37e
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x8a24
leaq -0x108(%rbp), %rdi
callq 0x8a24
movq %rbx, %rdi
callq 0x3520