// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlrad/qradutil.cpp
// Function: InvertMatrix(matrix_t const&, matrix_t&)
bool InvertMatrix (const matrix_t &m, matrix_t &m_inverse)
{
	double texplanes[2][4];
	double faceplane[4];
	int i;
	double texaxis[2][3];
	double normalaxis[3];
	double det, sqrlen1, sqrlen2, sqrlen3;
	double texorg[3];

	for (i = 0; i < 4; i++)
	{
		texplanes[0][i] = m.v[i][0];
		texplanes[1][i] = m.v[i][1];
		faceplane[i] = m.v[i][2];
	}

	sqrlen1 = DotProduct (texplanes[0], texplanes[0]);
	sqrlen2 = DotProduct (texplanes[1], texplanes[1]);
	sqrlen3 = DotProduct (faceplane, faceplane);
	if (sqrlen1 <= NORMAL_EPSILON * NORMAL_EPSILON || sqrlen2 <= NORMAL_EPSILON * NORMAL_EPSILON || sqrlen3 <= NORMAL_EPSILON * NORMAL_EPSILON)
		// s gradient, t gradient or face normal is too close to 0
	{
		return false;
	}

	CrossProduct (texplanes[0], texplanes[1], normalaxis);
	det = DotProduct (normalaxis, faceplane);
	if (det * det <= sqrlen1 * sqrlen2 * sqrlen3 * NORMAL_EPSILON * NORMAL_EPSILON)
		// s gradient, t gradient and face normal are coplanar
	{
		return false;
	}
	VectorScale (normalaxis, 1 / det, normalaxis);

	CrossProduct (texplanes[1], faceplane, texaxis[0]);
	VectorScale (texaxis[0], 1 / det, texaxis[0]);

	CrossProduct (faceplane, texplanes[0], texaxis[1]);
	VectorScale (texaxis[1], 1 / det, texaxis[1]);

	VectorScale (normalaxis, -faceplane[3], texorg);
	VectorMA (texorg, -texplanes[0][3], texaxis[0], texorg);
	VectorMA (texorg, -texplanes[1][3], texaxis[1], texorg);
	
	VectorCopy (texaxis[0], m_inverse.v[0]);
	VectorCopy (texaxis[1], m_inverse.v[1]);
	VectorCopy (normalaxis, m_inverse.v[2]);
	VectorCopy (texorg, m_inverse.v[3]);
	return true;
}

