// File: FreeSlave[P]vhlt/hlcsg/qcsg.cpp
// Function: SetLightStyles()
static void     SetLightStyles()
{
    int             stylenum;
    const char*     t;
    entity_t*       e;
    int             i, j;
    char            value[10];
    char            lighttargets[MAX_SWITCHED_LIGHTS][MAX_LIGHTTARGETS_NAME];

#ifdef ZHLT_TEXLIGHT
    	bool			newtexlight = false;
#endif

    // any light that is controlled (has a targetname)
    // must have a unique style number generated for it

    stylenum = 0;
    for (i = 1; i < g_numentities; i++)
    {
        e = &g_entities[i];

        t = ValueForKey(e, "classname");
        if (strncasecmp(t, "light", 5))
        {
#ifdef ZHLT_TEXLIGHT
            //LRC:
			// if it's not a normal light entity, allocate it a new style if necessary.
	        t = ValueForKey(e, "style");
			switch (atoi(t))
			{
			case 0: // not a light, no style, generally pretty boring
				continue;
			case -1: // normal switchable texlight
				safe_snprintf(value, sizeof(value), "%i", 32 + stylenum);
				SetKeyValue(e, "style", value);
				stylenum++;
				continue;
			case -2: // backwards switchable texlight
				safe_snprintf(value, sizeof(value), "%i", -(32 + stylenum));
				SetKeyValue(e, "style", value);
				stylenum++;
				continue;
			case -3: // (HACK) a piggyback texlight: switched on and off by triggering a real light that has the same name
				SetKeyValue(e, "style", "0"); // just in case the level designer didn't give it a name
				newtexlight = true;
				// don't 'continue', fall out
			}
	        //LRC (ends)
#else
            continue;
#endif
        }
        t = ValueForKey(e, "targetname");
#ifdef HLCSG_STYLEHACK
		if (*ValueForKey (e, "zhlt_usestyle"))
		{
			t = ValueForKey(e, "zhlt_usestyle");
			if (!strcasecmp (t, "null"))
			{
				t = "";
			}
		}
#endif
        if (!t[0])
        {
            continue;
        }

        // find this targetname
        for (j = 0; j < stylenum; j++)
        {
            if (!strcmp(lighttargets[j], t))
            {
                break;
            }
        }
        if (j == stylenum)
        {
            hlassume(stylenum < MAX_SWITCHED_LIGHTS, assume_MAX_SWITCHED_LIGHTS);
            safe_strncpy(lighttargets[j], t, MAX_LIGHTTARGETS_NAME);
            stylenum++;
        }
        safe_snprintf(value, sizeof(value), "%i", 32 + j);
        SetKeyValue(e, "style", value);
    }

}

