// File: FreeSlave[P]vhlt/hlrad/loadtextures.cpp
// Function: LoadTextures()
void LoadTextures ()
{
	if (!g_notextures)
	{
		Log ("Load Textures:\n");
	}
	g_numtextures = g_texdatasize? ((dmiptexlump_t *)g_dtexdata)->nummiptex: 0;
	g_textures = (radtexture_t *)malloc (g_numtextures * sizeof (radtexture_t));
	hlassume (g_textures != NULL, assume_NoMemory);
	int i;
	for (i = 0; i < g_numtextures; i++)
	{
		int offset = ((dmiptexlump_t *)g_dtexdata)->dataofs[i];
		int size = g_texdatasize - offset;
		radtexture_t *tex = &g_textures[i];
		if (g_notextures)
		{
			DefaultTexture (tex, "DEFAULT");
		}
		else if (offset < 0 || size < (int)sizeof (miptex_t))
		{
			Warning ("Invalid texture data in '%s'.", g_source);
			DefaultTexture (tex, "");
		}
		else
		{
			miptex_t *mt = (miptex_t *)&g_dtexdata[offset];
			if (mt->offsets[0])
			{
				Developer (DEVELOPER_LEVEL_MESSAGE, "Texture '%s': found in '%s'.\n", mt->name, g_source);
				Developer (DEVELOPER_LEVEL_MESSAGE, "Texture '%s': name '%s', width %d, height %d.\n", mt->name, mt->name, mt->width, mt->height);
				LoadTexture (tex, mt, size);
			}
			else
			{
				TryOpenWadFiles ();
				LoadTextureFromWad (tex, mt);
			}
		}
#ifdef HLRAD_REFLECTIVITY
		{
			vec3_t total;
			VectorClear (total);
			for (int j = 0; j < tex->width * tex->height; j++)
			{
				vec3_t reflectivity;
				if (tex->name[0] == '{' && tex->canvas[j] == 0xFF)
				{
					VectorFill (reflectivity, 0.0);
				}
				else
				{
					VectorScale (tex->palette[tex->canvas[j]], 1.0/255.0, reflectivity);
					for (int k = 0; k < 3; k++)
					{
						reflectivity[k] = pow (reflectivity[k], g_texreflectgamma);
					}
					VectorScale (reflectivity, g_texreflectscale, reflectivity);
				}
				VectorAdd (total, reflectivity, total);
			}
			VectorScale (total, 1.0 / (double)(tex->width * tex->height), total);
			VectorCopy (total, tex->reflectivity);
			Developer (DEVELOPER_LEVEL_MESSAGE, "Texture '%s': reflectivity is (%f,%f,%f).\n",
				tex->name, tex->reflectivity[0], tex->reflectivity[1], tex->reflectivity[2]);
			if (VectorMaximum (tex->reflectivity) > 1.0 + NORMAL_EPSILON)
			{
				Warning ("Texture '%s': reflectivity (%f,%f,%f) greater than 1.0.", tex->name, tex->reflectivity[0], tex->reflectivity[1], tex->reflectivity[2]);
			}
		}
#endif
	}
	if (!g_notextures)
	{
		Log ("%i textures referenced\n", g_numtextures);
		TryCloseWadFiles ();
	}
}