// Assembly:
addq $0x8, %rdi
xorl %eax, %eax
cmpq $0x4, %rax
je 0x2bf3e
cvtss2sd -0x8(%rdi), %xmm0
movsd %xmm0, -0x48(%rsp,%rax,8)
cvtss2sd -0x4(%rdi), %xmm0
movsd %xmm0, -0x28(%rsp,%rax,8)
cvtss2sd (%rdi), %xmm0
movsd %xmm0, -0x68(%rsp,%rax,8)
incq %rax
addq $0xc, %rdi
jmp 0x2bf0f
movapd -0x48(%rsp), %xmm2
movapd %xmm2, %xmm8
unpckhpd %xmm2, %xmm8            # xmm8 = xmm8[1],xmm2[1]
movapd %xmm8, %xmm0
mulsd %xmm8, %xmm0
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x38(%rsp), %xmm12
movapd %xmm12, %xmm7
mulsd %xmm12, %xmm7
addsd %xmm1, %xmm7
xorl %eax, %eax
movsd 0xd885(%rip), %xmm0     # 0x39808
ucomisd %xmm7, %xmm0
jae 0x2c1de
movapd -0x28(%rsp), %xmm5
movsd -0x18(%rsp), %xmm0
movapd -0x68(%rsp), %xmm4
movsd -0x58(%rsp), %xmm6
movapd %xmm4, %xmm1
unpckhpd %xmm5, %xmm1            # xmm1 = xmm1[1],xmm5[1]
mulpd %xmm1, %xmm1
movapd %xmm4, %xmm3
unpcklpd %xmm5, %xmm3            # xmm3 = xmm3[0],xmm5[0]
mulpd %xmm3, %xmm3
addpd %xmm1, %xmm3
movapd %xmm6, %xmm10
unpcklpd %xmm0, %xmm10           # xmm10 = xmm10[0],xmm0[0]
mulpd %xmm10, %xmm10
addpd %xmm3, %xmm10
movapd %xmm10, %xmm1
cmplepd 0xd84d(%rip), %xmm1     # 0x39830
movmskpd %xmm1, %ecx
movl %ecx, %edx
shrb %dl
jne 0x2c1de
testb $0x1, %cl
jne 0x2c1de
movapd %xmm5, %xmm1
unpckhpd %xmm5, %xmm1            # xmm1 = xmm1[1],xmm5[1]
movapd %xmm12, %xmm11
unpcklpd %xmm2, %xmm11           # xmm11 = xmm11[0],xmm2[0]
movapd %xmm5, %xmm9
shufpd $0x1, %xmm0, %xmm9      # xmm9 = xmm9[1],xmm0[0]
movapd %xmm9, %xmm13
mulpd %xmm11, %xmm13
movapd %xmm2, %xmm3
shufpd $0x1, %xmm5, %xmm3      # xmm3 = xmm3[1],xmm5[0]
unpcklpd %xmm12, %xmm0           # xmm0 = xmm0[0],xmm12[0]
mulpd %xmm0, %xmm3
subpd %xmm13, %xmm3
mulsd %xmm5, %xmm8
mulsd %xmm2, %xmm1
subsd %xmm8, %xmm1
movapd %xmm3, %xmm8
mulpd %xmm4, %xmm8
unpckhpd %xmm8, %xmm8            # xmm8 = xmm8[1,1]
movapd %xmm3, %xmm12
mulsd %xmm4, %xmm12
addsd %xmm8, %xmm12
movapd %xmm1, %xmm8
mulsd %xmm6, %xmm8
addsd %xmm12, %xmm8
movapd %xmm8, %xmm12
mulsd %xmm8, %xmm12
movapd %xmm10, %xmm13
unpckhpd %xmm10, %xmm13          # xmm13 = xmm13[1],xmm10[1]
mulsd %xmm13, %xmm7
mulsd %xmm10, %xmm7
movsd 0x5fe6(%rip), %xmm10    # 0x32080
mulsd %xmm10, %xmm7
mulsd %xmm10, %xmm7
ucomisd %xmm12, %xmm7
jae 0x2c1df
movsd 0x9010(%rip), %xmm12    # 0x350c8
divsd %xmm8, %xmm12
mulsd %xmm12, %xmm1
movapd %xmm5, %xmm10
unpcklpd %xmm6, %xmm10           # xmm10 = xmm10[0],xmm6[0]
mulpd %xmm4, %xmm11
movapd %xmm6, %xmm7
unpcklpd %xmm4, %xmm7            # xmm7 = xmm7[0],xmm4[0]
mulpd %xmm2, %xmm7
subpd %xmm11, %xmm7
movsd -0x50(%rsp), %xmm13
movapd %xmm1, %xmm14
mulsd %xmm13, %xmm14
movq -0x30(%rsp), %xmm8
pxor 0xa41d(%rip), %xmm8     # 0x36520
movsd -0x10(%rsp), %xmm11
movsd %xmm6, %xmm2            # xmm2 = xmm6[0],xmm2[1]
mulpd %xmm10, %xmm2
mulpd %xmm4, %xmm9
movapd %xmm4, %xmm10
shufpd $0x1, %xmm6, %xmm10     # xmm10 = xmm10[1],xmm6[0]
mulpd %xmm5, %xmm10
subpd %xmm9, %xmm10
mulpd %xmm4, %xmm0
subpd %xmm2, %xmm0
unpcklpd %xmm12, %xmm12          # xmm12 = xmm12[0,0]
mulpd %xmm12, %xmm0
mulpd %xmm12, %xmm10
pshufd $0x44, %xmm8, %xmm2     # xmm2 = xmm8[0,1,0,1]
mulsd %xmm10, %xmm8
cvtpd2ps %xmm0, %xmm4
subsd %xmm14, %xmm8
cvtpd2ps %xmm10, %xmm5
shufps $0x41, %xmm4, %xmm5     # xmm5 = xmm5[1,0],xmm4[0,1]
shufps $0xd8, %xmm5, %xmm5     # xmm5 = xmm5[0,2,1,3]
movups %xmm5, (%rsi)
mulpd %xmm12, %xmm7
mulpd %xmm12, %xmm3
unpcklpd %xmm13, %xmm13          # xmm13 = xmm13[0,0]
mulpd %xmm3, %xmm13
shufpd $0x1, %xmm0, %xmm10     # xmm10 = xmm10[1],xmm0[0]
mulpd %xmm2, %xmm10
subpd %xmm13, %xmm10
shufpd $0x1, %xmm7, %xmm0      # xmm0 = xmm0[1],xmm7[0]
cvtpd2ps %xmm7, %xmm2
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
mulsd %xmm11, %xmm7
unpcklpd %xmm11, %xmm11          # xmm11 = xmm11[0,0]
mulpd %xmm11, %xmm0
subpd %xmm0, %xmm10
cvtpd2ps %xmm3, %xmm0
subsd %xmm7, %xmm8
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
unpcklpd %xmm10, %xmm1           # xmm1 = xmm1[0],xmm10[0]
shufpd $0x1, %xmm8, %xmm10     # xmm10 = xmm10[1],xmm8[0]
cvtpd2ps %xmm1, %xmm0
cvtpd2ps %xmm10, %xmm1
movupd %xmm2, 0x10(%rsi)
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movupd %xmm0, 0x20(%rsi)
movb $0x1, %al
retq
xorl %eax, %eax
retq