// File: SpiritLooper[P]RDV_OBJRender/matrix.cpp
// Function: Matrix::inverse()
Matrix Matrix::inverse() {
    assert(rows==cols);
    // augmenting the square matrix with the identity matrix of the same dimensions a => [ai]
    Matrix result(rows, cols*2);
    for(int i=0; i<rows; i++)
        for(int j=0; j<cols; j++)
            result[i][j] = m[i][j];
    for(int i=0; i<rows; i++)
        result[i][i+cols] = 1;
    // first pass
    for (int i=0; i<rows-1; i++) {
        // normalize the first row
        for(int j=result.cols-1; j>=0; j--)
            result[i][j] /= result[i][i];
        for (int k=i+1; k<rows; k++) {
            float coeff = result[k][i];
            for (int j=0; j<result.cols; j++) {
                result[k][j] -= result[i][j]*coeff;
            }
        }
    }
    // normalize the last row
    for(int j=result.cols-1; j>=rows-1; j--)
        result[rows-1][j] /= result[rows-1][rows-1];
    // second pass
    for (int i=rows-1; i>0; i--) {
        for (int k=i-1; k>=0; k--) {
            float coeff = result[k][i];
            for (int j=0; j<result.cols; j++) {
                result[k][j] -= result[i][j]*coeff;
            }
        }
    }
    // cut the identity matrix back
    Matrix truncate(rows, cols);
    for(int i=0; i<rows; i++)
        for(int j=0; j<cols; j++)
            truncate[i][j] = result[i][j+cols];
    return truncate;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x98(%rbp)
movq %rdi, %rax
movq %rax, -0x90(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movl 0x18(%rcx), %eax
cmpl 0x1c(%rcx), %eax
jne 0x2ba9
jmp 0x2bc8
leaq 0xc4dc(%rip), %rdi      # 0xf08c
leaq 0xc460(%rip), %rsi      # 0xf017
movl $0x33, %edx
leaq 0xc4d4(%rip), %rcx      # 0xf097
callq 0x2160
movq -0x88(%rbp), %rax
movl 0x18(%rax), %esi
movl 0x1c(%rax), %edx
shll %edx
leaq -0x30(%rbp), %rdi
callq 0x2690
movl $0x0, -0x34(%rbp)
movq -0x88(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x2c73
movl $0x0, -0x38(%rbp)
movq -0x88(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x1c(%rcx), %eax
jge 0x2c63
movq -0x88(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x3400
movq %rax, %rdi
movslq -0x38(%rbp), %rsi
callq 0x33c0
movss (%rax), %xmm0
movss %xmm0, -0x9c(%rbp)
movl -0x34(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x38(%rbp), %rsi
callq 0x33c0
movss -0x9c(%rbp), %xmm0
movss %xmm0, (%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2bfd
jmp 0x2c65
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2be7
movl $0x0, -0x3c(%rbp)
movq -0x88(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x2cc4
movl -0x3c(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq -0x88(%rbp), %rcx
movq %rax, %rdi
movl -0x3c(%rbp), %eax
addl 0x1c(%rcx), %eax
movslq %eax, %rsi
callq 0x33c0
movss 0xc34f(%rip), %xmm0     # 0xf004
movss %xmm0, (%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2c7a
movl $0x0, -0x40(%rbp)
movq -0x88(%rbp), %rcx
movl -0x40(%rbp), %eax
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2e42
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x2d4d
movl -0x40(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x40(%rbp), %rsi
callq 0x33c0
movss (%rax), %xmm0
movss %xmm0, -0xa0(%rbp)
movl -0x40(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x44(%rbp), %rsi
callq 0x33c0
movss -0xa0(%rbp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2cec
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x88(%rbp), %rcx
movl -0x48(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x2e32
movl -0x48(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x40(%rbp), %rsi
callq 0x33c0
movss (%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2e22
movl -0x40(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x50(%rbp), %rsi
callq 0x33c0
movss (%rax), %xmm0
movss %xmm0, -0xa8(%rbp)
movss -0x4c(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movl -0x48(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x50(%rbp), %rsi
callq 0x33c0
movss -0xa8(%rbp), %xmm0
movss -0xa4(%rbp), %xmm2
movss (%rax), %xmm1
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2d91
jmp 0x2e24
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2d56
jmp 0x2e34
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2ccb
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x88(%rbp), %rcx
movl -0x54(%rbp), %eax
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x2ee4
movq -0x88(%rbp), %rax
movl 0x18(%rax), %esi
subl $0x1, %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movq -0x88(%rbp), %rax
movl 0x18(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x33c0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movss (%rcx), %xmm0
movss %xmm0, -0xac(%rbp)
movl 0x18(%rax), %esi
subl $0x1, %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x33c0
movss -0xac(%rbp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x2e4b
movq -0x88(%rbp), %rax
movl 0x18(%rax), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jle 0x2fea
movl -0x58(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x2fda
movl -0x5c(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x33c0
movss (%rax), %xmm0
movss %xmm0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2fca
movl -0x58(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x33c0
movss (%rax), %xmm0
movss %xmm0, -0xb4(%rbp)
movss -0x60(%rbp), %xmm0
movss %xmm0, -0xb0(%rbp)
movl -0x5c(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x33c0
movss -0xb4(%rbp), %xmm0
movss -0xb0(%rbp), %xmm2
movss (%rax), %xmm1
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2f39
jmp 0x2fcc
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x2f07
jmp 0x2fdc
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2ef4
movq -0x98(%rbp), %rdi
movq -0x88(%rbp), %rax
movb $0x0, -0x65(%rbp)
movl 0x18(%rax), %esi
movl 0x1c(%rax), %edx
callq 0x2690
jmp 0x3009
movl $0x0, -0x78(%rbp)
movq -0x88(%rbp), %rcx
movl -0x78(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x30c2
movl $0x0, -0x7c(%rbp)
movq -0x88(%rbp), %rcx
movl -0x7c(%rbp), %eax
cmpl 0x1c(%rcx), %eax
jge 0x30b2
movl -0x78(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x2890
movq -0x88(%rbp), %rcx
movq %rax, %rdi
movl -0x7c(%rbp), %eax
addl 0x1c(%rcx), %eax
movslq %eax, %rsi
callq 0x33c0
movq -0x98(%rbp), %rdi
movss (%rax), %xmm0
movss %xmm0, -0xb8(%rbp)
movl -0x78(%rbp), %esi
callq 0x2890
movq %rax, %rdi
movslq -0x7c(%rbp), %rsi
callq 0x33c0
movss -0xb8(%rbp), %xmm0
movss %xmm0, (%rax)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x302a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x33e0
jmp 0x30f1
jmp 0x30b4
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x3010
movb $0x1, -0x65(%rbp)
testb $0x1, -0x65(%rbp)
jne 0x30d8
movq -0x98(%rbp), %rdi
callq 0x33e0
leaq -0x30(%rbp), %rdi
callq 0x33e0
movq -0x90(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x2380
nopw (%rax,%rax)