// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
leaq 0x54d7845(%rip), %rax   # 0x54f6a3b
cmpb $0x0, (%rax)
jne 0x1f209
leaq 0x1762a(%rip), %rdi     # 0x3682c
xorl %eax, %eax
callq 0x8790
leaq 0x82e294(%rip), %rax    # 0x84d4a4
cmpl $0x0, (%rax)
je 0x1f223
leaq 0x82e28c(%rip), %rax    # 0x84d4a8
movq (%rax), %rax
movl (%rax), %eax
jmp 0x1f225
xorl %eax, %eax
movl %eax, 0x524f785(%rip)   # 0x526e9b0
cltq
imulq $0x330, %rax, %rdi      # imm = 0x330
callq 0x4420
movq %rax, 0x524f778(%rip)   # 0x526e9b8
xorl %edi, %edi
testq %rax, %rax
setne %dil
pushq $0x1
popq %rsi
callq 0x92cb
leaq 0x261d0(%rip), %r15     # 0x45428
leaq 0x261c5(%rip), %r14     # 0x45424
xorl %ecx, %ecx
movslq 0x524f748(%rip), %rsi   # 0x526e9b0
cmpq %rsi, %rcx
jge 0x1f52a
imulq $0x330, %rcx, %r12      # imm = 0x330
addq 0x524f739(%rip), %r12   # 0x526e9b8
leaq 0x54d77b5(%rip), %rax   # 0x54f6a3b
cmpb $0x1, (%rax)
movq %rcx, 0x18(%rsp)
jne 0x1f29c
movq %r12, %rdi
leaq 0x175a2(%rip), %rsi     # 0x3683c
jmp 0x1f2f0
leaq 0x82e205(%rip), %rax    # 0x84d4a8
movq (%rax), %rax
movl 0x4(%rax,%rcx,4), %ecx
leaq 0x82e1f3(%rip), %rdx    # 0x84d4a4
movl (%rdx), %r13d
subl %ecx, %r13d
testl %ecx, %ecx
sets %dl
cmpl $0x28, %r13d
setl %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x1f4bc
leaq 0x1756c(%rip), %rdi     # 0x36844
leaq 0x54d5731(%rip), %rsi   # 0x54f4a10
xorl %eax, %eax
callq 0x8ea5
movq %r12, %rdi
leaq 0x148e9(%rip), %rsi     # 0x33bd9
callq 0x1ee04
leaq 0x20(%r12), %rbx
pxor %xmm1, %xmm1
xorps %xmm2, %xmm2
xorl %r13d, %r13d
movslq 0x10(%r12), %rcx
movslq 0x14(%r12), %rax
imulq %rcx, %rax
cmpq %rax, %r13
jge 0x1f3f2
movdqa %xmm1, 0x20(%rsp)
movb (%r12), %cl
xorb $0x7b, %cl
movq 0x18(%r12), %rax
movb (%rax,%r13), %al
movl %eax, %edx
notb %dl
orb %cl, %dl
jne 0x1f345
pxor %xmm1, %xmm1
xorps %xmm0, %xmm0
jmp 0x1f3db
movss %xmm2, 0x14(%rsp)
movzbl %al, %eax
leaq (%rax,%rax,2), %rax
movzwl (%rbx,%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 0x1718e(%rip), %xmm0    # 0x36500
cvtpd2ps %xmm0, %xmm0
movlpd %xmm0, 0x8(%rsp)
movzbl 0x2(%rbx,%rax), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x17153(%rip), %xmm0    # 0x364e0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
xorl %ebp, %ebp
cmpq $0x3, %rbp
je 0x1f3ba
movss 0x8(%rsp,%rbp,4), %xmm0
movss (%r14), %xmm1
callq 0x4520
movss %xmm0, 0x8(%rsp,%rbp,4)
incq %rbp
jmp 0x1f399
movss (%r15), %xmm0
movsd 0x8(%rsp), %xmm2
movaps %xmm0, %xmm1
shufps $0x0, %xmm0, %xmm1      # xmm1 = xmm1[0,0],xmm0[0,0]
mulps %xmm2, %xmm1
mulss 0x10(%rsp), %xmm0
movss 0x14(%rsp), %xmm2
movaps 0x20(%rsp), %xmm3
addps %xmm1, %xmm3
movaps %xmm3, %xmm1
addss %xmm0, %xmm2
incq %r13
jmp 0x1f304
cvtps2pd %xmm1, %xmm0
cvtsi2sd %eax, %xmm1
movaps %xmm2, %xmm3
movsd 0x15cc4(%rip), %xmm2    # 0x350c8
divsd %xmm1, %xmm2
cvtss2sd %xmm3, %xmm1
mulsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm3
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm0, %xmm2
cvtpd2ps %xmm2, %xmm1
movlpd %xmm1, 0x320(%r12)
movss %xmm3, 0x328(%r12)
cvtss2sd %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm3, %xmm2
pushq $0x3
popq %rdi
leaq 0x17414(%rip), %rsi     # 0x36862
movq %r12, %rdx
movb $0x3, %al
callq 0x9045
movss 0x320(%r12), %xmm0
movss 0x324(%r12), %xmm1
movss 0x328(%r12), %xmm2
movaps %xmm1, %xmm3
maxss %xmm2, %xmm3
movaps %xmm0, %xmm4
maxss %xmm3, %xmm4
cvtss2sd %xmm4, %xmm3
ucomisd 0x17048(%rip), %xmm3    # 0x364d8
jbe 0x1f4af
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
leaq 0x173e8(%rip), %rdi     # 0x3688d
movq %r12, %rsi
movb $0x3, %al
callq 0x8ea5
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x1f261
leaq (%rax,%rcx), %rbx
cmpl $0x0, 0x18(%rax,%rcx)
je 0x1f515
pushq $0x3
popq %rbp
movl %ebp, %edi
leaq 0x17261(%rip), %rsi     # 0x36734
movq %rbx, %rdx
leaq 0x54d5533(%rip), %rcx   # 0x54f4a10
xorl %eax, %eax
callq 0x9045
movl 0x10(%rbx), %r8d
movl 0x14(%rbx), %r9d
movl %ebp, %edi
leaq 0x17289(%rip), %rsi     # 0x3677e
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x9045
movq %r12, %rdi
movq %rbx, %rsi
movl %r13d, %edx
callq 0x1ee83
jmp 0x1f2f5
callq 0x1ec48
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1effc
jmp 0x1f2f5
leaq 0x54d750a(%rip), %rax   # 0x54f6a3b
cmpb $0x0, (%rax)
je 0x1f545
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12d8a(%rip), %rdi     # 0x322d6
xorl %eax, %eax
callq 0x8790
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1edac