// File: FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: LoadOpaqueEntities()
static void		LoadOpaqueEntities()
{
	int modelnum, entnum;
	for (modelnum = 0; modelnum < g_nummodels; modelnum++)
	{
		dmodel_t *model = &g_dmodels[modelnum];
		char stringmodel[16];
		sprintf (stringmodel, "*%i", modelnum);
		for (entnum = 0; entnum < g_numentities; entnum++)
		{
			entity_t *ent = &g_entities[entnum];
			if (strcmp (ValueForKey (ent, "model"), stringmodel))
				continue;
			vec3_t origin;
			{
				GetVectorForKey (ent, "origin", origin);
				if (*ValueForKey (ent, "light_origin") && *ValueForKey (ent, "model_center"))
				{
					entity_t *ent2 = FindTargetEntity (ValueForKey (ent, "light_origin"));
					if (ent2)
					{
						vec3_t light_origin, model_center;
						GetVectorForKey (ent2, "origin", light_origin);
						GetVectorForKey (ent, "model_center", model_center);
						VectorSubtract (light_origin, model_center, origin);
					}
				}
			}
			bool opaque = false;
			{
				if (g_allow_opaques && (IntForKey (ent, "zhlt_lightflags") & eModelLightmodeOpaque))
					opaque = true;
			}
#ifdef HLRAD_HULLU
			vec3_t d_transparency;
			VectorFill (d_transparency, 0.0);
			bool b_transparency = false;
			{
				const char *s;
				if (*(s = ValueForKey(ent, "zhlt_customshadow")))
				{
        			double r1 = 1.0, g1 = 1.0, b1 = 1.0, tmp = 1.0;
					if (sscanf(s, "%lf %lf %lf", &r1, &g1, &b1) == 3) //RGB version
					{
						if(r1<0.0) r1 = 0.0;
						if(g1<0.0) g1 = 0.0;
						if(b1<0.0) b1 = 0.0;
						d_transparency[0] = r1;
						d_transparency[1] = g1;
						d_transparency[2] = b1;
					}
					else if (sscanf(s, "%lf", &tmp) == 1) //Greyscale version
					{
						if(tmp<0.0) tmp = 0.0;
						VectorFill(d_transparency, tmp);
					}
				}
				if (!VectorCompare (d_transparency, vec3_origin))
					b_transparency = true;
			}
#endif
#ifdef HLRAD_OPAQUE_STYLE
			int opaquestyle = -1;
			{
				int j;
				for (j = 0; j < g_numentities; j++)
				{
					entity_t *lightent = &g_entities[j];
					if (!strcmp (ValueForKey (lightent, "classname"), "light_shadow")
						&& *ValueForKey (lightent, "target")
						&& !strcmp (ValueForKey (lightent, "target"), ValueForKey (ent, "targetname")))
					{
						opaquestyle = IntForKey (lightent, "style");
	#ifdef ZHLT_TEXLIGHT
						if (opaquestyle < 0)
							opaquestyle = -opaquestyle;
	#endif
	#ifdef HLRAD_STYLE_CORING
						opaquestyle = (unsigned char)opaquestyle;
						if (opaquestyle >= ALLSTYLES)
						{
							Error ("invalid light style: style (%d) >= ALLSTYLES (%d)", opaquestyle, ALLSTYLES);
						}
	#endif
						break;
					}
				}
			}
#endif
#ifdef HLRAD_OPAQUE_BLOCK
			bool block = false;
			{
				if (g_blockopaque)
				{
					block = true;
					if (IntForKey (ent, "zhlt_lightflags") & eModelLightmodeNonsolid)
						block = false;
					if (b_transparency)
						block = false;
#ifdef HLRAD_OPAQUE_STYLE
					if (opaquestyle != -1)
						block = false;
#endif
				}
			}
#endif
			if (opaque)
			{
				AddFaceToOpaqueList (entnum, modelnum, origin
#ifdef HLRAD_HULLU
					, d_transparency, b_transparency
#endif
#ifdef HLRAD_OPAQUE_STYLE
					, opaquestyle
#endif
#ifdef HLRAD_OPAQUE_BLOCK
					, block
#endif
					);
			}
		}
	}
	{
		Log("%i opaque models\n", g_opaque_face_count);
		int i, facecount;
		for (facecount = 0, i = 0; i < g_opaque_face_count; i++)
		{
			facecount += CountOpaqueFaces (g_opaque_face_list[i].modelnum);
		}
		Log("%i opaque faces\n", facecount);
	}
}

