// File: /workspace/github_cpp_makefile_star2_O1/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 0x21424
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %rbx
movq %rdi, %r14
movl %esi, %eax
leaq (%rax,%rax,2), %rax
leaq 0x10d0241(%rip), %rcx   # 0x10f1400
leaq (%rcx,%rax,8), %r15
movslq (%r15), %rax
leaq (%rax,%rax,4), %rax
leaq 0xb1021f(%rip), %rcx    # 0xb313f0
movss (%rcx,%rax,4), %xmm5
movss 0x4(%rcx,%rax,4), %xmm4
movss 0x8(%rdx), %xmm0
movss 0x8(%rcx,%rax,4), %xmm3
movss 0xc(%rcx,%rax,4), %xmm6
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 %al
ucomiss %xmm3, %xmm5
setbe %cl
cmpb %cl, %al
je 0x21275
xorl %eax, %eax
ucomiss %xmm8, %xmm5
seta %al
movswl 0x4(%r15,%rax,2), %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x21196
jmp 0x21416
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 0x10(%rsp), %rcx
movlps %xmm3, (%rcx)
addss %xmm0, %xmm4
movss %xmm4, 0x8(%rcx)
movswl 0x4(%r15,%rax,2), %esi
movq %r14, %rdi
movss %xmm8, 0x20(%rsp)
callq 0x21196
cmpl $0x0, 0xa518(%r14)
jg 0x21416
movq %r14, 0x28(%rsp)
movq %rbx, 0x40(%rsp)
cmpw $0x0, 0x16(%r15)
je 0x213f2
xorl %r12d, %r12d
leaq 0x1b9010a(%rip), %r14   # 0x1bb1400
leaq 0x1c3e0(%rip), %r13     # 0x3d6dd
movzwl 0x14(%r15), %eax
addq %r12, %rax
leaq (%rax,%rax,4), %rbx
movswl 0xa(%r14,%rbx,4), %ebp
movl %ebp, %edi
callq 0x637c
movl $0x3, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x4170
testl %eax, %eax
je 0x213e1
leaq (%r14,%rbx,4), %rdi
cmpl $-0x1, 0x10(%rdi)
je 0x213e1
movslq %ebp, %rax
leaq (%rax,%rax,4), %rax
shlq $0x3, %rax
addq 0x26c22(%rip), %rax     # 0x47f70
movss 0x10(%rsp), %xmm0
movss 0x14(%rsp), %xmm1
movss 0x4(%rax), %xmm2
mulss %xmm1, %xmm2
movss (%rax), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x18(%rsp), %xmm4
movss 0x8(%rax), %xmm2
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
addss 0xc(%rax), %xmm2
cvttss2si %xmm2, %ebp
mulss 0x14(%rax), %xmm1
mulss 0x10(%rax), %xmm0
mulss 0x18(%rax), %xmm4
addss %xmm1, %xmm0
addss %xmm0, %xmm4
addss 0x1c(%rax), %xmm4
movss %xmm4, 0x24(%rsp)
leaq 0x38(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x2113d
subl 0x38(%rsp), %ebp
jl 0x213e1
cvttss2si 0x24(%rsp), %r9d
subl 0x3c(%rsp), %r9d
jl 0x213e1
movl 0x30(%rsp), %ecx
cmpl %ecx, %ebp
jg 0x213e1
movl 0x34(%rsp), %eax
cmpl %eax, %r9d
jle 0x21447
movzwl 0x16(%r15), %eax
incq %r12
cmpl %eax, %r12d
jb 0x212fd
movq 0x28(%rsp), %rdi
cmpl $0x0, 0xa518(%rdi)
jle 0x21425
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xc(%rdi)
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x14(%rdi)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
xorl %eax, %eax
ucomiss 0x20(%rsp), %xmm0
setbe %al
movswl 0x4(%r15,%rax,2), %esi
leaq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
jmp 0x2126b
sarl $0x4, %ebp
sarl $0x4, %r9d
movzwl 0x14(%r15), %edx
addl %edx, %r12d
leal 0xf(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x4, %edx
incl %edx
leal 0xf(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x4, %ecx
incl %ecx
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %r8d
callq 0x2101b
jmp 0x213f2