// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlvis/flow.cpp
// Function: BestNormalFromWinding(float const (*) [3], int, float (&) [3])
bool BestNormalFromWinding (const vec3_t *points, int numpoints, vec3_t &normal_out)
{
	const vec3_t *pt1, *pt2, *pt3;
	int k;
	vec3_t d, normal, edge;
	vec_t dist, maxdist;
	if (numpoints < 3)
	{
		return false;
	}
	pt1 = &points[0];
	maxdist = -1;
	for (k = 0; k < numpoints; k++)
	{
		if (&points[k] == pt1)
		{
			continue;
		}
		VectorSubtract (points[k], *pt1, edge);
		dist = DotProduct (edge, edge);
		if (dist > maxdist)
		{
			maxdist = dist;
			pt2 = &points[k];
		}
	}
	if (maxdist <= ON_EPSILON * ON_EPSILON)
	{
		return false;
	}
	maxdist = -1;
	VectorSubtract (*pt2, *pt1, edge);
	VectorNormalize (edge);
	for (k = 0; k < numpoints; k++)
	{
		if (&points[k] == pt1 || &points[k] == pt2)
		{
			continue;
		}
		VectorSubtract (points[k], *pt1, d);
		CrossProduct (edge, d, normal);
		dist = DotProduct (normal, normal);
		if (dist > maxdist)
		{
			maxdist = dist;
			pt3 = &points[k];
		}
	}
	if (maxdist <= ON_EPSILON * ON_EPSILON)
	{
		return false;
	}
	VectorSubtract (*pt3, *pt1, d);
	CrossProduct (edge, d, normal);
	VectorNormalize (normal);
	if (pt3 < pt2)
	{
		VectorScale (normal, -1, normal);
	}
	VectorCopy (normal, normal_out);
	return true;
}

