// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq (%rdi), %r12
testq %r12, %r12
je 0x327a0
movq (%rsi), %rcx
testq %rcx, %rcx
je 0x327a0
movq %rdi, %rbx
movss 0x14(%rsi), %xmm0
subss 0x14(%rdi), %xmm0
andps 0x7e9c(%rip), %xmm0     # 0x3a340
cvtss2sd %xmm0, %xmm0
ucomisd 0x8148(%rip), %xmm0     # 0x3a5f8
ja 0x327a0
movss 0x8(%rsi), %xmm1
movss 0x8(%rbx), %xmm0
subss %xmm0, %xmm1
andps 0x7e75(%rip), %xmm1     # 0x3a340
cvtss2sd %xmm1, %xmm1
ucomisd 0x4c41(%rip), %xmm1     # 0x37118
ja 0x327a0
movss 0xc(%rsi), %xmm2
movss 0xc(%rbx), %xmm1
subss %xmm1, %xmm2
andps 0x7e4e(%rip), %xmm2     # 0x3a340
cvtss2sd %xmm2, %xmm2
ucomisd 0x4c1a(%rip), %xmm2     # 0x37118
ja 0x327a0
movss 0x10(%rsi), %xmm3
movss 0x10(%rbx), %xmm2
subss %xmm2, %xmm3
andps 0x7e27(%rip), %xmm3     # 0x3a340
cvtss2sd %xmm3, %xmm3
ucomisd 0x4bf3(%rip), %xmm3     # 0x37118
ja 0x327a0
cmpb $0x0, 0x2c(%rbx)
jne 0x32537
cmpb $0x1, 0x2c(%rsi)
jne 0x32543
movl 0x28(%rbx), %eax
cmpl 0x28(%rsi), %eax
jne 0x327a0
movl 0x8(%r12), %edi
testq %rdi, %rdi
movq %rcx, 0x18(%rsp)
je 0x32787
movl 0x8(%rcx), %r8d
leal -0x1(%r8), %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x20(%rsp)
leal -0x2(,%r8,2), %eax
movl %eax, 0x2c(%rsp)
leal 0x1(%r8), %eax
movl %eax, 0x28(%rsp)
movl $0x4, %r10d
movaps 0x7db4(%rip), %xmm3     # 0x3a340
movsd 0x8514(%rip), %xmm4     # 0x3aaa8
xorl %r13d, %r13d
movq %rdi, (%rsp)
movl $0x0, %r15d
testq %r8, %r8
je 0x3276e
movq 0x10(%r12), %rsi
leaq (,%r13,2), %rax
addq %r13, %rax
leaq (%rsi,%rax,4), %rax
movq 0x10(%rcx), %rcx
movq %rax, 0x30(%rsp)
movss (%rax), %xmm5
leaq 0x1(%r13), %rax
movq 0x20(%rsp), %rdx
addq %rcx, %rdx
movq %rdx, 0x8(%rsp)
cmpq %rdi, %rax
movl %eax, %eax
movl $0x0, %edx
cmoveq %rdx, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsi,%rax,4), %rax
leaq (%rsi,%r10), %rdx
leaq 0x4(%rcx), %r11
movq %r11, %r9
xorl %ebp, %ebp
movq %rbp, %r15
incq %rbp
cmpq %r8, %rbp
movl %ebp, %edi
movl $0x0, %r14d
cmovneq %rdi, %r14
leaq (%r14,%r14,2), %rdi
movaps %xmm5, %xmm6
subss (%rcx,%rdi,4), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
ucomisd %xmm4, %xmm6
ja 0x326b9
leaq (%r15,%r15,2), %r14
leaq (%rcx,%r14,4), %r14
movq %r14, 0x10(%rsp)
leaq (%r11,%rdi,4), %r14
xorl %edi, %edi
cmpq $0x2, %rdi
je 0x3266e
movss (%rdx,%rdi,4), %xmm6
subss (%r14,%rdi,4), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
incq %rdi
ucomisd %xmm4, %xmm6
jbe 0x32644
decq %rdi
cmpq $0x2, %rdi
jb 0x326b9
movss (%rax), %xmm6
movq 0x10(%rsp), %rdi
subss (%rdi), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
ucomisd %xmm4, %xmm6
ja 0x326b9
xorl %edi, %edi
cmpq $0x2, %rdi
je 0x3271f
movss 0x4(%rax,%rdi,4), %xmm6
subss (%r9,%rdi,4), %xmm6
andps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
incq %rdi
ucomisd %xmm4, %xmm6
jbe 0x3268a
decq %rdi
cmpq $0x1, %rdi
ja 0x3271f
addq $0xc, %r9
cmpq %r8, %rbp
jne 0x325ff
movq (%rsp), %rdi
leal (%rdi,%r13), %eax
decl %eax
xorl %edx, %edx
divl %edi
leaq (%rdx,%rdx,2), %rax
leaq (%rsi,%rax,4), %r11
leal 0x2(%r13), %eax
xorl %edx, %edx
divl %edi
leaq (%rdx,%rdx,2), %rax
leaq (%rsi,%rax,4), %r9
movl 0x2c(%rsp), %eax
xorl %edx, %edx
divl %r8d
leaq (%rdx,%rdx,2), %rax
leaq (%rcx,%rax,4), %rsi
movl 0x28(%rsp), %eax
xorl %edx, %edx
divl %r8d
leaq (%rdx,%rdx,2), %rax
leaq (%rcx,%rax,4), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rsp), %rcx
jmp 0x32773
movq (%rsp), %rdi
leal (%rdi,%r13), %eax
decl %eax
xorl %edx, %edx
divl %edi
leaq (%rdx,%rdx,2), %rax
leaq (%rsi,%rax,4), %r11
leal 0x2(%r13), %eax
xorl %edx, %edx
divl %edi
leaq (%rdx,%rdx,2), %rax
leaq (%rsi,%rax,4), %r9
leal (%r15,%r8), %eax
decl %eax
xorl %edx, %edx
divl %r8d
leaq (%rdx,%rdx,2), %rax
leaq (%rcx,%rax,4), %rsi
leal 0x2(%r15), %eax
xorl %edx, %edx
divl %r8d
leaq (%rdx,%rdx,2), %rax
leaq (%rcx,%rax,4), %rax
movq 0x18(%rsp), %rcx
cmpl %r8d, %r15d
jne 0x3278c
incq %r13
addq $0xc, %r10
xorl %ebp, %ebp
cmpq %rdi, %r13
jne 0x3259b
jmp 0x327a2
xorl %r13d, %r13d
jmp 0x3279b
movq %r9, 0x20(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x30(%rsp), %r14
cmpl %edi, %r13d
jne 0x327b3
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movss 0x4(%rax), %xmm3
subss 0x4(%r11), %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 (%r11), %xmm5
movss 0x8(%r11), %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 0x50(%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 %r11, %rbp
callq 0x33bf7
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x32839
jp 0x32839
leaq 0xc402(%rip), %rsi      # 0x3ec28
xorl %ebp, %ebp
movl $0x2, %edi
xorl %eax, %eax
callq 0xa446
jmp 0x327a2
movss 0x50(%rsp), %xmm0
movss 0x54(%rsp), %xmm1
movss 0x4(%rbp), %xmm2
mulss %xmm1, %xmm2
movss (%rbp), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x58(%rsp), %xmm2
movss 0x8(%rbp), %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x5c(%rsp)
mulss 0x4(%r14), %xmm1
mulss (%r14), %xmm0
addss %xmm1, %xmm0
mulss 0x8(%r14), %xmm2
addss %xmm0, %xmm2
subss %xmm4, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x7d50(%rip), %xmm1     # 0x3a5f0
ucomisd %xmm0, %xmm1
ja 0x327a0
movsd %xmm0, (%rsp)
movq 0x20(%rsp), %rax
movss 0x4(%rax), %xmm1
movq 0x8(%rsp), %rbp
subss 0x4(%rbp), %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 (%rbp), %xmm2
movss 0x8(%rbp), %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 0x38(%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 0x33bf7
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x32933
jnp 0x3281f
movss 0x38(%rsp), %xmm0
movss 0x3c(%rsp), %xmm1
movss 0x4(%rbp), %xmm2
mulss %xmm1, %xmm2
movss (%rbp), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x40(%rsp), %xmm2
movss 0x8(%rbp), %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x44(%rsp)
movq 0x10(%rsp), %rax
mulss 0x4(%rax), %xmm1
mulss (%rax), %xmm0
addss %xmm1, %xmm0
mulss 0x8(%rax), %xmm2
addss %xmm0, %xmm2
subss %xmm4, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
movsd 0x7c54(%rip), %xmm0     # 0x3a5f0
ucomisd %xmm1, %xmm0
ja 0x327a0
movsd 0x7c4a(%rip), %xmm0     # 0x3a5f8
xorl %ebp, %ebp
movsd (%rsp), %xmm2
ucomisd %xmm0, %xmm2
seta %bpl
xorl %eax, %eax
movsd %xmm1, 0x8(%rsp)
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x10(%rsp)
movl $0x20, %edi
callq 0x42e0
movq %rax, %r14
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
addl 0x10(%rsp), %ebp
addl 0x8(%r12), %ebp
leal (%rax,%rbp), %esi
addl $-0x4, %esi
movq %r14, %rdi
callq 0xc1a6
leal 0x2(%r13), %eax
xorl %ecx, %ecx
xorl %edx, %edx
divl 0x8(%r12)
cmpl %r13d, %edx
je 0x32a72
xorl %ecx, %ecx
xorl %esi, %esi
movq 0x10(%r12), %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(%r12), %rdi
movss 0x4(%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdi
movss %xmm0, 0x4(%rdi,%rsi)
movq 0x10(%r12), %rdi
movss 0x8(%rdi,%rdx), %xmm0
movq 0x10(%r14), %rdx
movss %xmm0, 0x8(%rdx,%rsi)
incl %eax
xorl %edx, %edx
divl 0x8(%r12)
addq $0xc, %rsi
incl %ecx
cmpl %r13d, %edx
jne 0x32a12
movsd (%rsp), %xmm0
ucomisd 0x7b79(%rip), %xmm0     # 0x3a5f8
movq 0x18(%rsp), %r8
movsd 0x8(%rsp), %xmm1
jbe 0x32ae0
movq 0x10(%r12), %rax
movslq %r13d, %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(%r12), %rax
movss 0x4(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x4(%rax,%rsi)
movq 0x10(%r12), %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(%r8)
cmpl %r15d, %edx
je 0x32b56
movslq %ecx, %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
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 %r15d, %edx
jne 0x32afa
ucomisd 0x7a9a(%rip), %xmm1     # 0x3a5f8
jbe 0x32bb0
movq 0x10(%r8), %rax
movslq %r15d, %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(%r8), %rax
movss 0x4(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x4(%rax,%rcx)
movq 0x10(%r8), %rax
movss 0x8(%rax,%rdx), %xmm0
movq 0x10(%r14), %rax
movss %xmm0, 0x8(%rax,%rcx)
movss 0x7e7c(%rip), %xmm0     # 0x3aa34
movq %r14, %rdi
callq 0xc628
cmpl $0x2, 0x8(%r14)
ja 0x32be6
leaq 0xc07a(%rip), %rsi      # 0x3ec48
movl $0x2, %edi
xorl %eax, %eax
callq 0xa446
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
xorl %r14d, %r14d
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x32bf4
movq (%rdi), %rax
callq *0x8(%rax)
movq %r14, (%rbx)
movb $0x1, %bpl
jmp 0x327a2
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4580