// File: /workspace/github_cpp_makefile_star2_O1/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, 0x1ae1c(%rip)     # 0x493d8
jne 0x2e6bc
pushq %r14
pushq %rbx
subq $0x58, %rsp
movslq 0x58(%rdi), %rax
leaq (%rax,%rax,4), %rax
leaq 0x1b82e28(%rip), %rcx   # 0x1bb1400
leaq (%rcx,%rax,4), %rdi
movswq 0xa(%rdi), %rax
leaq (%rax,%rax,4), %rbx
leaq 0x1182e04(%rip), %r14   # 0x11b13f0
callq 0x303c5
movss (%rax), %xmm2
movss 0x4(%rax), %xmm1
movss 0x8(%rax), %xmm0
shufps $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movss (%r14,%rbx,8), %xmm6
movss 0x4(%r14,%rbx,8), %xmm7
movss 0x8(%r14,%rbx,8), %xmm5
movss 0x10(%r14,%rbx,8), %xmm3
unpcklps %xmm3, %xmm6            # xmm6 = xmm6[0],xmm3[0],xmm6[1],xmm3[1]
movss 0x14(%r14,%rbx,8), %xmm3
unpcklps %xmm3, %xmm7            # xmm7 = xmm7[0],xmm3[0],xmm7[1],xmm3[1]
movaps %xmm1, %xmm3
mulps %xmm7, %xmm3
movaps %xmm2, %xmm4
mulps %xmm6, %xmm4
addps %xmm3, %xmm4
movss 0x18(%r14,%rbx,8), %xmm3
unpcklps %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0],xmm5[1],xmm3[1]
movaps %xmm0, %xmm3
mulps %xmm5, %xmm3
addps %xmm4, %xmm3
mulps %xmm3, %xmm2
subps %xmm2, %xmm6
mulps %xmm3, %xmm1
subps %xmm1, %xmm7
mulps %xmm0, %xmm3
subps %xmm3, %xmm5
movaps %xmm6, %xmm0
movlhps %xmm7, %xmm0            # xmm0 = xmm0[0],xmm7[0]
movaps %xmm7, %xmm2
shufps $0x55, %xmm7, %xmm2     # xmm2 = xmm2[1,1],xmm7[1,1]
movaps %xmm5, %xmm1
shufps $0xd4, %xmm6, %xmm1     # xmm1 = xmm1[0,1],xmm6[1,3]
movaps %xmm6, %xmm4
shufps $0x55, %xmm6, %xmm4     # xmm4 = xmm4[1,1],xmm6[1,1]
shufps $0x88, %xmm1, %xmm0     # xmm0 = xmm0[0,2],xmm1[0,2]
mulps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movaps %xmm5, %xmm0
mulss %xmm5, %xmm0
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
addsd %xmm1, %xmm3
xorps %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jb 0x2e6c5
xorps %xmm1, %xmm1
sqrtsd %xmm3, %xmm1
jmp 0x2e70e
movss 0x9a74(%rip), %xmm0     # 0x38138
retq
movapd %xmm3, %xmm0
movaps %xmm5, (%rsp)
movaps %xmm6, 0x10(%rsp)
movaps %xmm7, 0x40(%rsp)
movaps %xmm2, 0x30(%rsp)
movaps %xmm4, 0x20(%rsp)
movsd %xmm3, 0x50(%rsp)
callq 0x4240
movsd 0x50(%rsp), %xmm3
movaps 0x20(%rsp), %xmm4
movaps 0x30(%rsp), %xmm2
movaps 0x40(%rsp), %xmm7
movaps 0x10(%rsp), %xmm6
movaps (%rsp), %xmm5
movapd %xmm0, %xmm1
movsd 0x99fa(%rip), %xmm0     # 0x38110
ucomisd %xmm1, %xmm0
ja 0x2e768
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jb 0x2e72f
xorps %xmm0, %xmm0
sqrtsd %xmm3, %xmm0
jmp 0x2e768
movapd %xmm3, %xmm0
movaps %xmm5, (%rsp)
movaps %xmm6, 0x10(%rsp)
movaps %xmm7, 0x40(%rsp)
movaps %xmm2, 0x30(%rsp)
movaps %xmm4, 0x20(%rsp)
callq 0x4240
movaps 0x20(%rsp), %xmm4
movaps 0x30(%rsp), %xmm2
movaps 0x40(%rsp), %xmm7
movaps 0x10(%rsp), %xmm6
movaps (%rsp), %xmm5
movsd 0xc9f8(%rip), %xmm3     # 0x3b168
movapd %xmm3, %xmm8
divsd %xmm0, %xmm8
unpcklps %xmm7, %xmm6            # xmm6 = xmm6[0],xmm7[0],xmm6[1],xmm7[1]
movaps %xmm5, %xmm0
unpcklps %xmm4, %xmm0            # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movlhps %xmm0, %xmm6            # xmm6 = xmm6[0],xmm0[0]
mulps %xmm6, %xmm6
mulps %xmm2, %xmm2
shufps $0x30, %xmm6, %xmm2     # xmm2 = xmm2[0,0],xmm6[3,0]
shufps $0xe2, %xmm6, %xmm2     # xmm2 = xmm2[2,0],xmm6[2,3]
cvtps2pd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
mulss %xmm5, %xmm5
xorps %xmm4, %xmm4
cvtss2sd %xmm5, %xmm4
addsd %xmm1, %xmm4
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm4
jb 0x2e7c9
xorps %xmm1, %xmm1
sqrtsd %xmm4, %xmm1
jmp 0x2e7f6
movapd %xmm4, %xmm0
movsd %xmm8, (%rsp)
movsd %xmm4, 0x10(%rsp)
callq 0x4240
movsd 0x10(%rsp), %xmm4
movsd (%rsp), %xmm8
movsd 0xc976(%rip), %xmm3     # 0x3b168
movapd %xmm0, %xmm1
xorps %xmm2, %xmm2
cvtsd2ss %xmm8, %xmm2
movsd 0x990a(%rip), %xmm0     # 0x38110
ucomisd %xmm1, %xmm0
ja 0x2e83a
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm4
jb 0x2e81f
xorps %xmm0, %xmm0
sqrtsd %xmm4, %xmm0
jmp 0x2e83a
movapd %xmm4, %xmm0
movss %xmm2, (%rsp)
callq 0x4240
movss (%rsp), %xmm2
movsd 0xc92e(%rip), %xmm3     # 0x3b168
divsd %xmm0, %xmm3
xorps %xmm0, %xmm0
cvtsd2ss %xmm3, %xmm0
mulss %xmm0, %xmm2
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
leaq 0x58(%rsp), %rsp
popq %rbx
popq %r14
jb 0x2e861
xorps %xmm0, %xmm0
sqrtss %xmm2, %xmm0
retq
movaps %xmm2, %xmm0
jmp 0x45c0