// File: FreeSlave[P]vhlt/hlbsp/solidbsp.cpp
// Function: TestSurfaceTree_r(surfacetree_t*, surfacetreenode_s const*, plane_t const*)
void TestSurfaceTree_r (surfacetree_t *tree, const surfacetreenode_t *node, const dplane_t *split)
{
	if (node->size == 0)
	{
		return;
	}
	vec_t low, high;
	low = high = -split->dist;
	for (int k = 0; k < 3; k++)
	{
		if (split->normal[k] >= 0)
		{
			high += split->normal[k] * node->maxs[k];
			low += split->normal[k] * node->mins[k];
		}
		else
		{
			high += split->normal[k] * node->mins[k];
			low += split->normal[k] * node->maxs[k];
		}
	}
	if (low > tree->epsilon)
	{
		tree->result.frontsize += node->size;
#ifdef HLCSG_HLBSP_SOLIDHINT
		tree->result.frontsize -= node->size_discardable;
#endif
		return;
	}
	if (high < -tree->epsilon)
	{
		tree->result.backsize += node->size;
#ifdef HLCSG_HLBSP_SOLIDHINT
		tree->result.backsize -= node->size_discardable;
#endif
		return;
	}
	if (node->isleaf)
	{
		for (std::vector< face_t * >::iterator i = node->leaffaces->begin (); i != node->leaffaces->end (); ++i)
		{
			tree->result.middle->push_back (*i);
		}
	}
	else
	{
		for (std::vector< face_t * >::iterator i = node->nodefaces->begin (); i != node->nodefaces->end (); ++i)
		{
			tree->result.middle->push_back (*i);
		}
		TestSurfaceTree_r (tree, node->children[0], split);
		TestSurfaceTree_r (tree, node->children[1], split);
	}
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq 0x58(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x2a682
jmp 0x2a969
movq 0x50(%rsp), %rax
movsd 0x30(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x48(%rsp)
movl $0x0, 0x3c(%rsp)
cmpl $0x3, 0x3c(%rsp)
jge 0x2a7ba
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2a742
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x58(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd 0x20(%rax,%rcx,8), %xmm2
movsd 0x40(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x58(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x2a7a8
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x58(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm2
movsd 0x40(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x58(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd 0x20(%rax,%rcx,8), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x2a7aa
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x2a6b7
movsd 0x48(%rsp), %xmm0
movq 0x60(%rsp), %rax
ucomisd 0x8(%rax), %xmm0
jbe 0x2a7f8
movq 0x58(%rsp), %rax
movl (%rax), %ecx
movq 0x60(%rsp), %rax
addl 0x18(%rax), %ecx
movl %ecx, 0x18(%rax)
movq 0x58(%rsp), %rax
movl 0x4(%rax), %edx
movq 0x60(%rsp), %rax
movl 0x18(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x18(%rax)
jmp 0x2a969
movsd 0x40(%rsp), %xmm1
movq 0x60(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2a851
movq 0x58(%rsp), %rax
movl (%rax), %ecx
movq 0x60(%rsp), %rax
addl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rax)
movq 0x58(%rsp), %rax
movl 0x4(%rax), %edx
movq 0x60(%rsp), %rax
movl 0x1c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x2a969
movq 0x58(%rsp), %rax
testb $0x1, 0x38(%rax)
je 0x2a8cd
movq 0x58(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x2e400
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x2e470
movq %rax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2e430
testb $0x1, %al
jne 0x2a897
jmp 0x2a8c8
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x2e4a0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x2e4e0
leaq 0x30(%rsp), %rdi
callq 0x2e4b0
jmp 0x2a86f
jmp 0x2a969
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rdi
callq 0x2e400
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rdi
callq 0x2e470
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2e430
testb $0x1, %al
jne 0x2a908
jmp 0x2a939
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x2e4a0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x2e4e0
leaq 0x20(%rsp), %rdi
callq 0x2e4b0
jmp 0x2a8e0
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x50(%rsp), %rdx
callq 0x2a660
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x48(%rax), %rsi
movq 0x50(%rsp), %rdx
callq 0x2a660
addq $0x68, %rsp
retq
nop