// File: FreeSlave[P]vhlt/hlrad/loadtextures.cpp
// Function: CQ_MapPoint_r(int*, int*, cq_searchnode_s*, unsigned char const (*) [3], unsigned char const*, int)
static void CQ_MapPoint_r (int *bestdist, int *best,
					cq_searchnode_t *node, const unsigned char (*colors)[CQ_DIM],
					const unsigned char point[CQ_DIM], int searchradius)
{
	while (!node->isleafnode)
	{
		int dist = point[node->planeaxis] - node->planedist;
		if (dist <= -searchradius)
		{
			node = node->childrennode[0];
		}
		else if (dist >= searchradius - 1)
		{
			node = node->childrennode[1];
		}
		else
		{
			CQ_MapPoint_r (bestdist, best, node->childrennode[0], colors, point, searchradius);
			CQ_MapPoint_r (bestdist, best, node->childrennode[1], colors, point, searchradius);
			return;
		}
	}
	int dist = 0;
	for (int k = 0; k < CQ_DIM; k++)
	{
		dist += (colors[node->result][k] - point[k]) * (colors[node->result][k] - point[k]);
	}
	if (dist <= *bestdist)
	{
		if (dist < *bestdist || node->result < *best)
		{
			*bestdist = dist;
			*best = node->result;
		}
	}
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movl %r9d, 0xc(%rsp)
movq 0x20(%rsp), %rax
movb (%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x499f4
jmp 0x49aa9
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movslq 0x18(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq 0x20(%rsp), %rcx
subl 0x1c(%rcx), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
xorl %ecx, %ecx
subl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jg 0x49a30
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x49aa4
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x49a4f
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x49aa2
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
movl 0xc(%rsp), %r9d
callq 0x499c0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
movl 0xc(%rsp), %r9d
callq 0x499c0
jmp 0x49b73
jmp 0x49aa4
jmp 0x499e2
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
cmpl $0x3, (%rsp)
jge 0x49b2c
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movslq 0x20(%rcx), %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movslq (%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x10(%rsp), %rcx
movslq (%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movslq 0x20(%rdx), %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rcx
movslq (%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
movq 0x10(%rsp), %rdx
movslq (%rsp), %rsi
movzbl (%rdx,%rsi), %edx
subl %edx, %ecx
imull %ecx, %eax
addl 0x4(%rsp), %eax
movl %eax, 0x4(%rsp)
movl (%rsp), %eax
addl $0x1, %eax
movl %eax, (%rsp)
jmp 0x49ab8
movl 0x4(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jg 0x49b73
movl 0x4(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jl 0x49b57
movq 0x20(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x49b71
movl 0x4(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax)
movq 0x20(%rsp), %rax
movl 0x20(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
jmp 0x49b73
addq $0x38, %rsp
retq
nopl (%rax,%rax)