// Assembly:
subq $0xd8, %rsp
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
leaq 0x2a580(%rip), %rcx     # 0x7e470
cmpl (%rcx), %eax
jge 0x54448
movslq 0xd4(%rsp), %rcx
leaq 0x2a579(%rip), %rax     # 0x7e480
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0xc8(%rsp)
leaq 0xb0(%rsp), %rdi
movl 0xd4(%rsp), %edx
leaq 0x1679a(%rip), %rsi     # 0x6a6c6
movb $0x0, %al
callq 0x40a0
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
leaq 0x20204e8(%rip), %rcx   # 0x2074434
cmpl (%rcx), %eax
jge 0x54430
movslq 0xd0(%rsp), %rcx
leaq 0x20204dd(%rip), %rax   # 0x2074440
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x16749(%rip), %rsi     # 0x6a6ca
callq 0x7d50
movq %rax, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4480
cmpl $0x0, %eax
je 0x53fa0
jmp 0x5441a
movq 0xa8(%rsp), %rdi
leaq 0x9c(%rsp), %rdx
leaq 0x1d5fd(%rip), %rsi     # 0x715b4
callq 0x8c10
movq 0xa8(%rsp), %rdi
leaq 0x1d5e3(%rip), %rsi     # 0x715ae
callq 0x7d50
cmpb $0x0, (%rax)
je 0x540ab
movq 0xa8(%rsp), %rdi
leaq 0x1d5d3(%rip), %rsi     # 0x715bb
callq 0x7d50
cmpb $0x0, (%rax)
je 0x540ab
movq 0xa8(%rsp), %rdi
leaq 0x1d5a9(%rip), %rsi     # 0x715ae
callq 0x7d50
movq %rax, %rdi
callq 0x8b70
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x540a9
movq 0x90(%rsp), %rdi
leaq 0x84(%rsp), %rdx
leaq 0x1d574(%rip), %rsi     # 0x715b4
callq 0x8c10
movq 0xa8(%rsp), %rdi
leaq 0x78(%rsp), %rdx
leaq 0x1d562(%rip), %rsi     # 0x715bb
callq 0x8c10
movss 0x84(%rsp), %xmm0
subss 0x78(%rsp), %xmm0
movss %xmm0, 0x9c(%rsp)
movss 0x88(%rsp), %xmm0
subss 0x7c(%rsp), %xmm0
movss %xmm0, 0xa0(%rsp)
movss 0x8c(%rsp), %xmm0
subss 0x80(%rsp), %xmm0
movss %xmm0, 0xa4(%rsp)
jmp 0x540ab
movb $0x0, 0x77(%rsp)
testb $0x1, 0x2a33d(%rip)     # 0x7e3f4
je 0x540da
movq 0xa8(%rsp), %rdi
leaq 0x1d500(%rip), %rsi     # 0x715c8
callq 0x7f70
andl $0x2, %eax
cmpl $0x0, %eax
je 0x540da
movb $0x1, 0x77(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x6c(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x70(%rsp)
movb $0x0, 0x67(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x1d4cf(%rip), %rsi     # 0x715d8
callq 0x7d50
movq %rax, 0x58(%rsp)
cmpb $0x0, (%rax)
je 0x5424e
movsd 0x190c4(%rip), %xmm0    # 0x6d1e8
movsd %xmm0, 0x50(%rsp)
movsd 0x190b6(%rip), %xmm0    # 0x6d1e8
movsd %xmm0, 0x48(%rsp)
movsd 0x190a8(%rip), %xmm0    # 0x6d1e8
movsd %xmm0, 0x40(%rsp)
movsd 0x1909a(%rip), %xmm0    # 0x6d1e8
movsd %xmm0, 0x38(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x19e60(%rip), %rsi     # 0x6dfc0
leaq 0x50(%rsp), %rdx
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
movb $0x0, %al
callq 0x4300
cmpl $0x3, %eax
jne 0x541e9
xorps %xmm0, %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0x5418f
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x541a3
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x40(%rsp), %xmm0
jbe 0x541b7
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x50(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x68(%rsp)
movsd 0x48(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x6c(%rsp)
movsd 0x40(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x70(%rsp)
jmp 0x5424c
movq 0x58(%rsp), %rdi
leaq 0x19dd3(%rip), %rsi     # 0x6dfc8
leaq 0x38(%rsp), %rdx
movb $0x0, %al
callq 0x4300
cmpl $0x1, %eax
jne 0x5424a
xorps %xmm0, %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x5421a
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x68(%rsp)
movsd 0x38(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x6c(%rsp)
movsd 0x38(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x70(%rsp)
jmp 0x5424c
jmp 0x5424e
leaq 0x68(%rsp), %rdi
leaq 0x17bf6(%rip), %rsi     # 0x6be50
callq 0x440c0
testb $0x1, %al
jne 0x54268
movb $0x1, 0x67(%rsp)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
leaq 0x20201b1(%rip), %rcx   # 0x2074434
cmpl (%rcx), %eax
jge 0x54385
movslq 0x30(%rsp), %rcx
leaq 0x20201a9(%rip), %rax   # 0x2074440
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x162a8(%rip), %rsi     # 0x6a557
callq 0x7d50
movq %rax, %rdi
leaq 0x16329(%rip), %rsi     # 0x6a5e7
callq 0x4480
cmpl $0x0, %eax
jne 0x54373
movq 0x28(%rsp), %rdi
leaq 0x19d63(%rip), %rsi     # 0x6e03b
callq 0x7d50
cmpb $0x0, (%rax)
je 0x54373
movq 0x28(%rsp), %rdi
leaq 0x19d49(%rip), %rsi     # 0x6e03b
callq 0x7d50
movq %rax, 0x10(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x163b0(%rip), %rsi     # 0x6a6bb
callq 0x7d50
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x4480
cmpl $0x0, %eax
jne 0x54373
movq 0x28(%rsp), %rdi
leaq 0x19c3f(%rip), %rsi     # 0x6df6d
callq 0x7f70
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x34(%rsp)
jge 0x54348
xorl %eax, %eax
subl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
movzbl %al, %eax
movl %eax, 0x34(%rsp)
cmpl $0x40, 0x34(%rsp)
jl 0x54371
movl 0x34(%rsp), %esi
leaq 0x19c1f(%rip), %rdi     # 0x6df84
movl $0x40, %edx
movb $0x0, %al
callq 0xb580
jmp 0x54385
jmp 0x54375
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x54278
movb $0x0, 0x27(%rsp)
cmpl $0x0, 0x2a08f(%rip)     # 0x7e420
je 0x543d3
movb $0x1, 0x27(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x1d221(%rip), %rsi     # 0x715c8
callq 0x7f70
andl $0x8, %eax
cmpl $0x0, %eax
je 0x543b9
movb $0x0, 0x27(%rsp)
testb $0x1, 0x67(%rsp)
je 0x543c5
movb $0x0, 0x27(%rsp)
cmpl $-0x1, 0x34(%rsp)
je 0x543d1
movb $0x0, 0x27(%rsp)
jmp 0x543d3
testb $0x1, 0x77(%rsp)
je 0x54418
movl 0xd0(%rsp), %edi
movl 0xd4(%rsp), %esi
leaq 0x9c(%rsp), %rdx
movb 0x67(%rsp), %r8b
movl 0x34(%rsp), %r9d
movb 0x27(%rsp), %al
leaq 0x68(%rsp), %rcx
andb $0x1, %r8b
andb $0x1, %al
movzbl %r8b, %r8d
movzbl %al, %eax
movl %eax, (%rsp)
callq 0x55520
jmp 0x5441a
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x53f3e
jmp 0x54432
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x53ee2
movl 0x54db622(%rip), %esi   # 0x552fa70
leaq 0x1d195(%rip), %rdi     # 0x715ea
movb $0x0, %al
callq 0xb0d0
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x54db5fa(%rip), %eax   # 0x552fa70
jae 0x544a8
movq 0x54db5e9(%rip), %rax   # 0x552fa68
movslq 0x20(%rsp), %rcx
imulq $0x2c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edi
callq 0x65280
addl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x5446c
movl 0x1c(%rsp), %esi
leaq 0x1d149(%rip), %rdi     # 0x715fc
movb $0x0, %al
callq 0xb0d0
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)