// File: /workspace/github_cpp_makefile_star2_O2/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:
testl %esi, %esi
js 0x1d8d0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movq %rdi, %r14
movl %esi, %eax
imulq $0x18, %rax, %rax
leaq 0x10cfdce(%rip), %rcx   # 0x10ed410
movslq (%rcx,%rax), %rsi
imulq $0x14, %rsi, %rsi
leaq 0xb0fdaf(%rip), %rdi    # 0xb2d400
movss (%rdi,%rsi), %xmm5
movss 0x4(%rdi,%rsi), %xmm4
movss 0x8(%rdi,%rsi), %xmm3
movss 0xc(%rdi,%rsi), %xmm6
movss 0x8(%rdx), %xmm0
movsd (%rdx), %xmm1
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
mulss %xmm4, %xmm2
movaps %xmm1, %xmm7
mulss %xmm5, %xmm7
addss %xmm2, %xmm7
movaps %xmm0, %xmm8
mulss %xmm3, %xmm8
addss %xmm7, %xmm8
subss %xmm6, %xmm8
movsd (%rbx), %xmm2
movaps %xmm2, %xmm7
shufps $0x55, %xmm2, %xmm7     # xmm7 = xmm7[1,1],xmm2[1,1]
mulss %xmm4, %xmm7
mulss %xmm2, %xmm5
addss %xmm7, %xmm5
movss 0x8(%rbx), %xmm4
mulss %xmm4, %xmm3
addss %xmm5, %xmm3
subss %xmm6, %xmm3
xorps %xmm5, %xmm5
ucomiss %xmm8, %xmm5
seta %sil
ucomiss %xmm3, %xmm5
leaq (%rcx,%rax), %rbp
setbe %al
cmpb %al, %sil
je 0x1d6fa
xorl %eax, %eax
ucomiss %xmm8, %xmm5
seta %al
movswl 0x4(%rbp,%rax,2), %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x1d619
jmp 0x1d8c2
xorl %eax, %eax
ucomiss %xmm8, %xmm5
seta %al
movaps %xmm8, %xmm5
subss %xmm3, %xmm5
movaps %xmm8, %xmm3
divss %xmm5, %xmm3
subps %xmm1, %xmm2
subss %xmm0, %xmm4
mulss %xmm3, %xmm4
unpcklps %xmm3, %xmm3            # xmm3 = xmm3[0,0,1,1]
mulps %xmm2, %xmm3
addps %xmm1, %xmm3
leaq 0x8(%rsp), %rcx
movlps %xmm3, (%rcx)
addss %xmm0, %xmm4
movss %xmm4, 0x8(%rcx)
movswl 0x4(%rbp,%rax,2), %esi
movq %r14, %rdi
movss %xmm8, 0x18(%rsp)
callq 0x1d619
cmpl $0x0, 0xa518(%r14)
jg 0x1d8c2
movq %r14, 0x20(%rsp)
xorl %r12d, %r12d
leaq 0x1b8fca7(%rip), %r14   # 0x1bad410
movzwl 0x16(%rbp), %eax
cmpl %eax, %r12d
jae 0x1d89e
movzwl 0x14(%rbp), %eax
addq %r12, %rax
imulq $0x14, %rax, %r13
movswl 0xa(%r14,%r13), %r15d
movl %r15d, %edi
callq 0x5c29
cmpb $0x73, (%rax)
jne 0x1d7a4
cmpb $0x6b, 0x1(%rax)
jne 0x1d7a4
cmpb $0x79, 0x2(%rax)
je 0x1d859
addq %r14, %r13
cmpl $-0x1, 0x10(%r13)
je 0x1d859
movslq %r15d, %rax
imulq $0x28, %rax, %rax
addq 0x267b0(%rip), %rax     # 0x43f70
movss 0x8(%rsp), %xmm0
movss 0xc(%rsp), %xmm1
movss 0x4(%rax), %xmm2
mulss %xmm1, %xmm2
movss (%rax), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x10(%rsp), %xmm4
movss 0x8(%rax), %xmm2
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
addss 0xc(%rax), %xmm2
cvttss2si %xmm2, %r15d
mulss 0x14(%rax), %xmm1
mulss 0x10(%rax), %xmm0
mulss 0x18(%rax), %xmm4
addss %xmm1, %xmm0
addss %xmm0, %xmm4
addss 0x1c(%rax), %xmm4
movss %xmm4, 0x1c(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x1d5bb
subl 0x30(%rsp), %r15d
jl 0x1d859
cvttss2si 0x1c(%rsp), %r9d
subl 0x34(%rsp), %r9d
jl 0x1d859
movl 0x28(%rsp), %eax
cmpl %eax, %r15d
jg 0x1d859
movl 0x2c(%rsp), %ecx
cmpl %ecx, %r9d
jle 0x1d861
incq %r12
jmp 0x1d769
sarl $0x4, %r15d
sarl $0x4, %r9d
movzwl 0x14(%rbp), %edx
addl %edx, %r12d
pushq $0x10
popq %rsi
cltd
idivl %esi
leal 0x1(%rax), %r8d
movl %ecx, %eax
cltd
idivl %esi
leal 0x1(%rax), %ecx
leaq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r8d, %edx
movl %r15d, %r8d
callq 0x1d484
movq 0x20(%rsp), %rdi
cmpl $0x0, 0xa518(%rdi)
jle 0x1d8d1
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xc(%rdi)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x14(%rdi)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
xorl %eax, %eax
ucomiss 0x18(%rsp), %xmm0
setbe %al
movswl 0x4(%rbp,%rax,2), %esi
leaq 0x8(%rsp), %rdx
jmp 0x1d6ed