// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/loadtextures.cpp
// Function: LoadTextureFromWad(radtexture_t*, miptex_s const*)
void LoadTextureFromWad (radtexture_t *tex, const miptex_t *header)
{
	tex->width = header->width;
	tex->height = header->height;
	strcpy (tex->name, header->name);
	tex->name[16 - 1] = '\0';
	wadfile_t *wad;
	for (wad = g_wadfiles; wad; wad = wad->next)
	{
		lumpinfo_t temp, *found;
		strcpy (temp.name, tex->name);
		found = (lumpinfo_t *)bsearch (&temp, wad->lumpinfos, wad->numlumps, sizeof (lumpinfo_t), lump_sorter_by_name);
		if (found)
		{
			Developer (DEVELOPER_LEVEL_MESSAGE, "Texture '%s': found in '%s'.\n", tex->name, wad->path);
			if (found->type != 67 || found->compression != 0)
				continue;
			if (found->disksize < (int)sizeof (miptex_t) || found->filepos < 0 || found->filepos + found->disksize > wad->filesize)
			{
				Warning ("Texture '%s': invalid texture data in '%s'.", tex->name, wad->path);
				continue;
			}
			miptex_t *mt = (miptex_t *)malloc (found->disksize);
			hlassume (mt != NULL, assume_NoMemory);
			if (fseek (wad->file, found->filepos, SEEK_SET))
				Error ("File read failure");
			SafeRead (wad->file, mt, found->disksize);
			if (!TerminatedString(mt->name, 16))
			{
				Warning("Texture '%s': invalid texture data in '%s'.", tex->name, wad->path);
				free (mt);
				continue;
			}
			Developer (DEVELOPER_LEVEL_MESSAGE, "Texture '%s': name '%s', width %d, height %d.\n", tex->name, mt->name, mt->width, mt->height);
			if (strcasecmp (mt->name, tex->name))
			{
				Warning("Texture '%s': texture name '%s' differs from its reference name '%s' in '%s'.", tex->name, mt->name, tex->name, wad->path);
			}
			LoadTexture (tex, mt, found->disksize);
			free (mt);
			break;
		}
	}
	if (!wad)
	{
		Warning ("Texture '%s': texture is not found in wad files.", tex->name);
		DefaultTexture (tex, tex->name);
		return;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl 0x10(%rsi), %eax
movl %eax, 0x10(%rdi)
movl 0x14(%rsi), %eax
movl %eax, 0x14(%rdi)
callq 0x42a0
movb $0x0, 0xf(%rbx)
movq 0x524fa08(%rip), %r14   # 0x52719b8
testq %r14, %r14
je 0x220e9
leaq -0x41b(%rip), %r15      # 0x21ba5
leaq 0x8(%rsp), %r12
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x42a0
movq 0x1018(%r14), %rsi
movslq 0x1014(%r14), %rdx
movl $0x20, %ecx
movq %r12, %rdi
movq %r15, %r8
callq 0x43d0
testq %rax, %rax
je 0x22051
movq %rax, %rbp
leaq 0x8(%r14), %r13
movl $0x3, %edi
leaq 0x19764(%rip), %rsi     # 0x3b76c
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xa446
cmpb $0x43, 0xc(%rbp)
jne 0x22051
cmpb $0x0, 0xd(%rbp)
jne 0x22051
movslq 0x4(%rbp), %rdi
cmpq $0x28, %rdi
jl 0x2203d
movl (%rbp), %eax
testl %eax, %eax
js 0x2203d
addl %edi, %eax
cmpl 0x1010(%r14), %eax
jle 0x22062
leaq 0x19746(%rip), %rdi     # 0x3b78a
movq %rbx, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xa2a6
movq (%r14), %r14
testq %r14, %r14
jne 0x21fc5
jmp 0x220e9
callq 0x4400
xorl %edi, %edi
movq %rax, (%rsp)
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movq 0x1008(%r14), %rdi
movslq (%rbp), %rsi
xorl %edx, %edx
callq 0x4330
testl %eax, %eax
je 0x220a2
leaq 0x168ee(%rip), %rdi     # 0x38989
xorl %eax, %eax
callq 0x9f34
movq 0x1008(%r14), %rdi
movl 0x4(%rbp), %edx
movq (%rsp), %rsi
callq 0x981c
movq (%rsp), %rdi
movl $0x10, %esi
callq 0x890b
testb %al, %al
jne 0x22114
leaq 0x196bc(%rip), %rdi     # 0x3b78a
movq %rbx, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xa2a6
movq (%rsp), %rdi
callq 0x4370
jmp 0x22051
leaq 0x19743(%rip), %rdi     # 0x3b833
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa2a6
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x21d87
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %r14
movl 0x10(%r14), %r8d
movl 0x14(%r14), %r9d
leaq 0x1968f(%rip), %rsi     # 0x3b7b6
movl $0x3, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0xa446
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4310
testl %eax, %eax
je 0x22162
leaq 0x19696(%rip), %rdi     # 0x3b7e5
movq %rbx, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0xa2a6
movl 0x4(%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21e08
movq %r14, %rdi
callq 0x4370
jmp 0x22105