// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x54d789c(%rip), %rax   # 0x54f9a2b
cmpb $0x0, (%rax)
jne 0x221a2
leaq 0x196c9(%rip), %rdi     # 0x3b864
xorl %eax, %eax
callq 0x9c46
leaq 0x82e2eb(%rip), %rax    # 0x850494
cmpl $0x0, (%rax)
je 0x221bc
leaq 0x82e2e3(%rip), %rax    # 0x850498
movq (%rax), %rax
movl (%rax), %eax
jmp 0x221be
xorl %eax, %eax
movl %eax, 0x524f7dc(%rip)   # 0x52719a0
cltq
imulq $0x330, %rax, %rdi      # imm = 0x330
callq 0x4400
movq %rax, 0x524f7cf(%rip)   # 0x52719a8
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movl 0x524f7ae(%rip), %esi   # 0x52719a0
testl %esi, %esi
jle 0x224ea
leaq 0x26213(%rip), %r15     # 0x48414
xorl %r14d, %r14d
imulq $0x330, %r14, %r12      # imm = 0x330
addq 0x524f796(%rip), %r12   # 0x52719a8
leaq 0x54d7812(%rip), %rax   # 0x54f9a2b
cmpb $0x1, (%rax)
jne 0x2222a
movq %r12, %rdi
leaq 0x1964c(%rip), %rsi     # 0x3b874
jmp 0x2227c
leaq 0x82e267(%rip), %rax    # 0x850498
movq (%rax), %rax
movl 0x4(%rax,%r14,4), %ecx
leaq 0x82e254(%rip), %rdx    # 0x850494
movl (%rdx), %ebp
subl %ecx, %ebp
testl %ecx, %ecx
sets %dl
cmpl $0x28, %ebp
setl %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x2247a
leaq 0x19618(%rip), %rdi     # 0x3b87c
leaq 0x54d5795(%rip), %rsi   # 0x54f7a00
xorl %eax, %eax
callq 0xa2a6
movq %r12, %rdi
leaq 0x169fd(%rip), %rsi     # 0x38c79
callq 0x21d87
movl 0x10(%r12), %eax
movl 0x14(%r12), %ecx
movl %ecx, %edx
imull %eax, %edx
testl %edx, %edx
jle 0x2239d
leaq 0x20(%r12), %r13
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorl %ebp, %ebp
movb (%r12), %sil
xorb $0x7b, %sil
movq 0x18(%r12), %rdx
movb (%rdx,%rbp), %dl
movl %edx, %edi
notb %dil
orb %sil, %dil
xorps %xmm0, %xmm0
pxor %xmm1, %xmm1
je 0x22376
movss %xmm3, 0xc(%rsp)
movaps %xmm2, 0x10(%rsp)
movzbl %dl, %eax
leaq (%rax,%rax,2), %rax
movzwl (%r13,%rax), %ecx
movd %ecx, %xmm0
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
cvtdq2pd %xmm0, %xmm0
mulpd 0x19226(%rip), %xmm0    # 0x3b520
cvtpd2ps %xmm0, %xmm0
movlpd %xmm0, (%rsp)
movzbl 0x2(%r13,%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19268(%rip), %xmm0    # 0x3b580
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movss (%rsp,%rbx,4), %xmm0
movss (%r15), %xmm1
callq 0x4500
movss %xmm0, (%rsp,%rbx,4)
incq %rbx
cmpq $0x3, %rbx
jne 0x22324
leaq 0x260d0(%rip), %rax     # 0x48418
movss (%rax), %xmm0
movsd (%rsp), %xmm2
movaps %xmm0, %xmm1
shufps $0x0, %xmm0, %xmm1      # xmm1 = xmm1[0,0],xmm0[0,0]
mulps %xmm2, %xmm1
mulss 0x8(%rsp), %xmm0
movl 0x10(%r12), %eax
movl 0x14(%r12), %ecx
movaps 0x10(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
addss %xmm0, %xmm3
addps %xmm1, %xmm2
incq %rbp
movl %ecx, %edx
imull %eax, %edx
movslq %edx, %rsi
cmpq %rsi, %rbp
jl 0x222a5
cvtps2pd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
jmp 0x223a4
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
movsd 0x17db5(%rip), %xmm3    # 0x3a168
divsd %xmm2, %xmm3
mulsd %xmm3, %xmm1
xorps %xmm2, %xmm2
cvtsd2ss %xmm1, %xmm2
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm0, %xmm3
cvtpd2ps %xmm3, %xmm1
movlpd %xmm1, 0x320(%r12)
movss %xmm2, 0x328(%r12)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
movl $0x3, %edi
leaq 0x19499(%rip), %rsi     # 0x3b89a
movq %r12, %rdx
movb $0x3, %al
callq 0xa446
movss 0x320(%r12), %xmm0
movss 0x324(%r12), %xmm1
movss 0x328(%r12), %xmm2
movaps %xmm1, %xmm3
maxss %xmm2, %xmm3
movaps %xmm0, %xmm4
maxss %xmm3, %xmm4
xorps %xmm3, %xmm3
cvtss2sd %xmm4, %xmm3
ucomisd 0x19142(%rip), %xmm3    # 0x3b588
jbe 0x22465
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
leaq 0x1946a(%rip), %rdi     # 0x3b8c5
movq %r12, %rsi
movb $0x3, %al
callq 0xa2a6
incq %r14
movslq 0x524f531(%rip), %rsi   # 0x52719a0
cmpq %rsi, %r14
jl 0x22204
jmp 0x224ea
leaq (%rax,%rcx), %r13
cmpl $0x0, 0x18(%rax,%rcx)
je 0x224d5
movl $0x3, %edi
leaq 0x192db(%rip), %rsi     # 0x3b76c
movq %r13, %rdx
leaq 0x54d5565(%rip), %rcx   # 0x54f7a00
xorl %eax, %eax
callq 0xa446
movl 0x10(%r13), %r8d
movl 0x14(%r13), %r9d
movl $0x3, %edi
leaq 0x19300(%rip), %rsi     # 0x3b7b6
movq %r13, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xa446
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x21e08
jmp 0x22281
callq 0x21bb2
movq %r12, %rdi
movq %r13, %rsi
callq 0x21f83
jmp 0x22281
leaq 0x54d753a(%rip), %rax   # 0x54f9a2b
cmpb $0x0, (%rax)
je 0x22505
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14e62(%rip), %rdi     # 0x3736e
xorl %eax, %eax
callq 0x9c46
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d29