// File: FreeSlave[P]vhlt/hlrad/qradutil.cpp
// Function: PointInLeaf_Worst_r(int, float const*)
dleaf_t*		PointInLeaf_Worst_r(int nodenum, const vec3_t point)
{
	vec_t			dist;
	dnode_t*		node;
	dplane_t*		plane;

	while (nodenum >= 0)
	{
		node = &g_dnodes[nodenum];
		plane = &g_dplanes[node->planenum];
		dist = DotProduct(point, plane->normal) - plane->dist;
		if (dist > HUNT_WALL_EPSILON)
		{
			nodenum = node->children[0];
		}
		else if (dist < -HUNT_WALL_EPSILON)
		{
			nodenum = node->children[1];
		}
		else
		{
			dleaf_t* result[2];
			result[0] = PointInLeaf_Worst_r(node->children[0], point);
			result[1] = PointInLeaf_Worst_r(node->children[1], point);
			if (result[0] == g_dleafs || result[0]->contents == CONTENTS_SOLID)
				return result[0];
			if (result[1] == g_dleafs || result[1]->contents == CONTENTS_SOLID)
				return result[1];
			if (result[0]->contents == CONTENTS_SKY)
				return result[0];
			if (result[1]->contents == CONTENTS_SKY)
				return result[1];
#ifdef HLRAD_WATERBLOCKLIGHT
			if (result[0]->contents == result[1]->contents)
				return result[0];
			return g_dleafs;
#else
			return result[0];
#endif
		}
	}

	return &g_dleafs[-nodenum - 1];
}

// Assembly:
subq $0x48, %rsp
movl %edi, 0x3c(%rsp)
movq %rsi, 0x30(%rsp)
cmpl $0x0, 0x3c(%rsp)
jl 0x5cc09
movslq 0x3c(%rsp), %rcx
leaq 0x10c99ac(%rip), %rax   # 0x1126410
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movslq (%rax), %rcx
leaq 0xb09981(%rip), %rax    # 0xb66400
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movss (%rax), %xmm1
movq 0x18(%rsp), %rax
movss (%rax), %xmm2
movq 0x30(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x18(%rsp), %rax
mulss 0x4(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x30(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x18(%rsp), %rax
movss 0x8(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x18(%rsp), %rax
subss 0xc(%rax), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x14d89(%rip), %xmm1    # 0x71880
ucomisd %xmm1, %xmm0
jbe 0x5cb0f
movq 0x20(%rsp), %rax
movswl 0x4(%rax), %eax
movl %eax, 0x3c(%rsp)
jmp 0x5cc04
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x14d67(%rip), %xmm0    # 0x71888
ucomisd %xmm1, %xmm0
jbe 0x5cb39
movq 0x20(%rsp), %rax
movswl 0x6(%rax), %eax
movl %eax, 0x3c(%rsp)
jmp 0x5cc02
movq 0x20(%rsp), %rax
movswl 0x4(%rax), %edi
movq 0x30(%rsp), %rsi
callq 0x5ca40
movq %rax, (%rsp)
movq 0x20(%rsp), %rax
movswl 0x6(%rax), %edi
movq 0x30(%rsp), %rsi
callq 0x5ca40
movq %rax, 0x8(%rsp)
leaq 0xa29961(%rip), %rax    # 0xa864d0
cmpq %rax, (%rsp)
je 0x5cb7e
movq (%rsp), %rax
cmpl $-0x2, (%rax)
jne 0x5cb8c
movq (%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5cc28
leaq 0xa2993d(%rip), %rax    # 0xa864d0
cmpq %rax, 0x8(%rsp)
je 0x5cba4
movq 0x8(%rsp), %rax
cmpl $-0x2, (%rax)
jne 0x5cbb0
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5cc28
movq (%rsp), %rax
cmpl $-0x6, (%rax)
jne 0x5cbc4
movq (%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5cc28
movq 0x8(%rsp), %rax
cmpl $-0x6, (%rax)
jne 0x5cbda
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5cc28
movq (%rsp), %rax
movl (%rax), %eax
movq 0x8(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x5cbf4
movq (%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5cc28
leaq 0xa298d5(%rip), %rax    # 0xa864d0
movq %rax, 0x40(%rsp)
jmp 0x5cc28
jmp 0x5cc04
jmp 0x5ca4d
xorl %eax, %eax
subl 0x3c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xa298b4(%rip), %rax    # 0xa864d0
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)