// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl 0x18(%rsi), %esi
cmpl 0x1c(%r14), %esi
jne 0x2c2e
movq %rdi, %rbx
leal (%rsi,%rsi), %edx
leaq 0x8(%rsp), %rdi
callq 0x25ec
movl 0x18(%r14), %esi
movl %esi, %eax
testl %esi, %esi
jle 0x2a8a
movl 0x1c(%r14), %ecx
xorl %edx, %edx
testl %ecx, %ecx
jle 0x2932
leaq (,%rdx,8), %rdi
leaq (%rdi,%rdi,2), %rdi
movq (%r14), %r8
addq %rdi, %r8
addq 0x8(%rsp), %rdi
xorl %r9d, %r9d
movslq 0x20(%rsp), %r10
cmpq %r10, %rdx
jge 0x2c0f
movq (%r8), %r10
movss (%r10,%r9,4), %xmm0
movq (%rdi), %r10
movss %xmm0, (%r10,%r9,4)
incq %r9
cmpq %r9, %rcx
jne 0x290a
incq %rdx
cmpq %rax, %rdx
jne 0x28ec
testl %esi, %esi
jle 0x2a8a
movq 0x8(%rsp), %rcx
movslq 0x1c(%r14), %rdx
shlq $0x2, %rdx
xorl %edi, %edi
movslq 0x20(%rsp), %r8
cmpq %r8, %rdi
jge 0x2c0f
movq (%rcx), %r8
addq %rdx, %r8
movl $0x3f800000, (%r8,%rdi,4) # imm = 0x3F800000
incq %rdi
addq $0x18, %rcx
cmpq %rdi, %rax
jne 0x2951
leal -0x1(%rsi), %r10d
cmpl $0x1, %esi
setne %cl
je 0x2a8e
movl %ecx, 0x28(%rsp)
movl 0x24(%rsp), %ecx
movl %r10d, 0x2c(%rsp)
movl %r10d, %r8d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x30(%rsp)
movl $0x1, %r10d
xorl %r11d, %r11d
leaq (%r11,%r11,2), %r13
testl %ecx, %ecx
jle 0x29f3
leaq (,%r13,8), %rdx
addq 0x8(%rsp), %rdx
movq 0x30(%rsp), %rdi
movslq 0x20(%rsp), %r9
cmpq %r9, %r11
jge 0x2c0f
movq (%rdx), %r9
movss -0x8(%r9,%rdi,4), %xmm0
divss (%r9,%r11,4), %xmm0
movss %xmm0, -0x8(%r9,%rdi,4)
decq %rdi
cmpq $0x1, %rdi
jg 0x29c5
leaq 0x1(%r11), %r15
movq 0x8(%rsp), %r12
leaq (%r12,%r13,8), %r13
movq %r10, %rbp
movslq 0x20(%rsp), %rdx
cmpq %rdx, %rbp
jge 0x2c0f
testl %ecx, %ecx
jle 0x2a67
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
movq (%r12,%rdx,8), %rdx
movss (%rdx,%r11,4), %xmm0
xorl %edi, %edi
movslq 0x20(%rsp), %r9
cmpq %r9, %r11
jge 0x2c0f
cmpq %r9, %rbp
jge 0x2c0f
movq (%r13), %r9
movss (%rdx,%rdi,4), %xmm1
movss (%r9,%rdi,4), %xmm2
mulss %xmm0, %xmm2
subss %xmm2, %xmm1
movss %xmm1, (%rdx,%rdi,4)
incq %rdi
cmpq %rdi, %rcx
jne 0x2a2c
incq %rbp
cmpq %rax, %rbp
jne 0x2a03
incq %r10
movq %r15, %r11
cmpq %r8, %r15
jne 0x29ab
movl 0x2c(%rsp), %r10d
movl 0x28(%rsp), %r11d
jmp 0x2a95
leal -0x1(%rsi), %r10d
movl 0x24(%rsp), %ecx
xorl %r11d, %r11d
cmpl %esi, %ecx
jl 0x2ae0
testl %esi, %esi
jle 0x2c0f
movl %r10d, %r8d
leaq (%r8,%r8,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rsp), %rdx
movslq %ecx, %rdi
incq %rdi
cmpl %esi, 0x20(%rsp)
jl 0x2c0f
movq (%rdx), %r9
movss -0x8(%r9,%rdi,4), %xmm0
divss (%r9,%r8,4), %xmm0
movss %xmm0, -0x8(%r9,%rdi,4)
decq %rdi
cmpq %rax, %rdi
jg 0x2ab7
testb %r11b, %r11b
je 0x2b7a
movl %r10d, %eax
movl %ecx, %edx
movq 0x8(%rsp), %rdi
leaq (%rax,%rax,2), %r8
leaq (%rdi,%r8,8), %r8
movq %rax, %r9
cmpl %r9d, 0x20(%rsp)
jl 0x2c0f
movl %r9d, %r10d
decq %r9
testl %ecx, %ecx
jle 0x2b63
movl %r9d, %r11d
leaq (%r11,%r11,2), %r11
movq (%rdi,%r11,8), %r11
movss (%r11,%rax,4), %xmm0
xorl %r15d, %r15d
movslq 0x20(%rsp), %r12
cmpq %r12, %rax
jge 0x2c0f
cmpl %r10d, %r12d
jl 0x2c0f
movq (%r8), %r12
movss (%r11,%r15,4), %xmm1
movss (%r12,%r15,4), %xmm2
mulss %xmm0, %xmm2
subss %xmm2, %xmm1
movss %xmm1, (%r11,%r15,4)
incq %r15
cmpq %r15, %rdx
jne 0x2b27
cmpl $0x1, %r10d
jg 0x2afe
leaq -0x1(%rax), %rdi
cmpq $0x1, %rax
movq %rdi, %rax
jg 0x2aee
movl 0x1c(%r14), %edx
movq %rbx, %rdi
callq 0x25ec
movslq 0x18(%r14), %rax
testq %rax, %rax
jle 0x2bf3
movl 0x1c(%r14), %ecx
movq %rcx, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
testl %ecx, %ecx
jle 0x2beb
leaq (,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
movq 0x8(%rsp), %r8
addq %rdi, %r8
addq (%rbx), %rdi
xorl %r9d, %r9d
movslq 0x20(%rsp), %r10
cmpq %r10, %rsi
jge 0x2c0f
movslq 0x18(%rbx), %r10
cmpq %r10, %rsi
jge 0x2c0f
movq (%r8), %r10
addq %rdx, %r10
movss (%r9,%r10), %xmm0
movq (%rdi), %r10
movss %xmm0, (%r10,%r9)
addq $0x4, %r9
cmpq %r9, %rdx
jne 0x2bba
incq %rsi
cmpq %rax, %rsi
jne 0x2b9c
leaq 0x8(%rsp), %rdi
callq 0x2f62
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x442e(%rip), %rdi      # 0x7044
leaq 0x4436(%rip), %rsi      # 0x7053
leaq 0x443a(%rip), %rcx      # 0x705e
movl $0x18, %edx
callq 0x2110
leaq 0x4493(%rip), %rdi      # 0x70c8
leaq 0x4417(%rip), %rsi      # 0x7053
leaq 0x4490(%rip), %rcx      # 0x70d3
movl $0x33, %edx
callq 0x2110
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2f62
movq %rbx, %rdi
callq 0x22d0