// File: FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: BaseLightForFace(dface_t const*, float*)
static void     BaseLightForFace(const dface_t* const f, vec3_t light)
{
#ifdef HLRAD_CUSTOMTEXLIGHT
	int fn = f - g_dfaces;
	if (g_face_texlights[fn])
	{
		double r, g, b, scaler;
		switch (sscanf (ValueForKey (g_face_texlights[fn], "_light"), "%lf %lf %lf %lf", &r, &g, &b, &scaler))
		{
		case -1:
		case 0:
			r = 0.0;
		case 1:
			g = b = r;
		case 3:
			break;
		case 4:
			r *= scaler / 255.0;
			g *= scaler / 255.0;
			b *= scaler / 255.0;
			break;
		default:
			vec3_t origin;
			GetVectorForKey (g_face_texlights[fn], "origin", origin);
			Log("light at (%f,%f,%f) has bad or missing '_light' value : '%s'\n",
				origin[0], origin[1], origin[2], ValueForKey (g_face_texlights[fn], "_light"));
			r = g = b = 0;
			break;
		}
		light[0] = r > 0? r: 0;
		light[1] = g > 0? g: 0;
		light[2] = b > 0? b: 0;
		return;
	}
#endif
    texinfo_t*      tx;
    miptex_t*       mt;
    int             ofs;

    //
    // check for light emited by texture
    //
    tx = &g_texinfo[f->texinfo];

    ofs = ((dmiptexlump_t*)g_dtexdata)->dataofs[tx->miptex];
    mt = (miptex_t*)((byte*) g_dtexdata + ofs);

    LightForTexture(mt->name, light);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq 0x90(%rsp), %rax
leaq 0x1b8f57a(%rip), %rcx   # 0x1be6410
subq %rcx, %rax
movl $0x14, %ecx
cqto
idivq %rcx
movl %eax, 0x84(%rsp)
movslq 0x84(%rsp), %rcx
leaq 0x5396b57(%rip), %rax   # 0x53eda10
cmpq $0x0, (%rax,%rcx,8)
je 0x5711a
movslq 0x84(%rsp), %rcx
leaq 0x5396b3d(%rip), %rax   # 0x53eda10
movq (%rax,%rcx,8), %rdi
leaq 0x17177(%rip), %rsi     # 0x6e055
callq 0x7d50
movq %rax, %rdi
leaq 0x170cf(%rip), %rsi     # 0x6dfbc
xorl %eax, %eax
leaq 0x78(%rsp), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x60(%rsp), %r9
callq 0x4300
incl %eax
movl %eax, %ecx
movq %rcx, 0x30(%rsp)
subl $0x5, %eax
ja 0x56fae
movq 0x30(%rsp), %rax
leaq 0x17d2a(%rip), %rcx     # 0x6ec50
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd %xmm0, 0x70(%rsp)
jmp 0x5705f
movsd 0x60(%rsp), %xmm0
movsd 0x17c8b(%rip), %xmm1    # 0x6ebe8
divsd %xmm1, %xmm0
mulsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x60(%rsp), %xmm0
movsd 0x17c6d(%rip), %xmm1    # 0x6ebe8
divsd %xmm1, %xmm0
mulsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x60(%rsp), %xmm0
movsd 0x17c4f(%rip), %xmm1    # 0x6ebe8
divsd %xmm1, %xmm0
mulsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0x5705f
movslq 0x84(%rsp), %rcx
leaq 0x5396a53(%rip), %rax   # 0x53eda10
movq (%rax,%rcx,8), %rdi
leaq 0x54(%rsp), %rdx
leaq 0x1a5e7(%rip), %rsi     # 0x715b4
callq 0x8c10
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movslq 0x84(%rsp), %rcx
leaq 0x53969ff(%rip), %rax   # 0x53eda10
movq (%rax,%rcx,8), %rdi
leaq 0x17039(%rip), %rsi     # 0x6e055
callq 0x7d50
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movq %rax, %rsi
leaq 0x16f8f(%rip), %rdi     # 0x6dfcc
movb $0x3, %al
callq 0xb0d0
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5707c
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x57087
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x57087
movsd 0x10(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x88(%rsp), %rax
movss %xmm0, (%rax)
movsd 0x70(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x570ba
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x570c5
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x570c5
movsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x88(%rsp), %rax
movss %xmm0, 0x4(%rax)
movsd 0x68(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x570f8
movsd 0x68(%rsp), %xmm0
movsd %xmm0, (%rsp)
jmp 0x57102
xorps %xmm0, %xmm0
movsd %xmm0, (%rsp)
jmp 0x57102
movsd (%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x88(%rsp), %rax
movss %xmm0, 0x8(%rax)
jmp 0x5717e
movq 0x90(%rsp), %rax
movswq 0xa(%rax), %rcx
leaq 0x118f2d2(%rip), %rax   # 0x11e6400
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
leaq 0x82f367(%rip), %rax    # 0x8864a8
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movl 0x4(%rax,%rcx,4), %eax
movl %eax, 0x3c(%rsp)
leaq 0x82f34c(%rip), %rax    # 0x8864a8
movq (%rax), %rax
movslq 0x3c(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x58380
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)