// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/mathutil.cpp
// Function: snap_to_winding(Winding const&, dplane_t const&, float*)
void			snap_to_winding(const Winding& w, const dplane_t& plane, vec_t* const point)
{
	int				numpoints;
	int				x;
	vec_t			*p1, *p2;
	vec3_t			delta;
	vec3_t			normal;
	vec_t			dist;
	vec_t			dot1, dot2, dot;
	vec3_t			bestpoint;
	vec_t			bestdist;
	bool			in;

	numpoints = w.m_NumPoints;

	in = true;
	for (x = 0; x < numpoints; x++)
	{
		p1 = w.m_Points[x];
		p2 = w.m_Points[(x + 1) % numpoints];
		VectorSubtract (p2, p1, delta);
		CrossProduct (delta, plane.normal, normal);
		dist = DotProduct (point, normal) - DotProduct (p1, normal);

		if (dist < 0.0)
		{
			in = false;

			CrossProduct (plane.normal, normal, delta);
			dot = DotProduct (delta, point);
			dot1 = DotProduct (delta, p1);
			dot2 = DotProduct (delta, p2);
			if (dot1 < dot && dot < dot2)
			{
				dist = dist / DotProduct (normal, normal);
				VectorMA (point, -dist, normal, point);
				return;
			}
		}
	}
	if (in)
	{
		return;
	}

	for (x = 0; x < numpoints; x++)
	{
		p1 = w.m_Points[x];
		VectorSubtract (p1, point, delta);
		dist = DotProduct (delta, plane.normal) / DotProduct (plane.normal, plane.normal);
		VectorMA (delta, -dist, plane.normal, delta);
		dot = DotProduct (delta, delta);

		if (x == 0 || dot < bestdist)
		{
			VectorAdd (point, delta, bestpoint);
			bestdist = dot;
		}
	}
	if (numpoints > 0)
	{
		VectorCopy (bestpoint, point);
	}
	return;
}

