// File: FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: CreateFacelightDependencyList()
void CreateFacelightDependencyList ()
{
	int facenum;
	dface_t *f;
	facelight_t *fl;
	int i;
	int k;
	int surface;
	facelightlist_t *item;

	for (i = 0; i < MAX_MAP_FACES; i++)
	{
		g_dependentfacelights[i] = NULL;
	}

	// for each face
	for (facenum = 0; facenum < g_numfaces; facenum++)
	{
		f = &g_dfaces[facenum];
		fl = &facelight[facenum];
		if (g_texinfo[f->texinfo].flags & TEX_SPECIAL)
		{
			continue;
		}

		for (k = 0; k < MAXLIGHTMAPS && f->styles[k] != 255; k++)
		{
			for (i = 0; i < fl->numsamples; i++)
			{
				surface = fl->samples[k][i].surface; // that surface contains at least one sample from this face
				if (0 <= surface && surface < g_numfaces)
				{
					// insert this face into the dependency list of that surface
					for (item = g_dependentfacelights[surface]; item != NULL; item = item->next)
					{
						if (item->facenum == facenum)
							break;
					}
					if (item)
					{
						continue;
					}

					item = (facelightlist_t *)malloc (sizeof (facelightlist_t));
					hlassume (item != NULL, assume_NoMemory);
					item->facenum = facenum;
					item->next = g_dependentfacelights[surface];
					g_dependentfacelights[surface] = item;
				}
			}
		}
	}
}

// Assembly:
subq $0x38, %rsp
movl $0x0, 0x1c(%rsp)
cmpl $0xffff, 0x1c(%rsp)     # imm = 0xFFFF
jge 0x40dd7
movslq 0x1c(%rsp), %rcx
leaq 0x51e6bee(%rip), %rax   # 0x52279b0
movq $0x0, (%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x40dac
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
leaq 0x1ba561a(%rip), %rcx   # 0x1be6404
cmpl (%rcx), %eax
jge 0x40fc0
movslq 0x34(%rsp), %rcx
leaq 0x1ba5612(%rip), %rax   # 0x1be6410
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movslq 0x34(%rsp), %rcx
leaq 0x4f66bba(%rip), %rax   # 0x4fa79d0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movswq 0xa(%rax), %rcx
leaq 0x11a55cd(%rip), %rax   # 0x11e6400
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x40e4a
jmp 0x40fb0
movl $0x0, 0x18(%rsp)
xorl %eax, %eax
cmpl $0x4, 0x18(%rsp)
movb %al, 0x7(%rsp)
jge 0x40e7a
movq 0x28(%rsp), %rax
movslq 0x18(%rsp), %rcx
movzbl 0xc(%rax,%rcx), %eax
cmpl $0xff, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x40e87
jmp 0x40fae
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x40f9c
movq 0x20(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movslq 0x1c(%rsp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, 0x14(%rsp)
xorl %eax, %eax
cmpl 0x14(%rsp), %eax
jg 0x40f8a
movl 0x14(%rsp), %eax
leaq 0x1ba552b(%rip), %rcx   # 0x1be6404
cmpl (%rcx), %eax
jge 0x40f8a
movslq 0x14(%rsp), %rcx
leaq 0x51e6ac3(%rip), %rax   # 0x52279b0
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
je 0x40f1f
movq 0x8(%rsp), %rax
movl (%rax), %eax
cmpl 0x34(%rsp), %eax
jne 0x40f0d
jmp 0x40f1f
jmp 0x40f0f
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x40ef6
cmpq $0x0, 0x8(%rsp)
je 0x40f29
jmp 0x40f8c
movl $0x10, %edi
callq 0x4430
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbf00
movl 0x34(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movslq 0x14(%rsp), %rcx
leaq 0x51e6a48(%rip), %rax   # 0x52279b0
movq (%rax,%rcx,8), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rdx
movslq 0x14(%rsp), %rcx
leaq 0x51e6a2a(%rip), %rax   # 0x52279b0
movq %rdx, (%rax,%rcx,8)
jmp 0x40f8c
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x40e8f
jmp 0x40f9e
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x40e52
jmp 0x40fb0
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x40ddf
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)