// File: FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: MLH_AddSample(mdllight_t*, int, int, int, int, int, float const*)
void MLH_AddSample (mdllight_t *ml, int facenum, int w, int h, int s, int t, const vec3_t pos)
{
	dface_t *f = &g_dfaces[facenum];
	int i, j;
	int r = MLH_AddFace (ml, facenum);
	if (r == -1)
	{
		return;
	}
	int size = w * h;
	int num = s + w * t;
	for (i = 0; i < ml->face[r].samplecount; i++)
	{
		if (ml->face[r].sample[i].num == num)
		{
			return;
		}
	}
	if (ml->face[r].samplecount >= MLH_MAXSAMPLECOUNT)
	{
		return;
	}
	i = ml->face[r].samplecount;
	ml->face[r].samplecount++;
	ml->face[r].sample[i].num = num;
	VectorCopy (pos, ml->face[r].sample[i].pos);
	for (j = 0; j < ALLSTYLES; j++)
	{
		if (ml->face[r].style[j].exist)
		{
			ml->face[r].sample[i].style[j] = &g_dlightdata[f->lightofs + (num + size * ml->face[r].style[j].seq) * 3];
		}
	}
}

// Assembly:
subq $0x48, %rsp
movq 0x50(%rsp), %rax
movq %rdi, 0x40(%rsp)
movl %esi, 0x3c(%rsp)
movl %edx, 0x38(%rsp)
movl %ecx, 0x34(%rsp)
movl %r8d, 0x30(%rsp)
movl %r9d, 0x2c(%rsp)
movslq 0x3c(%rsp), %rcx
leaq 0x1ba6600(%rip), %rax   # 0x1be6410
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rdi
movl 0x3c(%rsp), %esi
callq 0x3fbf0
movl %eax, 0x14(%rsp)
cmpl $-0x1, 0x14(%rsp)
jne 0x3fe3a
jmp 0x400f1
movl 0x38(%rsp), %eax
imull 0x34(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x30(%rsp), %eax
movl 0x38(%rsp), %ecx
imull 0x2c(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x40(%rsp), %rcx
addq $0x18, %rcx
movslq 0x14(%rsp), %rdx
imulq $0xa50, %rdx, %rdx      # imm = 0xA50
addq %rdx, %rcx
cmpl 0xa48(%rcx), %eax
jge 0x3fecf
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
addq $0x208, %rax            # imm = 0x208
movslq 0x1c(%rsp), %rcx
imulq $0x210, %rcx, %rcx      # imm = 0x210
addq %rcx, %rax
movl (%rax), %eax
cmpl 0xc(%rsp), %eax
jne 0x3fec0
jmp 0x400f1
jmp 0x3fec2
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x3fe62
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
cmpl $0x4, 0xa48(%rax)
jl 0x3fef5
jmp 0x400f1
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
movl 0xa48(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
movl 0xa48(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xa48(%rax)
movl 0xc(%rsp), %ecx
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rdx
imulq $0xa50, %rdx, %rdx      # imm = 0xA50
addq %rdx, %rax
addq $0x208, %rax            # imm = 0x208
movslq 0x1c(%rsp), %rdx
imulq $0x210, %rdx, %rdx      # imm = 0x210
addq %rdx, %rax
movl %ecx, (%rax)
movq 0x50(%rsp), %rax
movss (%rax), %xmm0
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
addq $0x208, %rax            # imm = 0x208
movslq 0x1c(%rsp), %rcx
imulq $0x210, %rcx, %rcx      # imm = 0x210
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
movq 0x50(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
addq $0x208, %rax            # imm = 0x208
movslq 0x1c(%rsp), %rcx
imulq $0x210, %rcx, %rcx      # imm = 0x210
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movq 0x50(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
addq $0x208, %rax            # imm = 0x208
movslq 0x1c(%rsp), %rcx
imulq $0x210, %rcx, %rcx      # imm = 0x210
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
movl $0x0, 0x18(%rsp)
cmpl $0x40, 0x18(%rsp)
jge 0x400f1
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
movslq 0x18(%rsp), %rcx
testb $0x1, 0x4(%rax,%rcx,8)
je 0x400df
leaq 0x846432(%rip), %rax    # 0x886498
movq (%rax), %rdx
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %esi
movq 0x40(%rsp), %rdi
addq $0x18, %rdi
movslq 0x14(%rsp), %r8
imulq $0xa50, %r8, %r8        # imm = 0xA50
addq %r8, %rdi
movslq 0x18(%rsp), %r8
imull 0x8(%rdi,%r8,8), %esi
addl %esi, %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
cltq
addq %rax, %rdx
movq 0x40(%rsp), %rax
addq $0x18, %rax
movslq 0x14(%rsp), %rcx
imulq $0xa50, %rcx, %rcx      # imm = 0xA50
addq %rcx, %rax
addq $0x208, %rax            # imm = 0x208
movslq 0x1c(%rsp), %rcx
imulq $0x210, %rcx, %rcx      # imm = 0x210
addq %rcx, %rax
movslq 0x18(%rsp), %rcx
movq %rdx, 0x10(%rax,%rcx,8)
jmp 0x400e1
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x4002c
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)