// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: getScale(patch_s const*)
static vec_t    getScale(const patch_t* const patch)
{
    dface_t*        f = g_dfaces + patch->faceNumber;
    texinfo_t*      tx = &g_texinfo[f->texinfo];

    if (g_texscale)
    {
#ifdef ZHLT_FREETEXTUREAXIS
		const dplane_t*	faceplane = getPlaneFromFace (f);
		vec3_t			vecs_perpendicular[2];
		vec_t			scale[2];
		vec_t			dot;
		
		// snap texture "vecs" to faceplane without affecting texture alignment
		for (int x = 0; x < 2; x++)
		{
			dot = DotProduct (faceplane->normal, tx->vecs[x]);
			VectorMA (tx->vecs[x], -dot, faceplane->normal, vecs_perpendicular[x]);
		}
		
		scale[0] = 1 / qmax (NORMAL_EPSILON, VectorLength (vecs_perpendicular[0]));
		scale[1] = 1 / qmax (NORMAL_EPSILON, VectorLength (vecs_perpendicular[1]));

		// don't care about the angle between vecs[0] and vecs[1] (given the length of "vecs", smaller angle = larger texel area), because gridplanes will have the same angle (also smaller angle = larger patch area)

		return sqrt (scale[0] * scale[1]);
#else
        vec_t           scale[2];

        scale[0] = 0.0;
        scale[1] = 0.0;

        scale[0] += tx->vecs[0][0] * tx->vecs[0][0];
        scale[0] += tx->vecs[0][1] * tx->vecs[0][1];
        scale[0] += tx->vecs[0][2] * tx->vecs[0][2];

        scale[1] += tx->vecs[1][0] * tx->vecs[1][0];
        scale[1] += tx->vecs[1][1] * tx->vecs[1][1];
        scale[1] += tx->vecs[1][2] * tx->vecs[1][2];

        scale[0] = sqrt(scale[0]);
        scale[1] = sqrt(scale[1]);

        return 2.0 / ((scale[0] + scale[1]));
#endif
    }
    else
    {
        return 1.0;
    }
}

// Assembly:
cmpb $0x1, 0x1b64f(%rip)     # 0x453e8
jne 0x29e37
pushq %rbx
subq $0x20, %rsp
movslq 0x58(%rdi), %rax
imulq $0x14, %rax, %rax
leaq 0x1b8365d(%rip), %rcx   # 0x1bad410
leaq (%rcx,%rax), %rdi
movswq 0xa(%rcx,%rax), %rbx
callq 0x2b6a1
movsd (%rax), %xmm0
movss 0x8(%rax), %xmm1
imulq $0x28, %rbx, %rax
leaq 0x118362a(%rip), %rcx   # 0x11ad400
addq %rcx, %rax
addq $0x8, %rax
pushq $0x8
popq %rcx
cmpq $0x20, %rcx
je 0x29e40
movss (%rax), %xmm2
movsd -0x8(%rax), %xmm3
movaps %xmm0, %xmm4
mulps %xmm3, %xmm4
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
movaps %xmm0, %xmm5
mulss %xmm3, %xmm5
addss %xmm4, %xmm5
movaps %xmm1, %xmm4
mulss %xmm2, %xmm4
addss %xmm5, %xmm4
movaps %xmm4, %xmm5
unpcklps %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0],xmm5[1],xmm4[1]
mulps %xmm0, %xmm5
subps %xmm5, %xmm3
movlps %xmm3, -0x8(%rsp,%rcx)
mulss %xmm1, %xmm4
subss %xmm4, %xmm2
movss %xmm2, (%rsp,%rcx)
addq $0xc, %rcx
addq $0x10, %rax
jmp 0x29de0
movss 0x8225(%rip), %xmm0     # 0x32064
retq
movaps (%rsp), %xmm0
movups 0x4(%rsp), %xmm1
movss 0xc(%rsp), %xmm2
movlhps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
shufps $0xe2, %xmm0, %xmm2     # xmm2 = xmm2[2,0],xmm0[2,3]
mulps %xmm2, %xmm2
cvtps2pd %xmm2, %xmm0
movss 0x10(%rsp), %xmm2
movlhps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
shufps $0xe2, %xmm1, %xmm2     # xmm2 = xmm2[2,0],xmm1[2,3]
mulps %xmm2, %xmm2
cvtps2pd %xmm2, %xmm1
movups 0x8(%rsp), %xmm2
addpd %xmm0, %xmm1
movss 0x14(%rsp), %xmm0
movlhps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
shufps $0xe2, %xmm2, %xmm0     # xmm0 = xmm0[2,0],xmm2[2,3]
mulps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
addpd %xmm1, %xmm0
sqrtpd %xmm0, %xmm0
movapd 0xc6b5(%rip), %xmm1     # 0x36550
divpd %xmm0, %xmm1
cmpltpd 0xcdb8(%rip), %xmm0     # 0x36c60
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd 0xcdb8(%rip), %xmm0     # 0x36c70
orpd %xmm2, %xmm0
cvtpd2ps %xmm0, %xmm1
movapd %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
mulss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x29eda
sqrtss %xmm0, %xmm0
jmp 0x29edf
callq 0x45c0
addq $0x20, %rsp
popq %rbx
retq