// File: /workspace/github_cpp_makefile_star2_O2/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)
leaq 0x524f99f(%rip), %r15   # 0x526e9c8
leaq 0x8(%rsp), %r12
pushq $0x20
popq %r13
movq (%r15), %r15
testq %r15, %r15
je 0x1f152
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x42a0
movq 0x1018(%r15), %rsi
movslq 0x1014(%r15), %rdx
movq %r12, %rdi
movq %r13, %rcx
leaq -0x42b(%rip), %r8       # 0x1ec3b
callq 0x43e0
testq %rax, %rax
je 0x1f032
movq %rax, %rbp
leaq 0x8(%r15), %r14
pushq $0x3
popq %rdi
leaq 0x176b3(%rip), %rsi     # 0x36734
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x9045
cmpb $0x43, 0xc(%rbp)
jne 0x1f032
cmpb $0x0, 0xd(%rbp)
jne 0x1f032
movslq 0x4(%rbp), %rdi
cmpq $0x28, %rdi
jl 0x1f0b6
movl (%rbp), %eax
testl %eax, %eax
js 0x1f0b6
addl %edi, %eax
cmpl 0x1010(%r15), %eax
jle 0x1f0cf
leaq 0x17695(%rip), %rdi     # 0x36752
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8ea5
jmp 0x1f032
callq 0x4420
xorl %edi, %edi
movq %rax, (%rsp)
testq %rax, %rax
setne %dil
pushq $0x1
popq %rsi
callq 0x92cb
movq 0x1008(%r15), %rdi
movslq (%rbp), %rsi
xorl %edx, %edx
callq 0x4340
testl %eax, %eax
je 0x1f10d
leaq 0x147e3(%rip), %rdi     # 0x338e9
xorl %eax, %eax
callq 0x8b2f
movq 0x1008(%r15), %rdi
movl 0x4(%rbp), %edx
movq (%rsp), %rsi
callq 0x836f
movq (%rsp), %rdi
pushq $0x10
popq %rsi
callq 0x7773
testb %al, %al
jne 0x1f17d
leaq 0x1761b(%rip), %rdi     # 0x36752
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8ea5
movq (%rsp), %rdi
callq 0x4380
jmp 0x1f032
leaq 0x176a2(%rip), %rdi     # 0x367fb
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8ea5
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1ee04
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %r15
movl 0x10(%r15), %r8d
movl 0x14(%r15), %r9d
leaq 0x175ee(%rip), %rsi     # 0x3677e
pushq $0x3
popq %rdi
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x9045
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4320
testl %eax, %eax
je 0x1f1c9
leaq 0x175f7(%rip), %rdi     # 0x367ad
movq %rbx, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x8ea5
movl 0x4(%rbp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1ee83
movq %r15, %rdi
callq 0x4380
jmp 0x1f16e