// File: /workspace/github_cpp_makefile_star2_O1/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 0x54d7c16(%rip), %rax   # 0x54faa2b
cmpb $0x0, (%rax)
jne 0x22e28
leaq 0x19b03(%rip), %rdi     # 0x3c924
xorl %eax, %eax
callq 0x9d2e
leaq 0x82e665(%rip), %rax    # 0x851494
cmpl $0x0, (%rax)
je 0x22e42
leaq 0x82e65d(%rip), %rax    # 0x851498
movq (%rax), %rax
movl (%rax), %eax
jmp 0x22e44
xorl %eax, %eax
movl %eax, 0x524fb56(%rip)   # 0x52729a0
cltq
imulq $0x330, %rax, %rdi      # imm = 0x330
callq 0x4410
movq %rax, 0x524fb49(%rip)   # 0x52729a8
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movl 0x524fb28(%rip), %esi   # 0x52729a0
testl %esi, %esi
jle 0x2318a
leaq 0x2658d(%rip), %r15     # 0x49414
xorl %r14d, %r14d
imulq $0x330, %r14, %r12      # imm = 0x330
addq 0x524fb10(%rip), %r12   # 0x52729a8
leaq 0x54d7b8c(%rip), %rax   # 0x54faa2b
cmpb $0x1, (%rax)
jne 0x22eb0
movq %r12, %rdi
leaq 0x19a86(%rip), %rsi     # 0x3c934
jmp 0x22f02
leaq 0x82e5e1(%rip), %rax    # 0x851498
movq (%rax), %rax
movl 0x4(%rax,%r14,4), %ecx
leaq 0x82e5ce(%rip), %rdx    # 0x851494
movl (%rdx), %ebp
subl %ecx, %ebp
testl %ecx, %ecx
sets %dl
cmpl $0x28, %ebp
setl %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x2311a
leaq 0x19a52(%rip), %rdi     # 0x3c93c
leaq 0x54d5b0f(%rip), %rsi   # 0x54f8a00
xorl %eax, %eax
callq 0xa38e
movq %r12, %rdi
leaq 0x16d77(%rip), %rsi     # 0x39c79
callq 0x22a0f
movl 0x14(%r12), %eax
imull 0x10(%r12), %eax
testl %eax, %eax
jle 0x2303d
leaq 0x20(%r12), %r13
pxor %xmm1, %xmm1
xorps %xmm2, %xmm2
xorl %ebp, %ebp
cmpb $0x7b, (%r12)
jne 0x22f3e
movq 0x18(%r12), %rax
cmpb $-0x1, (%rax,%rbp)
je 0x2301f
movss %xmm2, 0xc(%rsp)
movdqa %xmm1, 0x10(%rsp)
movq 0x18(%r12), %rax
movzbl (%rax,%rbp), %eax
leaq (%rax,%rax,2), %rax
movzwl (%r13,%rax), %ecx
movd %ecx, %xmm0
pxor %xmm1, %xmm1
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 0x19627(%rip), %xmm0    # 0x3c5a0
cvtpd2ps %xmm0, %xmm0
movlpd %xmm0, (%rsp)
movzbl 0x2(%r13,%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x196a9(%rip), %xmm0    # 0x3c640
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movss (%rsp,%rbx,4), %xmm0
movss (%r15), %xmm1
callq 0x4510
movss %xmm0, (%rsp,%rbx,4)
incq %rbx
cmpq $0x3, %rbx
jne 0x22fa3
leaq 0x26451(%rip), %rax     # 0x49418
movss (%rax), %xmm0
movsd (%rsp), %xmm1
movaps %xmm0, %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
mulps %xmm1, %xmm2
movlps %xmm2, (%rsp)
mulss 0x8(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movdqa 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm2
movsd (%rsp), %xmm0
addps %xmm0, %xmm1
addss 0x8(%rsp), %xmm2
incq %rbp
movslq 0x10(%r12), %rcx
movslq 0x14(%r12), %rax
imulq %rcx, %rax
cmpq %rax, %rbp
jl 0x22f28
jmp 0x23031
movq $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
jmp 0x22ff5
cvtps2pd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
jmp 0x23044
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movsd 0x18115(%rip), %xmm3    # 0x3b168
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 0x198b9(%rip), %rsi     # 0x3c95a
movq %r12, %rdx
movb $0x3, %al
callq 0xa52e
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 0x19562(%rip), %xmm3    # 0x3c648
jbe 0x23105
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
leaq 0x1988a(%rip), %rdi     # 0x3c985
movq %r12, %rsi
movb $0x3, %al
callq 0xa38e
incq %r14
movslq 0x524f891(%rip), %rsi   # 0x52729a0
cmpq %rsi, %r14
jl 0x22e8a
jmp 0x2318a
leaq (%rax,%rcx), %r13
cmpl $0x0, 0x18(%rax,%rcx)
je 0x23175
movl $0x3, %edi
leaq 0x196fb(%rip), %rsi     # 0x3c82c
movq %r13, %rdx
leaq 0x54d58c5(%rip), %rcx   # 0x54f8a00
xorl %eax, %eax
callq 0xa52e
movl 0x10(%r13), %r8d
movl 0x14(%r13), %r9d
movl $0x3, %edi
leaq 0x19720(%rip), %rsi     # 0x3c876
movq %r13, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xa52e
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x22a90
jmp 0x22f07
callq 0x2283a
movq %r12, %rdi
movq %r13, %rsi
callq 0x22c09
jmp 0x22f07
leaq 0x54d789a(%rip), %rax   # 0x54faa2b
cmpb $0x0, (%rax)
je 0x231a5
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x151ca(%rip), %rdi     # 0x38376
xorl %eax, %eax
callq 0x9d2e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x229b1