// File: FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: MLH_GetSamples_r(mdllight_t*, int, float const*, float const*)
void MLH_GetSamples_r (mdllight_t *ml, int nodenum, const float *start, const float *end)
{
	if (nodenum < 0)
		return;
	dnode_t *node = &g_dnodes[nodenum];
	dplane_t *plane;
	float front, back, frac;
	float mid[3];
	int side;
	plane = &g_dplanes[node->planenum];
	front = DotProduct (start, plane->normal) - plane->dist;
	back = DotProduct (end, plane->normal) - plane->dist;
	side = front < 0;
	if ((back < 0) == side)
	{
		MLH_GetSamples_r (ml, node->children[side], start, end);
		return;
	}
	frac = front / (front - back);
	mid[0] = start[0] + (end[0] - start[0]) * frac;
	mid[1] = start[1] + (end[1] - start[1]) * frac;
	mid[2] = start[2] + (end[2] - start[2]) * frac;
	MLH_GetSamples_r (ml, node->children[side], start, mid);
	if (ml->facecount > 0)
	{
		return;
	}
	{
		int i;
		for (i = 0; i < node->numfaces; i++)
		{
			dface_t *f = &g_dfaces[node->firstface + i];
			texinfo_t *tex = &g_texinfo[f->texinfo];
			const char *texname = GetTextureByNumber (f->texinfo);
			if (!strncmp (texname, "sky", 3))
			{
				continue;
			}
			if (f->lightofs == -1)
			{
				continue;
			}
			int s = (int)(DotProduct (mid, tex->vecs[0]) + tex->vecs[0][3]);
			int t = (int)(DotProduct (mid, tex->vecs[1]) + tex->vecs[1][3]);
			int texturemins[2], extents[2];
			MLH_CalcExtents (f, texturemins, extents);
			if (s < texturemins[0] || t < texturemins[1])
			{
				continue;
			}
			int ds = s - texturemins[0];
			int dt = t - texturemins[1];
			if (ds > extents[0] || dt > extents[1])
			{
				continue;
			}
			ds >>= 4;
			dt >>= 4;
			MLH_AddSample (ml, node->firstface + i, extents[0] / TEXTURE_STEP + 1, extents[1] / TEXTURE_STEP + 1, ds, dt, mid);
			break;
		}
	}
	if (ml->facecount > 0)
	{
		VectorCopy (mid, ml->floor);
		return;
	}
	MLH_GetSamples_r (ml, node->children[!side], mid, end);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
cmpl $0x0, 0x8c(%rsp)
jge 0x401d2
jmp 0x406b6
movslq 0x8c(%rsp), %rcx
leaq 0x10e622f(%rip), %rax   # 0x1126410
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movslq (%rax), %rcx
leaq 0xb26204(%rip), %rax    # 0xb66400
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0x80(%rsp), %rax
movss (%rax), %xmm1
movq 0x68(%rsp), %rax
movss (%rax), %xmm2
movq 0x80(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x68(%rsp), %rax
mulss 0x4(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x80(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x68(%rsp), %rax
movss 0x8(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x68(%rsp), %rax
subss 0xc(%rax), %xmm0
movss %xmm0, 0x64(%rsp)
movq 0x78(%rsp), %rax
movss (%rax), %xmm1
movq 0x68(%rsp), %rax
movss (%rax), %xmm2
movq 0x78(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x68(%rsp), %rax
mulss 0x4(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x78(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x68(%rsp), %rax
movss 0x8(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x68(%rsp), %rax
subss 0xc(%rax), %xmm0
movss %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
ucomiss 0x64(%rsp), %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x4c(%rsp)
xorps %xmm0, %xmm0
ucomiss 0x60(%rsp), %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
cmpl 0x4c(%rsp), %eax
jne 0x4031d
movq 0x90(%rsp), %rdi
movq 0x70(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movswl 0x4(%rax,%rcx,2), %esi
movq 0x80(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x401a0
jmp 0x406b6
movss 0x64(%rsp), %xmm0
movss 0x64(%rsp), %xmm1
subss 0x60(%rsp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x5c(%rsp)
movq 0x80(%rsp), %rax
movss (%rax), %xmm1
movq 0x78(%rsp), %rax
movss (%rax), %xmm0
movq 0x80(%rsp), %rax
subss (%rax), %xmm0
movss 0x5c(%rsp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x50(%rsp)
movq 0x80(%rsp), %rax
movss 0x4(%rax), %xmm1
movq 0x78(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x80(%rsp), %rax
subss 0x4(%rax), %xmm0
movss 0x5c(%rsp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x54(%rsp)
movq 0x80(%rsp), %rax
movss 0x8(%rax), %xmm1
movq 0x78(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x80(%rsp), %rax
subss 0x8(%rax), %xmm0
movss 0x5c(%rsp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x58(%rsp)
movq 0x90(%rsp), %rdi
movq 0x70(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movswl 0x4(%rax,%rcx,2), %esi
movq 0x80(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x401a0
movq 0x90(%rsp), %rax
cmpl $0x0, 0xa518(%rax)
jle 0x4041d
jmp 0x406b6
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
movq 0x70(%rsp), %rcx
movzwl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x40638
movq 0x70(%rsp), %rax
movzwl 0x14(%rax), %eax
addl 0x48(%rsp), %eax
movslq %eax, %rcx
leaq 0x1ba5fbf(%rip), %rax   # 0x1be6410
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movswq 0xa(%rax), %rcx
leaq 0x11a5f92(%rip), %rax   # 0x11e6400
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movswl 0xa(%rax), %edi
callq 0x69d0
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x2f1c8(%rip), %rsi     # 0x6f661
movl $0x3, %edx
callq 0x4190
cmpl $0x0, %eax
jne 0x404ad
jmp 0x40628
movq 0x40(%rsp), %rax
cmpl $-0x1, 0x10(%rax)
jne 0x404bd
jmp 0x40628
movss 0x50(%rsp), %xmm1
movq 0x38(%rsp), %rax
movss (%rax), %xmm2
movss 0x54(%rsp), %xmm0
movq 0x38(%rsp), %rax
mulss 0x4(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
movq 0x38(%rsp), %rax
movss 0x8(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x38(%rsp), %rax
addss 0xc(%rax), %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0x2c(%rsp)
movss 0x50(%rsp), %xmm1
movq 0x38(%rsp), %rax
movss 0x10(%rax), %xmm2
movss 0x54(%rsp), %xmm0
movq 0x38(%rsp), %rax
mulss 0x14(%rax), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
movq 0x38(%rsp), %rax
movss 0x18(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x38(%rsp), %rax
addss 0x1c(%rax), %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0x28(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x40100
movl 0x2c(%rsp), %eax
cmpl 0x20(%rsp), %eax
jl 0x40588
movl 0x28(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x4058d
jmp 0x40628
movl 0x2c(%rsp), %eax
subl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x28(%rsp), %eax
subl 0x24(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x18(%rsp), %eax
jg 0x405b9
movl 0x10(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jle 0x405bb
jmp 0x40628
movl 0x14(%rsp), %eax
sarl $0x4, %eax
movl %eax, 0x14(%rsp)
movl 0x10(%rsp), %eax
sarl $0x4, %eax
movl %eax, 0x10(%rsp)
movq 0x90(%rsp), %rdi
movq 0x70(%rsp), %rax
movzwl 0x14(%rax), %esi
addl 0x48(%rsp), %esi
movl 0x18(%rsp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%rsp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl 0xc(%rsp), %edx
movl %eax, %ecx
addl $0x1, %ecx
movl 0x14(%rsp), %r8d
movl 0x10(%rsp), %r9d
leaq 0x50(%rsp), %rax
movq %rax, (%rsp)
callq 0x3fde0
jmp 0x40638
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x40425
movq 0x90(%rsp), %rax
cmpl $0x0, 0xa518(%rax)
jle 0x40684
movss 0x50(%rsp), %xmm0
movq 0x90(%rsp), %rax
movss %xmm0, 0xc(%rax)
movss 0x54(%rsp), %xmm0
movq 0x90(%rsp), %rax
movss %xmm0, 0x10(%rax)
movss 0x58(%rsp), %xmm0
movq 0x90(%rsp), %rax
movss %xmm0, 0x14(%rax)
jmp 0x406b6
movq 0x90(%rsp), %rdi
movq 0x70(%rsp), %rax
cmpl $0x0, 0x4c(%rsp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movswl 0x4(%rax,%rcx,2), %esi
leaq 0x50(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x401a0
addq $0x98, %rsp
retq
nop