// File: /workspace/github_cpp_makefile_star2_O3/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, 0x1ac94(%rip)     # 0x483d8
jne 0x2d887
pushq %r14
pushq %rbx
subq $0x18, %rsp
movslq %edi, %rax
leaq (%rax,%rax,4), %rax
leaq 0x1b82ca1(%rip), %rcx   # 0x1bb0400
leaq (%rcx,%rax,4), %rdi
movswq 0xa(%rdi), %rax
leaq (%rax,%rax,4), %rbx
shlq $0x3, %rbx
addq 0x197f9(%rip), %rbx     # 0x46f70
leaq 0xc(%rsp), %r14
callq 0x2f342
movsd (%rax), %xmm0
movss 0x8(%rax), %xmm1
movq %rsp, %rcx
movb $0x1, %al
xorl %edx, %edx
shlq $0x4, %rdx
movss 0x8(%rbx,%rdx), %xmm2
movsd (%rbx,%rdx), %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, (%rcx)
mulss %xmm1, %xmm4
subss %xmm4, %xmm2
movss %xmm2, 0x8(%rcx)
movl $0x1, %edx
movq %r14, %rcx
testb $0x1, %al
movl $0x0, %eax
jne 0x2d791
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 0xdd18(%rip), %xmm1     # 0x3b560
divpd %xmm0, %xmm1
cmpltpd 0xe43b(%rip), %xmm0     # 0x3bc90
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd 0xe43b(%rip), %xmm0     # 0x3bca0
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 0x2d890
sqrtss %xmm0, %xmm0
jmp 0x2d895
movss 0x9815(%rip), %xmm0     # 0x370a4
retq
callq 0x45b0
addq $0x18, %rsp
popq %rbx
popq %r14
retq