// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlrad/trace.cpp
// Function: TryMerge(opaqueface_t*, opaqueface_t const*)
bool TryMerge (opaqueface_t *f, const opaqueface_t *f2)
{
	if (!f->winding || !f2->winding)
	{
		return false;
	}
	if (fabs (f2->plane.dist - f->plane.dist) > ON_EPSILON
		|| fabs (f2->plane.normal[0] - f->plane.normal[0]) > NORMAL_EPSILON
		|| fabs (f2->plane.normal[1] - f->plane.normal[1]) > NORMAL_EPSILON
		|| fabs (f2->plane.normal[2] - f->plane.normal[2]) > NORMAL_EPSILON
		)
	{
		return false;
	}
#ifdef HLRAD_OPAQUE_ALPHATEST
	if ((f->tex_alphatest || f2->tex_alphatest) && f->texinfo != f2->texinfo)
	{
		return false;
	}
#endif

	Winding *w = f->winding;
	const Winding *w2 = f2->winding;
	const vec_t *pA, *pB, *pC, *pD, *p2A, *p2B, *p2C, *p2D;
	int i, i2;

	for (i = 0; i < w->m_NumPoints; i++)
	{
		for (i2 = 0; i2 < w2->m_NumPoints; i2++)
		{
			pA = w->m_Points[(i+w->m_NumPoints-1)%w->m_NumPoints];
			pB = w->m_Points[i];
			pC = w->m_Points[(i+1)%w->m_NumPoints];
			pD = w->m_Points[(i+2)%w->m_NumPoints];
			p2A = w2->m_Points[(i2+w2->m_NumPoints-1)%w2->m_NumPoints];
			p2B = w2->m_Points[i2];
			p2C = w2->m_Points[(i2+1)%w2->m_NumPoints];
			p2D = w2->m_Points[(i2+2)%w2->m_NumPoints];
			if (!VectorCompare (pB, p2C) || !VectorCompare (pC, p2B))
			{
				continue;
			}
			break;
		}
		if (i2 == w2->m_NumPoints)
		{
			continue;
		}
		break;
	}
	if (i == w->m_NumPoints)
	{
		return false;
	}

	const vec_t *normal = f->plane.normal;
	vec3_t e1, e2;
	dplane_t pl1, pl2;
	int side1, side2;

	VectorSubtract (p2D, pA, e1);
	CrossProduct (normal, e1, pl1.normal); // pointing outward
	if (VectorNormalize (pl1.normal) == 0.0)
	{
		Developer (DEVELOPER_LEVEL_WARNING, "Warning: TryMerge: Empty edge.\n");
		return false;
	}
	pl1.dist = DotProduct (pA, pl1.normal);
	if (DotProduct (pB, pl1.normal) - pl1.dist < -ON_EPSILON)
	{
		return false;
	}
	side1 = (DotProduct (pB, pl1.normal) - pl1.dist > ON_EPSILON)? 1: 0;

	VectorSubtract (pD, p2A, e2);
	CrossProduct (normal, e2, pl2.normal); // pointing outward
	if (VectorNormalize (pl2.normal) == 0.0)
	{
		Developer (DEVELOPER_LEVEL_WARNING, "Warning: TryMerge: Empty edge.\n");
		return false;
	}
	pl2.dist = DotProduct (p2A, pl2.normal);
	if (DotProduct (p2B, pl2.normal) - pl2.dist < -ON_EPSILON)
	{
		return false;
	}
	side2 = (DotProduct (p2B, pl2.normal) - pl2.dist > ON_EPSILON)? 1: 0;

	Winding *neww = new Winding (w->m_NumPoints + w2->m_NumPoints - 4 + side1 + side2);
	int j, k;
	k = 0;
	for (j = (i + 2) % w->m_NumPoints; j != i; j = (j + 1) % w->m_NumPoints)
	{
		VectorCopy (w->m_Points[j], neww->m_Points[k]);
		k++;
	}
	if (side1)
	{
		VectorCopy (w->m_Points[j], neww->m_Points[k]);
		k++;
	}
	for (j = (i2 + 2) % w2->m_NumPoints; j != i2; j = (j + 1) % w2->m_NumPoints)
	{
		VectorCopy (w2->m_Points[j], neww->m_Points[k]);
		k++;
	}
	if (side2)
	{
		VectorCopy (w2->m_Points[j], neww->m_Points[k]);
		k++;
	}
	neww->RemoveColinearPoints ();
	if (neww->m_NumPoints < 3)
	{
		Developer (DEVELOPER_LEVEL_WARNING, "Warning: TryMerge: Empty winding.\n");
		delete neww;
		neww = NULL;
	}
	delete f->winding;
	f->winding = neww;
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq (%rdi), %rbp
testq %rbp, %rbp
je 0x337e3
movq (%rsi), %r13
testq %r13, %r13
je 0x337e3
movq %rdi, %rbx
movss 0x14(%rsi), %xmm0
subss 0x14(%rdi), %xmm0
andps 0x7e20(%rip), %xmm0     # 0x3b340
cvtss2sd %xmm0, %xmm0
ucomisd 0x811c(%rip), %xmm0     # 0x3b648
ja 0x337e3
movss 0x8(%rsi), %xmm1
movss 0x8(%rbx), %xmm0
subss %xmm0, %xmm1
andps 0x7df9(%rip), %xmm1     # 0x3b340
cvtss2sd %xmm1, %xmm1
ucomisd 0x4bbd(%rip), %xmm1     # 0x38110
ja 0x337e3
movss 0xc(%rsi), %xmm2
movss 0xc(%rbx), %xmm1
subss %xmm1, %xmm2
andps 0x7dd2(%rip), %xmm2     # 0x3b340
cvtss2sd %xmm2, %xmm2
ucomisd 0x4b96(%rip), %xmm2     # 0x38110
ja 0x337e3
movss 0x10(%rsi), %xmm3
movss 0x10(%rbx), %xmm2
subss %xmm2, %xmm3
andps 0x7dab(%rip), %xmm3     # 0x3b340
cvtss2sd %xmm3, %xmm3
ucomisd 0x4b6f(%rip), %xmm3     # 0x38110
ja 0x337e3
cmpb $0x0, 0x2c(%rbx)
jne 0x335b3
cmpb $0x1, 0x2c(%rsi)
jne 0x335bf
movl 0x28(%rbx), %eax
cmpl 0x28(%rsi), %eax
jne 0x337e3
movl 0x8(%rbp), %eax
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq %rbp, 0x28(%rsp)
je 0x337cf
movl 0x8(%r13), %r8d
leal -0x1(%r8), %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x38(%rsp)
leal -0x2(,%r8,2), %eax
movl %eax, 0x24(%rsp)
leal 0x1(%r8), %eax
movl %eax, 0x20(%rsp)
movl $0x4, %r10d
movaps 0x7d35(%rip), %xmm3     # 0x3b340
movsd 0x84e5(%rip), %xmm4     # 0x3baf8
xorl %edi, %edi
movq %r13, 0x40(%rsp)
movl $0x0, %r15d
testl %r8d, %r8d
je 0x337aa
movq 0x10(%rbp), %r9
leaq (%rdi,%rdi,2), %rax
leaq (%r9,%rax,4), %rax
movq 0x10(%r13), %r11
movq %rax, 0x30(%rsp)
movss (%rax), %xmm5
movq %rdi, 0x18(%rsp)
leaq 0x1(%rdi), %rax
movq 0x38(%rsp), %rcx
addq %r11, %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x8(%rsp), %rax
movl %eax, %eax
movl $0x0, %ecx
cmoveq %rcx, %rax
leaq (%rax,%rax,2), %rax
leaq (%r9,%rax,4), %rcx
leaq (%r9,%r10), %rdx
leaq 0x4(%r11), %rax
movq %rax, %rsi
xorl %r13d, %r13d
movq %r13, %r15
incq %r13
cmpq %r8, %r13
movl %r13d, %edi
movl $0x0, %r14d
cmovneq %rdi, %r14
leaq (%r14,%r14,2), %rdi
movaps %xmm5, %xmm6
subss (%r11,%rdi,4), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
ucomisd %xmm4, %xmm6
ja 0x33733
leaq (%r15,%r15,2), %r14
leaq (%r11,%r14,4), %r14
leaq (%rax,%rdi,4), %rdi
xorl %r12d, %r12d
movq %r12, %rbp
cmpq $0x2, %r12
je 0x336e5
movss (%rdx,%rbp,4), %xmm6
subss (%rdi,%rbp,4), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
leaq 0x1(%rbp), %r12
ucomisd %xmm4, %xmm6
jbe 0x336c1
cmpq $0x2, %rbp
jb 0x33733
movss (%rcx), %xmm6
subss (%r14), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
ucomisd %xmm4, %xmm6
ja 0x33733
xorl %r12d, %r12d
movq %r12, %rdi
cmpq $0x2, %r12
je 0x33729
movss 0x4(%rcx,%rdi,4), %xmm6
subss (%rsi,%rdi,4), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
leaq 0x1(%rdi), %r12
ucomisd %xmm4, %xmm6
jbe 0x33704
cmpq $0x1, %rdi
ja 0x337c3
addq $0xc, %rsi
cmpq %r8, %r13
jne 0x3367e
movl 0x20(%rsp), %ecx
movl %r8d, %r15d
movq 0x10(%rsp), %r14
movl 0x24(%rsp), %esi
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r12
leal (%rdi,%r12), %eax
decl %eax
xorl %edx, %edx
divl %r12d
leaq (%rdx,%rdx,2), %rax
leaq (%r9,%rax,4), %rax
movq %rax, 0x10(%rsp)
leal 0x2(%rdi), %eax
xorl %edx, %edx
divl %r12d
leaq (%rdx,%rdx,2), %rax
leaq (%r9,%rax,4), %r9
movl %esi, %eax
xorl %edx, %edx
divl %r8d
leaq (%rdx,%rdx,2), %rax
leaq (%r11,%rax,4), %r12
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
leaq (%rdx,%rdx,2), %rax
leaq (%r11,%rax,4), %rax
movq 0x40(%rsp), %r13
movq 0x28(%rsp), %rbp
cmpl %r8d, %r15d
jne 0x337d8
incq %rdi
addq $0xc, %r10
cmpq 0x8(%rsp), %rdi
jne 0x3361a
jmp 0x337d3
leal (%r15,%r8), %esi
decl %esi
leal 0x2(%r15), %ecx
jmp 0x33750
xorl %edi, %edi
jmp 0x337dd
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rcx
cmpl 0x8(%rsp), %edi
jne 0x337f6
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movss 0x4(%rax), %xmm3
subss 0x4(%rcx), %xmm3
movaps %xmm1, %xmm4
unpcklps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
movss (%rax), %xmm5
movss 0x8(%rax), %xmm6
unpcklps %xmm5, %xmm6            # xmm6 = xmm6[0],xmm5[0],xmm6[1],xmm5[1]
movss (%rcx), %xmm5
movss 0x8(%rcx), %xmm7
unpcklps %xmm5, %xmm7            # xmm7 = xmm7[0],xmm5[0],xmm7[1],xmm5[1]
subps %xmm7, %xmm6
mulss %xmm3, %xmm0
unpcklps %xmm6, %xmm3            # xmm3 = xmm3[0],xmm6[0],xmm3[1],xmm6[1]
mulps %xmm2, %xmm3
mulps %xmm6, %xmm4
subps %xmm3, %xmm4
leaq 0x60(%rsp), %rdi
movlps %xmm4, (%rdi)
shufps $0x55, %xmm6, %xmm6     # xmm6 = xmm6[1,1,1,1]
mulss %xmm1, %xmm6
subss %xmm6, %xmm0
movss %xmm0, 0x8(%rdi)
movq %rcx, %rbp
callq 0x34c65
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x33883
jp 0x33883
leaq 0xc438(%rip), %rsi      # 0x3fca8
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0xa52e
jmp 0x337e5
movss 0x60(%rsp), %xmm0
movss 0x64(%rsp), %xmm1
movss 0x4(%rbp), %xmm2
mulss %xmm1, %xmm2
movss (%rbp), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x68(%rsp), %xmm2
movss 0x8(%rbp), %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x6c(%rsp)
movq 0x30(%rsp), %rax
mulss 0x4(%rax), %xmm1
mulss (%rax), %xmm0
addss %xmm1, %xmm0
mulss 0x8(%rax), %xmm2
addss %xmm0, %xmm2
subss %xmm4, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x7d54(%rip), %xmm1     # 0x3b640
ucomisd %xmm0, %xmm1
ja 0x337e3
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %rax
movss 0x4(%rax), %xmm1
subss 0x4(%r12), %xmm1
movss 0x8(%rbx), %xmm0
movss (%rax), %xmm2
movss 0x8(%rax), %xmm3
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movss (%r12), %xmm2
movss 0x8(%r12), %xmm4
unpcklps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
subps %xmm4, %xmm3
movsd 0xc(%rbx), %xmm2
movaps %xmm0, %xmm4
shufps $0xd4, %xmm2, %xmm4     # xmm4 = xmm4[0,1],xmm2[1,3]
shufps $0x52, %xmm2, %xmm4     # xmm4 = xmm4[2,0],xmm2[1,1]
mulss %xmm1, %xmm0
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
mulps %xmm4, %xmm1
movaps %xmm2, %xmm4
mulps %xmm3, %xmm4
subps %xmm1, %xmm4
leaq 0x48(%rsp), %rdi
movlps %xmm4, (%rdi)
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
mulss %xmm2, %xmm3
subss %xmm3, %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x34c65
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x33980
jnp 0x33869
movss 0x48(%rsp), %xmm0
movss 0x4c(%rsp), %xmm1
movss 0x4(%r12), %xmm2
mulss %xmm1, %xmm2
movss (%r12), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x50(%rsp), %xmm2
movss 0x8(%r12), %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x54(%rsp)
mulss 0x4(%r14), %xmm1
mulss (%r14), %xmm0
addss %xmm1, %xmm0
mulss 0x8(%r14), %xmm2
addss %xmm0, %xmm2
subss %xmm4, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
movsd 0x7c54(%rip), %xmm0     # 0x3b640
ucomisd %xmm1, %xmm0
ja 0x337e3
movsd 0x7c4a(%rip), %xmm0     # 0x3b648
xorl %r12d, %r12d
movsd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
seta %r12b
xorl %ebp, %ebp
movsd %xmm1, 0x8(%rsp)
ucomisd %xmm0, %xmm1
seta %bpl
movl $0x20, %edi
callq 0x42f0
movq %rax, %r14
movl 0x8(%r13), %eax
addl %ebp, %r12d
movq 0x28(%rsp), %rbp
addl 0x8(%rbp), %r12d
leal (%rax,%r12), %esi
addl $-0x4, %esi
movq %r14, %rdi
callq 0xc372
movq 0x18(%rsp), %rsi
leal 0x2(%rsi), %eax
xorl %ecx, %ecx
xorl %edx, %edx
divl 0x8(%rbp)
cmpl %esi, %edx
movq %rbp, %r8
jne 0x33a69
movsd 0x8(%rsp), %xmm1
jmp 0x33ad0
xorl %ecx, %ecx
xorl %esi, %esi
movsd 0x8(%rsp), %xmm1
movq 0x10(%r8), %rdi
movslq %edx, %rax
leaq (,%rax,4), %rdx
leaq (%rdx,%rdx,2), %rdx
movss (%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdi
movss %xmm0, (%rdi,%rsi)
movq 0x10(%r8), %rdi
movss 0x4(%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdi
movss %xmm0, 0x4(%rdi,%rsi)
movq 0x10(%r8), %rdi
movss 0x8(%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdx
movss %xmm0, 0x8(%rdx,%rsi)
incl %eax
xorl %edx, %edx
divl 0x8(%r8)
addq $0xc, %rsi
incl %ecx
cmpl 0x18(%rsp), %edx
jne 0x33a73
movsd 0x10(%rsp), %xmm0
ucomisd 0x7b6a(%rip), %xmm0     # 0x3b648
jbe 0x33b31
movq 0x10(%r8), %rax
movslq %edx, %rdx
shlq $0x2, %rdx
leaq (%rdx,%rdx,2), %rdx
movss (%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movl %ecx, %esi
shlq $0x2, %rsi
leaq (%rsi,%rsi,2), %rsi
movss %xmm0, (%rax,%rsi)
movq 0x10(%r8), %rax
movss 0x4(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x4(%rax,%rsi)
movq 0x10(%r8), %rax
movss 0x8(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x8(%rax,%rsi)
incl %ecx
leal 0x2(%r15), %eax
xorl %edx, %edx
divl 0x8(%r13)
cmpl %r15d, %edx
je 0x33ba7
movslq %ecx, %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
movq 0x10(%r13), %rdi
movslq %edx, %rax
leaq (,%rax,4), %rdx
leaq (%rdx,%rdx,2), %rdx
movss (%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdi
movss %xmm0, (%rdi,%rsi)
movq 0x10(%r13), %rdi
movss 0x4(%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdi
movss %xmm0, 0x4(%rdi,%rsi)
movq 0x10(%r13), %rdi
movss 0x8(%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdx
movss %xmm0, 0x8(%rdx,%rsi)
incl %eax
xorl %edx, %edx
divl 0x8(%r13)
addq $0xc, %rsi
incl %ecx
cmpl %r15d, %edx
jne 0x33b4b
ucomisd 0x7a99(%rip), %xmm1     # 0x3b648
jbe 0x33c01
movq 0x10(%r13), %rax
movslq %edx, %rdx
shlq $0x2, %rdx
leaq (%rdx,%rdx,2), %rdx
movss (%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rcx
movss %xmm0, (%rax,%rcx)
movq 0x10(%r13), %rax
movss 0x4(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x4(%rax,%rcx)
movq 0x10(%r13), %rax
movss 0x8(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x8(%rax,%rcx)
movss 0x7e7b(%rip), %xmm0     # 0x3ba84
movq %r14, %rdi
callq 0xc7de
cmpl $0x2, 0x8(%r14)
ja 0x33c37
leaq 0xc0a9(%rip), %rsi      # 0x3fcc8
movl $0x2, %edi
xorl %eax, %eax
callq 0xa52e
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
xorl %r14d, %r14d
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x33c45
movq (%rdi), %rax
callq *0x8(%rax)
movq %r14, (%rbx)
movb $0x1, %bl
jmp 0x337e5
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4590