// Assembly:
subq $0x58, %rsp
leaq 0x54ea950(%rip), %rax   # 0x552fa4b
testb $0x1, (%rax)
jne 0x4510e
leaq 0x2973b(%rip), %rdi     # 0x6e842
movb $0x0, %al
callq 0xb0d0
leaq 0x84138f(%rip), %rax    # 0x8864a4
cmpl $0x0, (%rax)
je 0x4512c
leaq 0x841387(%rip), %rax    # 0x8864a8
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
jmp 0x45134
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x45134
movl 0x14(%rsp), %eax
movl %eax, 0x5262882(%rip)   # 0x52a79c0
movslq 0x526287b(%rip), %rax   # 0x52a79c0
imulq $0x330, %rax, %rdi      # imm = 0x330
callq 0x4430
movq %rax, 0x5262870(%rip)   # 0x52a79c8
cmpq $0x0, 0x5262868(%rip)   # 0x52a79c8
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbf00
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x526283b(%rip), %eax   # 0x52a79c0
jge 0x45742
leaq 0x841316(%rip), %rax    # 0x8864a8
movq (%rax), %rax
movslq 0x54(%rsp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movl %eax, 0x50(%rsp)
leaq 0x8412fb(%rip), %rax    # 0x8864a4
movl (%rax), %eax
subl 0x50(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x526280e(%rip), %rax   # 0x52a79c8
movslq 0x54(%rsp), %rcx
imulq $0x330, %rcx, %rcx      # imm = 0x330
addq %rcx, %rax
movq %rax, 0x40(%rsp)
leaq 0x54ea876(%rip), %rax   # 0x552fa4b
testb $0x1, (%rax)
je 0x451f0
movq 0x40(%rsp), %rdi
leaq 0x2966c(%rip), %rsi     # 0x6e852
callq 0x44a10
jmp 0x452c6
cmpl $0x0, 0x50(%rsp)
jl 0x451fe
cmpl $0x28, 0x4c(%rsp)
jge 0x45229
leaq 0x29655(%rip), %rdi     # 0x6e85a
leaq 0x54e8814(%rip), %rsi   # 0x552da20
movb $0x0, %al
callq 0xb9f0
movq 0x40(%rsp), %rdi
leaq 0x26ada(%rip), %rsi     # 0x6bcf9
callq 0x44a10
jmp 0x452c4
leaq 0x841278(%rip), %rax    # 0x8864a8
movq (%rax), %rax
movslq 0x50(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x452ae
movq 0x38(%rsp), %rdx
movl $0x3, %edi
leaq 0x294ee(%rip), %rsi     # 0x6e74a
leaq 0x54e87bd(%rip), %rcx   # 0x552da20
movb $0x0, %al
callq 0xbbf0
movq 0x38(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x38(%rsp), %rax
movl 0x10(%rax), %r8d
movq 0x38(%rsp), %rax
movl 0x14(%rax), %r9d
movl $0x3, %edi
leaq 0x29502(%rip), %rsi     # 0x6e794
movb $0x0, %al
callq 0xbbf0
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x4c(%rsp), %edx
callq 0x44b40
jmp 0x452c2
callq 0x44750
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x44e30
jmp 0x452c4
jmp 0x452c6
xorps %xmm0, %xmm0
movss %xmm0, 0x34(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movq 0x40(%rsp), %rcx
movl 0x10(%rcx), %ecx
movq 0x40(%rsp), %rdx
imull 0x14(%rdx), %ecx
cmpl %ecx, %eax
jge 0x454d8
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x4534c
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x28(%rsp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xff, %eax
jne 0x4534c
xorps %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
jmp 0x45492
movq 0x40(%rsp), %rax
addq $0x20, %rax
movq 0x40(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x28(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movzbl (%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x291eb(%rip), %xmm1    # 0x6e568
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x40(%rsp), %rax
addq $0x20, %rax
movq 0x40(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x28(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movzbl 0x1(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x291ab(%rip), %xmm1    # 0x6e568
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rax
addq $0x20, %rax
movq 0x40(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x28(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x2916b(%rip), %xmm1    # 0x6e568
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
movl $0x0, 0x18(%rsp)
cmpl $0x3, 0x18(%rsp)
jge 0x4544d
movslq 0x18(%rsp), %rax
movss 0x1c(%rsp,%rax,4), %xmm0
leaq 0x38ff8(%rip), %rax     # 0x7e424
movss (%rax), %xmm1
callq 0x44140
movslq 0x18(%rsp), %rax
movss %xmm0, 0x1c(%rsp,%rax,4)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x45413
movss 0x1c(%rsp), %xmm0
leaq 0x38fce(%rip), %rax     # 0x7e428
mulss (%rax), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x20(%rsp), %xmm0
leaq 0x38fb7(%rip), %rax     # 0x7e428
mulss (%rax), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x24(%rsp), %xmm0
leaq 0x38fa0(%rip), %rax     # 0x7e428
mulss (%rax), %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x2c(%rsp), %xmm0
addss 0x1c(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x30(%rsp), %xmm0
addss 0x20(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
movss 0x34(%rsp), %xmm0
addss 0x24(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x452e9
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x40(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x40(%rsp), %rcx
imull 0x14(%rcx), %eax
cvtsi2sd %eax, %xmm2
movsd 0x27ce9(%rip), %xmm1    # 0x6d1e8
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x30(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x40(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x40(%rsp), %rcx
imull 0x14(%rcx), %eax
cvtsi2sd %eax, %xmm2
movsd 0x27cb0(%rip), %xmm1    # 0x6d1e8
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x30(%rsp)
movss 0x34(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x40(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x40(%rsp), %rcx
imull 0x14(%rcx), %eax
cvtsi2sd %eax, %xmm2
movsd 0x27c77(%rip), %xmm1    # 0x6d1e8
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x2c(%rsp), %xmm0
movq 0x40(%rsp), %rax
movss %xmm0, 0x320(%rax)
movss 0x30(%rsp), %xmm0
movq 0x40(%rsp), %rax
movss %xmm0, 0x324(%rax)
movss 0x34(%rsp), %xmm0
movq 0x40(%rsp), %rax
movss %xmm0, 0x328(%rax)
movq 0x40(%rsp), %rdx
movq 0x40(%rsp), %rax
movss 0x320(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x40(%rsp), %rax
movss 0x324(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq 0x40(%rsp), %rax
movss 0x328(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
movl $0x3, %edi
leaq 0x29278(%rip), %rsi     # 0x6e878
movb $0x3, %al
callq 0xbbf0
movq 0x40(%rsp), %rax
movss 0x320(%rax), %xmm0
movss %xmm0, 0x10(%rsp)
movq 0x40(%rsp), %rax
movss 0x324(%rax), %xmm0
movq 0x40(%rsp), %rax
ucomiss 0x328(%rax), %xmm0
jbe 0x4564a
movq 0x40(%rsp), %rax
movss 0x324(%rax), %xmm0
movss %xmm0, 0xc(%rsp)
jmp 0x4565d
movq 0x40(%rsp), %rax
movss 0x328(%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x10(%rsp), %xmm0
movss 0xc(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x45683
movq 0x40(%rsp), %rax
movss 0x320(%rax), %xmm0
movss %xmm0, 0x8(%rsp)
jmp 0x456d2
movq 0x40(%rsp), %rax
movss 0x324(%rax), %xmm0
movq 0x40(%rsp), %rax
ucomiss 0x328(%rax), %xmm0
jbe 0x456b3
movq 0x40(%rsp), %rax
movss 0x324(%rax), %xmm0
movss %xmm0, 0x4(%rsp)
jmp 0x456c6
movq 0x40(%rsp), %rax
movss 0x328(%rax), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0x8(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x28e7c(%rip), %xmm1    # 0x6e560
ucomisd %xmm1, %xmm0
jbe 0x45730
movq 0x40(%rsp), %rsi
movq 0x40(%rsp), %rax
movss 0x320(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x40(%rsp), %rax
movss 0x324(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq 0x40(%rsp), %rax
movss 0x328(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x2917a(%rip), %rdi     # 0x6e8a3
movb $0x3, %al
callq 0xb9f0
jmp 0x45732
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x4517b
leaq 0x54ea302(%rip), %rax   # 0x552fa4b
testb $0x1, (%rax)
jne 0x45767
movl 0x526226c(%rip), %esi   # 0x52a79c0
leaq 0x24b63(%rip), %rdi     # 0x6a2be
movb $0x0, %al
callq 0xb0d0
callq 0x44990
addq $0x58, %rsp
retq
nopl (%rax)