// File: FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: getGridPlanes(patch_s const*, dplane_t*)
static void     getGridPlanes(const patch_t* const p, dplane_t* const pl)
{
    const patch_t*  patch = p;
    dplane_t*       planes = pl;
    const dface_t*  f = g_dfaces + patch->faceNumber;
    texinfo_t*      tx = &g_texinfo[f->texinfo];
    dplane_t*       plane = planes;
    const dplane_t* faceplane = getPlaneFromFaceNumber(patch->faceNumber);
    int             x;

    for (x = 0; x < 2; x++, plane++)
    {
#ifdef ZHLT_FREETEXTUREAXIS
		// cut the patch along texel grid planes
		vec_t			val;
		val = DotProduct (faceplane->normal, tx->vecs[!x]);
		VectorMA (tx->vecs[!x], -val, faceplane->normal, plane->normal);
#else
        vec3_t          a, b, c;
        vec3_t          delta1, delta2;

        VectorCopy(patch->origin, a);
        VectorAdd(patch->origin, faceplane->normal, b);
        VectorAdd(patch->origin, tx->vecs[x], c);

        VectorSubtract(b, a, delta1);
        VectorSubtract(c, a, delta2);

        CrossProduct(delta1, delta2, plane->normal);
#endif
        VectorNormalize(plane->normal);
        plane->dist = DotProduct(plane->normal, patch->origin);
    }
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movslq 0x58(%rax), %rcx
leaq 0x1b8df3e(%rip), %rax   # 0x1be6410
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movswq 0xa(%rax), %rcx
leaq 0x118df11(%rip), %rax   # 0x11e6400
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movl 0x58(%rax), %edi
callq 0x5ce10
movq %rax, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
cmpl $0x2, 0x4(%rsp)
jge 0x5872b
movq 0x8(%rsp), %rax
movss (%rax), %xmm1
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss (%rax), %xmm2
movq 0x8(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
mulss 0x4(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x8(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rsp)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss (%rax), %xmm1
movss (%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq 0x8(%rsp), %rax
movss (%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x4(%rax), %xmm1
movss (%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq 0x8(%rsp), %rax
movss 0x4(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, 0x4(%rax)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm1
movss (%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq 0x8(%rsp), %rax
movss 0x8(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, 0x8(%rax)
movq 0x10(%rsp), %rdi
callq 0x11980
movq 0x10(%rsp), %rax
movss (%rax), %xmm1
movq 0x30(%rsp), %rax
movss 0x8(%rax), %xmm2
movq 0x10(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x30(%rsp), %rax
mulss 0xc(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x10(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x30(%rsp), %rax
movss 0x10(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, 0xc(%rax)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rax
addq $0x14, %rax
movq %rax, 0x10(%rsp)
jmp 0x5851f
addq $0x48, %rsp
retq