// Assembly:
movslq 0x8(%rdi), %rcx
testq %rcx, %rcx
jle 0x24f9e
movq 0x10(%rdi), %rax
movss (%rsi), %xmm2
movsd 0x4(%rsi), %xmm11
movaps %xmm11, %xmm3
shufps $0x55, %xmm11, %xmm3    # xmm3 = xmm3[1,1],xmm11[1,1]
movsd (%rdx), %xmm1
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
movaps %xmm0, -0x18(%rsp)
movss 0x8(%rdx), %xmm0
movaps %xmm0, -0x78(%rsp)
movaps 0x12453(%rip), %xmm0    # 0x37080
movaps %xmm3, -0x58(%rsp)
xorps %xmm0, %xmm3
movaps %xmm3, -0x28(%rsp)
movaps %xmm2, %xmm3
xorps %xmm0, %xmm3
movaps %xmm3, -0x38(%rsp)
movaps %xmm11, %xmm3
xorps %xmm0, %xmm3
movaps %xmm3, -0x48(%rsp)
movaps %xmm2, -0x68(%rsp)
movaps %xmm2, %xmm4
shufps $0xd4, %xmm11, %xmm4    # xmm4 = xmm4[0,1],xmm11[1,3]
shufps $0xe2, %xmm11, %xmm4    # xmm4 = xmm4[2,0],xmm11[2,3]
leaq 0x4(%rax), %rsi
movq %rcx, %rdi
negq %rdi
movb $0x1, %r10b
movl $0x1, %r8d
xorl %r9d, %r9d
xorps %xmm0, %xmm0
movq %rdi, %r11
addq %r8, %r11
movq %r8, %r11
cmoveq %r9, %r11
leaq (%r11,%r11,2), %r11
movss (%rax,%r11,4), %xmm5
movss -0x4(%rsi), %xmm12
movaps %xmm5, %xmm13
subss %xmm12, %xmm13
movsd 0x4(%rax,%r11,4), %xmm15
movsd (%rsi), %xmm7
movaps %xmm15, %xmm14
subps %xmm7, %xmm14
movaps %xmm13, %xmm2
shufps $0xd4, %xmm14, %xmm2    # xmm2 = xmm2[0,1],xmm14[1,3]
shufps $0x52, %xmm14, %xmm2    # xmm2 = xmm2[2,0],xmm14[1,1]
mulps %xmm11, %xmm2
movaps -0x68(%rsp), %xmm3
mulss %xmm14, %xmm3
mulps %xmm4, %xmm14
subps %xmm2, %xmm14
mulss %xmm11, %xmm13
subss %xmm3, %xmm13
movaps %xmm7, %xmm2
shufps $0x10, %xmm14, %xmm2    # xmm2 = xmm2[0,0],xmm14[1,0]
shufps $0xe2, %xmm14, %xmm2    # xmm2 = xmm2[2,0],xmm14[2,3]
movaps %xmm14, %xmm3
shufps $0x11, %xmm1, %xmm3     # xmm3 = xmm3[1,0],xmm1[1,0]
shufps $0xe2, %xmm1, %xmm3     # xmm3 = xmm3[2,0],xmm1[2,3]
mulps %xmm2, %xmm3
movaps %xmm12, %xmm2
movlhps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
shufps $0xe2, %xmm1, %xmm2     # xmm2 = xmm2[2,0],xmm1[2,3]
movaps %xmm14, %xmm8
shufps $0x0, %xmm14, %xmm8     # xmm8 = xmm8[0,0],xmm14[0,0]
mulps %xmm2, %xmm8
addps %xmm3, %xmm8
movaps %xmm7, %xmm2
movaps -0x78(%rsp), %xmm3
movss %xmm3, %xmm2            # xmm2 = xmm3[0],xmm2[1,2,3]
movaps %xmm13, %xmm6
shufps $0x0, %xmm13, %xmm6     # xmm6 = xmm6[0,0],xmm13[0,0]
mulps %xmm2, %xmm6
addps %xmm8, %xmm6
movaps %xmm6, %xmm2
shufps $0x55, %xmm6, %xmm2     # xmm2 = xmm2[1,1],xmm6[1,1]
subss %xmm2, %xmm6
ucomiss %xmm6, %xmm0
jbe 0x24e1d
movaps %xmm4, %xmm0
movaps %xmm14, %xmm8
shufps $0x55, %xmm14, %xmm8    # xmm8 = xmm8[1,1],xmm14[1,1]
movaps %xmm8, %xmm2
mulss -0x28(%rsp), %xmm2
movaps %xmm11, %xmm4
mulss %xmm13, %xmm4
addss %xmm2, %xmm4
movaps %xmm13, %xmm2
mulss -0x38(%rsp), %xmm2
movaps -0x58(%rsp), %xmm9
mulss %xmm14, %xmm9
addss %xmm2, %xmm9
movaps %xmm14, %xmm10
mulss -0x48(%rsp), %xmm10
movaps -0x68(%rsp), %xmm2
mulss %xmm8, %xmm2
addss %xmm10, %xmm2
movaps -0x18(%rsp), %xmm10
mulss %xmm9, %xmm10
movaps %xmm4, %xmm3
mulss %xmm1, %xmm3
addss %xmm10, %xmm3
movaps %xmm2, %xmm10
mulss -0x78(%rsp), %xmm10
addss %xmm3, %xmm10
movaps %xmm7, %xmm3
mulss %xmm9, %xmm3
mulss %xmm4, %xmm12
addss %xmm3, %xmm12
shufps $0x55, %xmm7, %xmm7     # xmm7 = xmm7[1,1,1,1]
mulss %xmm2, %xmm7
addss %xmm12, %xmm7
ucomiss %xmm7, %xmm10
jbe 0x24e14
mulss %xmm15, %xmm9
mulss %xmm5, %xmm4
addss %xmm9, %xmm4
shufps $0x55, %xmm15, %xmm15   # xmm15 = xmm15[1,1,1,1]
mulss %xmm15, %xmm2
addss %xmm4, %xmm2
ucomiss %xmm10, %xmm2
ja 0x24f53
xorl %r10d, %r10d
movaps %xmm0, %xmm4
xorps %xmm0, %xmm0
addq $0xc, %rsi
leaq (%rdi,%r8), %r11
incq %r11
incq %r8
cmpq $0x1, %r11
jne 0x24c7c
testb $0x1, %r10b
jne 0x24f9e
movaps %xmm11, %xmm2
mulss %xmm11, %xmm2
movaps -0x68(%rsp), %xmm4
movaps %xmm4, %xmm3
mulss %xmm4, %xmm3
addss %xmm2, %xmm3
movaps -0x58(%rsp), %xmm5
mulss %xmm5, %xmm5
addss %xmm3, %xmm5
movaps %xmm11, %xmm7
shufps $0x0, %xmm11, %xmm7     # xmm7 = xmm7[0,0],xmm11[0,0]
movss %xmm4, %xmm7            # xmm7 = xmm4[0],xmm7[1,2,3]
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %esi, %esi
movaps -0x78(%rsp), %xmm13
movaps 0x121f6(%rip), %xmm15   # 0x37080
movaps -0x58(%rsp), %xmm14
movss 0x8(%rax,%rsi), %xmm4
subss %xmm13, %xmm4
movsd (%rax,%rsi), %xmm9
subps %xmm1, %xmm9
movaps %xmm9, %xmm2
shufps $0x55, %xmm9, %xmm2     # xmm2 = xmm2[1,1],xmm9[1,1]
mulss %xmm11, %xmm2
movaps %xmm9, %xmm12
mulss -0x68(%rsp), %xmm12
addss %xmm2, %xmm12
movaps %xmm4, %xmm10
mulss %xmm14, %xmm10
addss %xmm12, %xmm10
xorps %xmm15, %xmm10
divss %xmm5, %xmm10
movaps %xmm10, %xmm2
shufps $0x0, %xmm10, %xmm2     # xmm2 = xmm2[0,0],xmm10[0,0]
mulps %xmm7, %xmm2
addps %xmm9, %xmm2
mulss %xmm14, %xmm10
addss %xmm4, %xmm10
movaps %xmm2, %xmm4
mulps %xmm2, %xmm4
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
movaps %xmm2, %xmm12
mulss %xmm2, %xmm12
addss %xmm4, %xmm12
movaps %xmm10, %xmm9
mulss %xmm10, %xmm9
addss %xmm12, %xmm9
testq %rsi, %rsi
sete %dil
ucomiss %xmm9, %xmm8
seta %r8b
orb %dil, %r8b
je 0x24f41
addps %xmm1, %xmm2
addss %xmm13, %xmm10
movaps %xmm10, %xmm6
movaps %xmm9, %xmm8
movaps %xmm2, %xmm3
addq $0xc, %rsi
cmpq %rsi, %rcx
jne 0x24e90
movlps %xmm3, (%rdx)
jmp 0x24f99
mulss %xmm8, %xmm8
movaps %xmm14, %xmm2
mulss %xmm14, %xmm2
addss %xmm8, %xmm2
movaps %xmm13, %xmm3
mulss %xmm13, %xmm3
addss %xmm2, %xmm3
xorps 0x12106(%rip), %xmm6    # 0x37080
divss %xmm3, %xmm6
movaps %xmm6, %xmm2
unpcklps %xmm6, %xmm2            # xmm2 = xmm2[0],xmm6[0],xmm2[1],xmm6[1]
mulps %xmm14, %xmm2
addps %xmm1, %xmm2
movlps %xmm2, (%rdx)
mulss %xmm13, %xmm6
addss -0x78(%rsp), %xmm6
movss %xmm6, 0x8(%rdx)
retq