// File: /workspace/github_cpp_makefile_star2_O1/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), %rax
testq %rax, %rax
jle 0x25d19
pushq %r14
pushq %rbx
movq 0x10(%rdi), %rcx
movss (%rsi), %xmm10
movsd 0x4(%rsi), %xmm1
movaps %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm3     # xmm3 = xmm3[1,1],xmm1[1,1]
movsd (%rdx), %xmm2
movaps %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm0     # xmm0 = xmm0[1,1],xmm2[1,1]
movaps %xmm0, -0x28(%rsp)
movss 0x8(%rdx), %xmm0
movaps %xmm0, -0x78(%rsp)
movaps 0x126e9(%rip), %xmm0    # 0x38090
movaps %xmm3, -0x18(%rsp)
xorps %xmm0, %xmm3
movaps %xmm3, -0x38(%rsp)
movaps %xmm10, %xmm3
xorps %xmm0, %xmm3
movaps %xmm3, -0x48(%rsp)
movaps %xmm1, %xmm3
xorps %xmm0, %xmm3
movaps %xmm3, -0x58(%rsp)
movaps %xmm10, -0x68(%rsp)
shufps $0xd4, %xmm1, %xmm10    # xmm10 = xmm10[0,1],xmm1[1,3]
shufps $0xe2, %xmm1, %xmm10    # xmm10 = xmm10[2,0],xmm1[2,3]
leaq 0x4(%rcx), %r8
movq %rax, %r9
negq %r9
movb $0x1, %bl
movl $0x1, %r10d
xorl %r11d, %r11d
xorps %xmm8, %xmm8
movq %r9, %r14
addq %r10, %r14
movq %r10, %r14
cmoveq %r11, %r14
leaq (%r14,%r14,2), %r14
movss (%rcx,%r14,4), %xmm0
movss -0x4(%r8), %xmm11
movaps %xmm0, %xmm15
subss %xmm11, %xmm15
movsd 0x4(%rcx,%r14,4), %xmm14
movsd (%r8), %xmm6
movaps %xmm14, %xmm13
subps %xmm6, %xmm13
movaps %xmm15, %xmm3
shufps $0xd4, %xmm13, %xmm3    # xmm3 = xmm3[0,1],xmm13[1,3]
shufps $0x52, %xmm13, %xmm3    # xmm3 = xmm3[2,0],xmm13[1,1]
mulps %xmm1, %xmm3
movaps -0x68(%rsp), %xmm4
mulss %xmm13, %xmm4
mulps %xmm10, %xmm13
subps %xmm3, %xmm13
mulss %xmm1, %xmm15
subss %xmm4, %xmm15
movaps %xmm6, %xmm3
shufps $0x10, %xmm13, %xmm3    # xmm3 = xmm3[0,0],xmm13[1,0]
shufps $0xe2, %xmm13, %xmm3    # xmm3 = xmm3[2,0],xmm13[2,3]
movaps %xmm13, %xmm4
shufps $0x11, %xmm2, %xmm4     # xmm4 = xmm4[1,0],xmm2[1,0]
shufps $0xe2, %xmm2, %xmm4     # xmm4 = xmm4[2,0],xmm2[2,3]
mulps %xmm3, %xmm4
movaps %xmm11, %xmm3
movlhps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
shufps $0xe2, %xmm2, %xmm3     # xmm3 = xmm3[2,0],xmm2[2,3]
movaps %xmm13, %xmm7
shufps $0x0, %xmm13, %xmm7     # xmm7 = xmm7[0,0],xmm13[0,0]
mulps %xmm3, %xmm7
addps %xmm4, %xmm7
movaps %xmm6, %xmm3
movaps -0x78(%rsp), %xmm4
movss %xmm4, %xmm3            # xmm3 = xmm4[0],xmm3[1,2,3]
movaps %xmm15, %xmm12
shufps $0x0, %xmm15, %xmm12    # xmm12 = xmm12[0,0],xmm15[0,0]
mulps %xmm3, %xmm12
addps %xmm7, %xmm12
movaps %xmm12, %xmm3
shufps $0x55, %xmm12, %xmm3    # xmm3 = xmm3[1,1],xmm12[1,1]
subss %xmm3, %xmm12
ucomiss %xmm12, %xmm8
jbe 0x25b8f
movaps %xmm13, %xmm7
shufps $0x55, %xmm13, %xmm7    # xmm7 = xmm7[1,1],xmm13[1,1]
movaps %xmm7, %xmm3
mulss -0x38(%rsp), %xmm3
movaps %xmm1, %xmm5
mulss %xmm15, %xmm5
addss %xmm3, %xmm5
movaps %xmm15, %xmm3
mulss -0x48(%rsp), %xmm3
movaps -0x18(%rsp), %xmm9
mulss %xmm13, %xmm9
addss %xmm3, %xmm9
movaps %xmm13, %xmm8
mulss -0x58(%rsp), %xmm8
movaps -0x68(%rsp), %xmm3
mulss %xmm7, %xmm3
addss %xmm8, %xmm3
movaps -0x28(%rsp), %xmm8
mulss %xmm9, %xmm8
movaps %xmm5, %xmm4
mulss %xmm2, %xmm4
addss %xmm8, %xmm4
movaps %xmm3, %xmm8
mulss -0x78(%rsp), %xmm8
addss %xmm4, %xmm8
movaps %xmm6, %xmm4
mulss %xmm9, %xmm4
mulss %xmm5, %xmm11
addss %xmm4, %xmm11
shufps $0x55, %xmm6, %xmm6     # xmm6 = xmm6[1,1,1,1]
mulss %xmm3, %xmm6
addss %xmm11, %xmm6
ucomiss %xmm6, %xmm8
jbe 0x25b89
mulss %xmm14, %xmm9
mulss %xmm0, %xmm5
addss %xmm9, %xmm5
shufps $0x55, %xmm14, %xmm14   # xmm14 = xmm14[1,1,1,1]
mulss %xmm14, %xmm3
addss %xmm5, %xmm3
ucomiss %xmm8, %xmm3
ja 0x25cc7
xorl %ebx, %ebx
xorps %xmm8, %xmm8
addq $0xc, %r8
leaq (%r9,%r10), %r14
incq %r14
incq %r10
cmpq $0x1, %r14
jne 0x259f4
testb $0x1, %bl
jne 0x25d16
movq 0x10(%rdi), %rcx
movss 0x8(%rdx), %xmm1
movsd (%rdx), %xmm2
movsd (%rsi), %xmm3
movaps %xmm3, %xmm0
shufps $0x55, %xmm3, %xmm0     # xmm0 = xmm0[1,1],xmm3[1,1]
movss 0x8(%rsi), %xmm4
mulss %xmm0, %xmm0
movaps %xmm3, %xmm5
mulss %xmm3, %xmm5
addss %xmm0, %xmm5
movaps %xmm4, %xmm0
mulss %xmm4, %xmm0
addss %xmm5, %xmm0
movl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rax
xorl %esi, %esi
movaps 0x12495(%rip), %xmm12   # 0x38090
movss 0x8(%rcx,%rsi), %xmm10
subss %xmm1, %xmm10
movsd (%rcx,%rsi), %xmm11
subps %xmm2, %xmm11
movaps %xmm11, %xmm8
mulps %xmm3, %xmm8
shufps $0x55, %xmm8, %xmm8     # xmm8 = xmm8[1,1,1,1]
movaps %xmm11, %xmm9
mulss %xmm3, %xmm9
addss %xmm8, %xmm9
movaps %xmm10, %xmm8
mulss %xmm4, %xmm8
addss %xmm9, %xmm8
xorps %xmm12, %xmm8
divss %xmm0, %xmm8
movaps %xmm8, %xmm9
shufps $0x0, %xmm8, %xmm9      # xmm9 = xmm9[0,0],xmm8[0,0]
mulps %xmm3, %xmm9
addps %xmm11, %xmm9
mulss %xmm4, %xmm8
addss %xmm10, %xmm8
movaps %xmm9, %xmm10
mulps %xmm9, %xmm10
shufps $0x55, %xmm10, %xmm10   # xmm10 = xmm10[1,1,1,1]
movaps %xmm9, %xmm11
mulss %xmm9, %xmm11
addss %xmm10, %xmm11
movaps %xmm8, %xmm10
mulss %xmm8, %xmm10
addss %xmm11, %xmm10
testq %rsi, %rsi
sete %dil
ucomiss %xmm10, %xmm6
seta %r8b
orb %dil, %r8b
je 0x25cb0
addps %xmm2, %xmm9
addss %xmm1, %xmm8
movaps %xmm8, %xmm5
movaps %xmm10, %xmm6
movaps %xmm9, %xmm7
addq $0xc, %rsi
cmpq %rsi, %rax
jne 0x25bfb
movlps %xmm7, (%rdx)
movss %xmm5, 0x8(%rdx)
jmp 0x25d16
mulss %xmm7, %xmm7
movaps %xmm13, %xmm0
mulss %xmm13, %xmm0
addss %xmm7, %xmm0
movaps %xmm15, %xmm1
mulss %xmm15, %xmm1
addss %xmm0, %xmm1
xorps 0x123a3(%rip), %xmm12   # 0x38090
divss %xmm1, %xmm12
movaps %xmm12, %xmm0
unpcklps %xmm12, %xmm0           # xmm0 = xmm0[0],xmm12[0],xmm0[1],xmm12[1]
mulps %xmm13, %xmm0
addps %xmm2, %xmm0
movlps %xmm0, (%rdx)
mulss %xmm15, %xmm12
addss -0x78(%rsp), %xmm12
movss %xmm12, 0x8(%rdx)
popq %rbx
popq %r14
retq