// Assembly:
subq $0x848, %rsp            # imm = 0x848
movb $0x0, 0xf(%rsp)
movl $0x0, 0x844(%rsp)
movl $0x1, 0x82c(%rsp)
movl 0x82c(%rsp), %eax
leaq 0x200cb14(%rip), %rcx   # 0x202d4a4
cmpl (%rcx), %eax
jge 0x20cba
movslq 0x82c(%rsp), %rcx
leaq 0x200cb09(%rip), %rax   # 0x202d4b0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x830(%rsp)
movq 0x830(%rsp), %rdi
leaq 0x9b91(%rip), %rsi      # 0x2a556
callq 0x7ff0
movq %rax, 0x838(%rsp)
movq 0x838(%rsp), %rdi
leaq 0x9c39(%rip), %rsi      # 0x2a61a
movl $0x5, %edx
callq 0x44e0
cmpl $0x0, %eax
je 0x20b1c
movq 0x830(%rsp), %rdi
leaq 0xe40e(%rip), %rsi      # 0x2ee11
callq 0x7ff0
movq %rax, 0x838(%rsp)
movq 0x838(%rsp), %rdi
callq 0x45d0
addl $0x3, %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0x3, %eax
ja 0x20b1a
movq (%rsp), %rax
leaq 0xdd46(%rip), %rcx      # 0x2e780
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x20ca4
leaq 0x81e(%rsp), %rdi
movl 0x844(%rsp), %ecx
addl $0x20, %ecx
movl $0xa, %esi
leaq 0xda8a(%rip), %rdx      # 0x2e4f0
movb $0x0, %al
callq 0x99e0
movq 0x830(%rsp), %rdi
leaq 0x81e(%rsp), %rdx
leaq 0xe38d(%rip), %rsi      # 0x2ee11
callq 0x8070
movl 0x844(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x844(%rsp)
jmp 0x20ca4
leaq 0x81e(%rsp), %rdi
movl 0x844(%rsp), %eax
addl $0x20, %eax
xorl %ecx, %ecx
subl %eax, %ecx
movl $0xa, %esi
leaq 0xda2f(%rip), %rdx      # 0x2e4f0
movb $0x0, %al
callq 0x99e0
movq 0x830(%rsp), %rdi
leaq 0x81e(%rsp), %rdx
leaq 0xe332(%rip), %rsi      # 0x2ee11
callq 0x8070
movl 0x844(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x844(%rsp)
jmp 0x20ca4
movq 0x830(%rsp), %rdi
leaq 0xe308(%rip), %rsi      # 0x2ee11
leaq 0xbb3f(%rip), %rdx      # 0x2c64f
callq 0x8070
movb $0x1, 0xf(%rsp)
jmp 0x20b1c
movq 0x830(%rsp), %rdi
leaq 0x9b79(%rip), %rsi      # 0x2a6a4
callq 0x7ff0
movq %rax, 0x838(%rsp)
movq 0x830(%rsp), %rdi
leaq 0xe2c2(%rip), %rsi      # 0x2ee09
callq 0x7ff0
cmpb $0x0, (%rax)
je 0x20b97
movq 0x830(%rsp), %rdi
leaq 0xe2a9(%rip), %rsi      # 0x2ee09
callq 0x7ff0
movq %rax, 0x838(%rsp)
movq 0x838(%rsp), %rdi
leaq 0xd17f(%rip), %rsi      # 0x2dcfb
callq 0x4410
cmpl $0x0, %eax
jne 0x20b95
leaq 0xb1ac(%rip), %rax      # 0x2bd39
movq %rax, 0x838(%rsp)
jmp 0x20b97
movq 0x838(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x20ba9
jmp 0x20ca4
movl $0x0, 0x828(%rsp)
movl 0x828(%rsp), %eax
cmpl 0x844(%rsp), %eax
jge 0x20c01
movslq 0x828(%rsp), %rax
leaq 0x10(%rsp), %rdi
shlq $0x6, %rax
addq %rax, %rdi
movq 0x838(%rsp), %rsi
callq 0x4530
cmpl $0x0, %eax
jne 0x20bec
jmp 0x20c01
jmp 0x20bee
movl 0x828(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x828(%rsp)
jmp 0x20bb4
movl 0x828(%rsp), %eax
cmpl 0x844(%rsp), %eax
jne 0x20c63
cmpl $0x20, 0x844(%rsp)
setl %al
movzbl %al, %edi
andl $0x1, %edi
movl $0xf, %esi
callq 0xc400
movslq 0x828(%rsp), %rax
leaq 0x10(%rsp), %rdi
shlq $0x6, %rax
addq %rax, %rdi
movq 0x838(%rsp), %rsi
movl $0x40, %edx
callq 0x9af0
movl 0x844(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x844(%rsp)
leaq 0x81e(%rsp), %rdi
movl 0x828(%rsp), %ecx
addl $0x20, %ecx
movl $0xa, %esi
leaq 0xd86f(%rip), %rdx      # 0x2e4f0
movb $0x0, %al
callq 0x99e0
movq 0x830(%rsp), %rdi
leaq 0x81e(%rsp), %rdx
leaq 0xe172(%rip), %rsi      # 0x2ee11
callq 0x8070
movl 0x82c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x82c(%rsp)
jmp 0x20982
addq $0x848, %rsp            # imm = 0x848
retq
nopw %cs:(%rax,%rax)