// Assembly:
cmpl $0x3, %esi
jl 0xd2d9
movl %esi, %ecx
leaq (,%rcx,4), %rax
leaq (%rax,%rax,2), %rsi
movss 0x828c(%rip), %xmm0     # 0x152f0
xorl %r8d, %r8d
testq %r8, %r8
je 0xd0ae
movss (%rdi,%r8), %xmm2
movss 0x4(%rdi,%r8), %xmm3
subss (%rdi), %xmm2
subss 0x4(%rdi), %xmm3
movss 0x8(%rdi,%r8), %xmm1
subss 0x8(%rdi), %xmm1
mulss %xmm3, %xmm3
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm0, %xmm1
jbe 0xd0ae
leaq (%rdi,%r8), %rax
movaps %xmm1, %xmm0
addq $0xc, %r8
cmpq %r8, %rsi
jne 0xd067
cvtss2sd %xmm0, %xmm0
movsd 0x83c5(%rip), %xmm1     # 0x15488
ucomisd %xmm0, %xmm1
jae 0xd2d9
movss (%rax), %xmm0
movss (%rdi), %xmm4
subss %xmm4, %xmm0
movsd 0x4(%rax), %xmm6
movsd 0x4(%rdi), %xmm3
subps %xmm3, %xmm6
movaps %xmm6, %xmm1
shufps $0x55, %xmm6, %xmm1     # xmm1 = xmm1[1,1],xmm6[1,1]
movaps %xmm6, %xmm5
mulss %xmm6, %xmm5
movaps %xmm0, %xmm7
mulss %xmm0, %xmm7
addss %xmm5, %xmm7
mulss %xmm1, %xmm1
addss %xmm7, %xmm1
cvtss2sd %xmm1, %xmm1
xorps %xmm7, %xmm7
sqrtsd %xmm1, %xmm7
movsd 0x4ffe(%rip), %xmm1     # 0x12118
ucomisd %xmm7, %xmm1
jbe 0xd129
xorps %xmm2, %xmm2
xorpd %xmm1, %xmm1
jmp 0xd147
cvtss2sd %xmm0, %xmm0
divsd %xmm7, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
cvtps2pd %xmm6, %xmm0
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
divpd %xmm7, %xmm0
cvtpd2ps %xmm0, %xmm2
movapd %xmm2, %xmm7
shufps $0x55, %xmm2, %xmm7     # xmm7 = xmm7[1,1],xmm2[1,1]
movaps 0x4f2a(%rip), %xmm0     # 0x12080
movaps %xmm7, %xmm8
xorps %xmm0, %xmm8
movaps %xmm1, %xmm9
xorps %xmm0, %xmm9
movaps %xmm2, %xmm10
xorps %xmm0, %xmm10
movaps %xmm3, %xmm11
shufps $0x55, %xmm3, %xmm11    # xmm11 = xmm11[1,1],xmm3[1,1]
movss 0x8170(%rip), %xmm12    # 0x152f0
xorl %r8d, %r8d
testq %r8, %r8
sete %r9b
cmpq %rax, %rdi
sete %r10b
orb %r9b, %r10b
jne 0xd212
movss (%rdi), %xmm13
movss 0x4(%rdi), %xmm14
subss %xmm4, %xmm13
subss %xmm3, %xmm14
movss 0x8(%rdi), %xmm15
subss %xmm11, %xmm15
movaps %xmm1, %xmm5
mulss %xmm14, %xmm5
mulss %xmm8, %xmm14
movaps %xmm2, %xmm6
mulss %xmm15, %xmm6
addss %xmm14, %xmm6
mulss %xmm9, %xmm15
movaps %xmm7, %xmm14
mulss %xmm13, %xmm14
addss %xmm15, %xmm14
mulss %xmm10, %xmm13
addss %xmm5, %xmm13
mulss %xmm14, %xmm14
mulss %xmm6, %xmm6
addss %xmm14, %xmm6
mulss %xmm13, %xmm13
addss %xmm6, %xmm13
ucomiss %xmm12, %xmm13
jbe 0xd212
movq %rdi, %rsi
movaps %xmm13, %xmm12
incq %r8
addq $0xc, %rdi
cmpq %r8, %rcx
jne 0xd183
xorps %xmm5, %xmm5
cvtss2sd %xmm12, %xmm5
movsd 0x8256(%rip), %xmm6     # 0x15488
ucomisd %xmm5, %xmm6
jae 0xd2d9
movss 0x4(%rsi), %xmm5
subss %xmm3, %xmm5
movaps %xmm1, %xmm6
shufps $0xd4, %xmm2, %xmm6     # xmm6 = xmm6[0,1],xmm2[1,3]
shufps $0x52, %xmm2, %xmm6     # xmm6 = xmm6[2,0],xmm2[1,1]
movss (%rsi), %xmm7
movss 0x8(%rsi), %xmm8
unpcklps %xmm7, %xmm8            # xmm8 = xmm8[0],xmm7[0],xmm8[1],xmm7[1]
shufps $0xd4, %xmm3, %xmm4     # xmm4 = xmm4[0,1],xmm3[1,3]
shufps $0x52, %xmm3, %xmm4     # xmm4 = xmm4[2,0],xmm3[1,1]
subps %xmm4, %xmm8
movaps %xmm8, %xmm3
shufps $0x0, %xmm8, %xmm3      # xmm3 = xmm3[0,0],xmm8[0,0]
movss %xmm5, %xmm3            # xmm3 = xmm5[0],xmm3[1,2,3]
mulps %xmm6, %xmm3
movaps %xmm2, %xmm4
mulps %xmm8, %xmm4
subps %xmm3, %xmm4
shufps $0x55, %xmm8, %xmm8     # xmm8 = xmm8[1,1,1,1]
mulss %xmm2, %xmm8
mulss %xmm1, %xmm5
subss %xmm8, %xmm5
movaps %xmm4, %xmm1
mulps %xmm4, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm4, %xmm2
mulss %xmm4, %xmm2
addss %xmm1, %xmm2
movaps %xmm5, %xmm1
mulss %xmm5, %xmm1
addss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
xorps %xmm3, %xmm3
sqrtsd %xmm1, %xmm3
movsd 0x4e4e(%rip), %xmm1     # 0x12118
ucomisd %xmm3, %xmm1
jbe 0xd2dc
xorpd %xmm1, %xmm1
xorps %xmm2, %xmm2
jmp 0xd2fe
xorl %eax, %eax
retq
cvtps2pd %xmm4, %xmm1
movapd %xmm3, %xmm2
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
divpd %xmm2, %xmm1
cvtpd2ps %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm5, %xmm2
divsd %xmm3, %xmm2
cvtsd2ss %xmm2, %xmm2
xorl %ecx, %ecx
movapd %xmm1, %xmm3
xorpd %xmm0, %xmm3
cmpq %rax, %rsi
setb %al
jae 0xd313
xorps %xmm0, %xmm2
movb %al, %cl
movd %ecx, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
pslld $0x1f, %xmm0
psrad $0x1f, %xmm0
andpd %xmm0, %xmm3
andnpd %xmm1, %xmm0
orpd %xmm3, %xmm0
movlpd %xmm0, (%rdx)
movss %xmm2, 0x8(%rdx)
movb $0x1, %al
retq