// File: /workspace/github_cpp_makefile_star2_O1/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 0x42b0
movb $0x0, 0xf(%rbx)
movq 0x524fd82(%rip), %r14   # 0x52729b8
testq %r14, %r14
je 0x22d6f
leaq -0x419(%rip), %r15      # 0x2282d
leaq 0x8(%rsp), %r12
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x42b0
movq 0x1018(%r14), %rsi
movslq 0x1014(%r14), %rdx
movl $0x20, %ecx
movq %r12, %rdi
movq %r15, %r8
callq 0x43e0
testq %rax, %rax
je 0x22cd7
movq %rax, %rbp
leaq 0x8(%r14), %r13
movl $0x3, %edi
leaq 0x19b9e(%rip), %rsi     # 0x3c82c
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xa52e
cmpb $0x43, 0xc(%rbp)
jne 0x22cd7
cmpb $0x0, 0xd(%rbp)
jne 0x22cd7
movslq 0x4(%rbp), %rdi
cmpq $0x28, %rdi
jl 0x22cc3
movl (%rbp), %eax
testl %eax, %eax
js 0x22cc3
addl %edi, %eax
cmpl 0x1010(%r14), %eax
jle 0x22ce8
leaq 0x19b80(%rip), %rdi     # 0x3c84a
movq %rbx, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xa38e
movq (%r14), %r14
testq %r14, %r14
jne 0x22c4b
jmp 0x22d6f
callq 0x4410
xorl %edi, %edi
movq %rax, (%rsp)
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movq 0x1008(%r14), %rdi
movslq (%rbp), %rsi
xorl %edx, %edx
callq 0x4340
testl %eax, %eax
je 0x22d28
leaq 0x16c68(%rip), %rdi     # 0x39989
xorl %eax, %eax
callq 0xa01c
movq 0x1008(%r14), %rdi
movl 0x4(%rbp), %edx
movq (%rsp), %rsi
callq 0x9907
movq (%rsp), %rdi
movl $0x10, %esi
callq 0x89ef
testb %al, %al
jne 0x22d9a
leaq 0x19af6(%rip), %rdi     # 0x3c84a
movq %rbx, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xa38e
movq (%rsp), %rdi
callq 0x4380
jmp 0x22cd7
leaq 0x19b7d(%rip), %rdi     # 0x3c8f3
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa38e
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x22a0f
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 0x19ac9(%rip), %rsi     # 0x3c876
movl $0x3, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0xa52e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4320
testl %eax, %eax
je 0x22de8
leaq 0x19ad0(%rip), %rdi     # 0x3c8a5
movq %rbx, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0xa38e
movl 0x4(%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a90
movq %r14, %rdi
callq 0x4380
jmp 0x22d8b