// File: 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
subq $0x400, %rsp            # imm = 0x400
movq %rdi, -0x370(%rbp)
movq %rdi, %rax
movq %rax, -0x368(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x360(%rbp)
addq $0x18, %rdi
leaq 0x876b(%rip), %rsi      # 0x1b405
callq 0xafa0
testb $0x1, %al
jne 0x12ca8
jmp 0x13264
movq -0x360(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
je 0x12cdd
movl $0x8, %edi
callq 0x31c0
movq %rax, %rdi
leaq 0x8824(%rip), %rax      # 0x1b4ee
movq %rax, (%rdi)
movq 0xf2f4(%rip), %rsi      # 0x21fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x35f0
movq -0x360(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xec70
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x378(%rbp)
callq 0x3640
movq -0x378(%rbp), %rdx
leaq 0x86f7(%rip), %rsi      # 0x1b405
leaq -0xa0(%rbp), %rdi
callq 0xab40
jmp 0x12d1c
movq -0x360(%rbp), %rax
movl (%rax), %ecx
movl %ecx, -0x380(%rbp)
movl 0x4(%rax), %eax
movl %eax, -0x37c(%rbp)
leaq -0xc8(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0x19810
jmp 0x12d48
movl -0x37c(%rbp), %ecx
movl -0x380(%rbp), %edx
movsd -0xc8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
xorl %r8d, %r8d
callq 0x19470
jmp 0x12d79
leaq -0xa0(%rbp), %rdi
callq 0x3270
leaq -0xa1(%rbp), %rdi
callq 0x3410
leaq -0x48(%rbp), %rdi
callq 0x147b0
movsd %xmm1, -0x390(%rbp)
movsd %xmm0, -0x388(%rbp)
jmp 0x12dac
movsd -0x390(%rbp), %xmm0
movsd -0x388(%rbp), %xmm1
movsd %xmm1, -0xd8(%rbp)
movsd %xmm0, -0xd0(%rbp)
movq $0x0, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x19dc0
movb %al, -0x391(%rbp)
jmp 0x12df2
movb -0x391(%rbp), %al
testb $0x1, %al
jne 0x12e01
jmp 0x12f88
movb $0x0, -0xe1(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x3640
movq -0x3a0(%rbp), %rdx
leaq 0x85dc(%rip), %rsi      # 0x1b405
leaq -0x108(%rbp), %rdi
callq 0xab40
jmp 0x12e37
movq -0x360(%rbp), %rax
movl (%rax), %ecx
movl %ecx, -0x3a8(%rbp)
movl 0x4(%rax), %eax
movl %eax, -0x3a4(%rbp)
leaq -0x120(%rbp), %rdi
movsd 0x8532(%rip), %xmm0     # 0x1b390
xorps %xmm1, %xmm1
callq 0x19810
jmp 0x12e68
movl -0x3a4(%rbp), %ecx
movl -0x3a8(%rbp), %edx
movq -0x370(%rbp), %rdi
movsd -0x120(%rbp), %xmm0
movsd -0x118(%rbp), %xmm1
leaq -0x108(%rbp), %rsi
movl $0x4, %r8d
callq 0x19470
jmp 0x12e9f
leaq -0x108(%rbp), %rdi
callq 0x3270
leaq -0x109(%rbp), %rdi
callq 0x3410
movb $0x1, -0xe1(%rbp)
movl $0x1, -0x124(%rbp)
testb $0x1, -0xe1(%rbp)
jne 0x12f83
jmp 0x12f77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x12f0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3270
leaq -0xa1(%rbp), %rdi
callq 0x3410
jmp 0x13256
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x1324d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x12f66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3270
leaq -0x109(%rbp), %rdi
callq 0x3410
jmp 0x1324d
movq -0x370(%rbp), %rdi
callq 0xe650
jmp 0x13236
movsd 0x83f0(%rip), %xmm0     # 0x1b380
movsd %xmm0, -0x130(%rbp)
movsd 0x83e0(%rip), %xmm0     # 0x1b380
movsd %xmm0, -0x138(%rbp)
movl $0x0, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0x13144
movsd -0x138(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movl $0x0, -0x140(%rbp)
movl -0x140(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x13118
movl -0x13c(%rbp), %edx
movl -0x140(%rbp), %ecx
leaq -0x198(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x13fe0
jmp 0x13008
leaq -0x198(%rbp), %rdi
callq 0x147b0
movsd %xmm1, -0x3b8(%rbp)
movsd %xmm0, -0x3b0(%rbp)
jmp 0x13026
movsd -0x3b8(%rbp), %xmm0
movsd -0x3b0(%rbp), %xmm1
movsd %xmm1, -0x160(%rbp)
movsd %xmm0, -0x158(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x19ac0
movsd %xmm1, -0x3c8(%rbp)
movsd %xmm0, -0x3c0(%rbp)
jmp 0x1306b
movsd -0x3c8(%rbp), %xmm0
movsd -0x3c0(%rbp), %xmm1
movsd %xmm1, -0x150(%rbp)
movsd %xmm0, -0x148(%rbp)
movq -0x70(%rbp), %rax
movslq -0x13c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x140(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x150(%rbp), %rcx
movq %rcx, (%rax)
movq -0x148(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x198(%rbp), %rdi
callq 0xe650
movsd 0x82b7(%rip), %xmm0     # 0x1b388
mulsd -0x130(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movl -0x140(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x140(%rbp)
jmp 0x12fdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x198(%rbp), %rdi
callq 0xe650
jmp 0x1324d
movsd 0x8268(%rip), %xmm0     # 0x1b388
mulsd -0x138(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
movl -0x13c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x12fb2
leaq -0x208(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x15b40
jmp 0x13156
leaq -0x1d0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x208(%rbp), %rdx
callq 0x10e80
jmp 0x1316f
leaq -0x1d0(%rbp), %rdi
callq 0xe650
leaq -0x208(%rbp), %rdi
callq 0xe650
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x220(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x19cf0
movsd %xmm1, -0x3d8(%rbp)
movsd %xmm0, -0x3d0(%rbp)
jmp 0x131bd
movsd -0x3d8(%rbp), %xmm0
movsd -0x3d0(%rbp), %xmm1
movsd %xmm1, -0x218(%rbp)
movsd %xmm0, -0x210(%rbp)
movsd -0x218(%rbp), %xmm0
movsd -0x210(%rbp), %xmm1
leaq -0x80(%rbp), %rdi
callq 0x12690
jmp 0x131f8
movq -0x370(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xeff0
jmp 0x1320a
movl $0x1, -0x124(%rbp)
jmp 0x13236
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x208(%rbp), %rdi
callq 0xe650
jmp 0x1324d
leaq -0x80(%rbp), %rdi
callq 0xe650
leaq -0x48(%rbp), %rdi
callq 0xe650
jmp 0x135de
leaq -0x80(%rbp), %rdi
callq 0xe650
leaq -0x48(%rbp), %rdi
callq 0xe650
jmp 0x135ee
movq -0x360(%rbp), %rdi
addq $0x18, %rdi
leaq 0x818f(%rip), %rsi      # 0x1b405
callq 0xaca0
testb $0x1, %al
jne 0x13284
jmp 0x135dc
movq -0x360(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
je 0x132b9
movl $0x8, %edi
callq 0x31c0
movq %rax, %rdi
leaq 0x8248(%rip), %rax      # 0x1b4ee
movq %rax, (%rdi)
movq 0xed18(%rip), %rsi      # 0x21fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x35f0
movq -0x360(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0xec70
movq -0x360(%rbp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq -0x290(%rbp), %rdi
xorl %ecx, %ecx
xorps %xmm0, %xmm0
callq 0xe7c0
jmp 0x132eb
leaq -0x258(%rbp), %rdi
callq 0x143a0
movsd %xmm0, -0x3e0(%rbp)
jmp 0x13301
movsd -0x3e0(%rbp), %xmm0
movsd %xmm0, -0x298(%rbp)
movsd -0x298(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x133b5
jp 0x133b5
movq -0x370(%rbp), %rdi
movq -0x360(%rbp), %rax
movb $0x0, -0x299(%rbp)
movl (%rax), %esi
movl 0x4(%rax), %edx
movl $0x4, %ecx
movsd 0x803d(%rip), %xmm0     # 0x1b390
callq 0xe7c0
jmp 0x1335a
movb $0x1, -0x299(%rbp)
movl $0x1, -0x124(%rbp)
testb $0x1, -0x299(%rbp)
jne 0x133b0
jmp 0x133a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x135ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x135c2
movq -0x370(%rbp), %rdi
callq 0xe650
jmp 0x135a8
movl $0x1, -0x2a0(%rbp)
movl $0x1, -0x2a4(%rbp)
movl $0x0, -0x2a8(%rbp)
movl -0x2a8(%rbp), %eax
cmpl -0x290(%rbp), %eax
jge 0x134f7
movl -0x2a4(%rbp), %eax
movl %eax, -0x2a0(%rbp)
movl $0x0, -0x2ac(%rbp)
movl -0x2ac(%rbp), %eax
cmpl -0x28c(%rbp), %eax
jge 0x134d6
cvtsi2sdl -0x2a0(%rbp), %xmm0
movsd %xmm0, -0x3e8(%rbp)
movl -0x2a8(%rbp), %edx
movl -0x2ac(%rbp), %ecx
leaq -0x2e8(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x13fe0
jmp 0x1343e
leaq -0x2e8(%rbp), %rdi
callq 0x143a0
movsd %xmm0, -0x3f0(%rbp)
jmp 0x13454
movsd -0x3f0(%rbp), %xmm1
movsd -0x3e8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq -0x288(%rbp), %rax
movslq -0x2a8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2ac(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq -0x2e8(%rbp), %rdi
callq 0xe650
imull $-0x1, -0x2a0(%rbp), %eax
movl %eax, -0x2a0(%rbp)
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x133fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0xe650
jmp 0x135c2
imull $-0x1, -0x2a4(%rbp), %eax
movl %eax, -0x2a4(%rbp)
movl -0x2a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a8(%rbp)
jmp 0x133d3
leaq -0x358(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x15b40
jmp 0x1350c
leaq -0x320(%rbp), %rdi
leaq -0x290(%rbp), %rsi
leaq -0x358(%rbp), %rdx
callq 0x10e80
jmp 0x13528
leaq -0x320(%rbp), %rdi
callq 0xe650
leaq -0x358(%rbp), %rdi
callq 0xe650
movsd -0x298(%rbp), %xmm1
movsd 0x7e30(%rip), %xmm0     # 0x1b380
divsd %xmm1, %xmm0
leaq -0x290(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x12610
movq -0x370(%rbp), %rdi
movq -0x3f8(%rbp), %rsi
callq 0xeff0
jmp 0x1357c
movl $0x1, -0x124(%rbp)
jmp 0x135a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x358(%rbp), %rdi
callq 0xe650
jmp 0x135c2
leaq -0x290(%rbp), %rdi
callq 0xe650
leaq -0x258(%rbp), %rdi
callq 0xe650
jmp 0x135de
leaq -0x290(%rbp), %rdi
callq 0xe650
leaq -0x258(%rbp), %rdi
callq 0xe650
jmp 0x135ee
ud2
movq -0x368(%rbp), %rax
addq $0x400, %rsp            # imm = 0x400
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x3630
nopw (%rax,%rax)