// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlcsg/textures.cpp
// Function: LoadLump(lumpinfo_t const*, unsigned char*, int*, int, unsigned char*&, int&)
int             LoadLump(const lumpinfo_t* const source, byte* dest, int* texsize
#ifdef HLCSG_FILEREADFAILURE_FIX
						, int dest_maxsize
#endif
#ifdef ZHLT_NOWADDIR
						, byte *&writewad_data, int &writewad_datasize
#endif
						)
{
#ifdef ZHLT_NOWADDIR
	writewad_data = NULL;
	writewad_datasize = -1;
#endif
    //Log("** PnFNFUNC: LoadLump\n");

    *texsize = 0;
    if (source->filepos)
    {
        if (fseek(texfiles[source->iTexFile], source->filepos, SEEK_SET))
        {
            Warning("fseek to %d failed\n", source->filepos);
#ifdef HLCSG_FILEREADFAILURE_FIX
			Error ("File read failure");
#endif
        }
        *texsize = source->disksize;

#ifdef HLCSG_AUTOWAD_NEW
		if (texwadpathes[source->iTexFile]->usedbymap)
#else
        bool wadinclude = false;
        std::map< int, bool >::iterator it;
        it = s_WadIncludeMap.find(source->iTexFile);
        if (it != s_WadIncludeMap.end())
        {
            wadinclude = it->second;
        }

        // Should we just load the texture header w/o the palette & bitmap?
        if (g_wadtextures && !wadinclude)
#endif
        {
            // Just read the miptex header and zero out the data offsets.
            // We will load the entire texture from the WAD at engine runtime
            int             i;
            miptex_t*       miptex = (miptex_t*)dest;
#ifdef HLCSG_FILEREADFAILURE_FIX
			hlassume ((int)sizeof (miptex_t) <= dest_maxsize, assume_MAX_MAP_MIPTEX);
#endif
            SafeRead(texfiles[source->iTexFile], dest, sizeof(miptex_t));

            for (i = 0; i < MIPLEVELS; i++)
                miptex->offsets[i] = 0;
#ifdef ZHLT_NOWADDIR
			writewad_data = (byte *)malloc (source->disksize);
			hlassume (writewad_data != NULL, assume_NoMemory);
			if (fseek (texfiles[source->iTexFile], source->filepos, SEEK_SET))
				Error ("File read failure");
			SafeRead (texfiles[source->iTexFile], writewad_data, source->disksize);
			writewad_datasize = source->disksize;
#endif
            return sizeof(miptex_t);
        }
        else
        {
			Developer(DEVELOPER_LEVEL_MESSAGE,"Including texture %s\n",source->name);
            // Load the entire texture here so the BSP contains the texture
#ifdef HLCSG_FILEREADFAILURE_FIX
			hlassume (source->disksize <= dest_maxsize, assume_MAX_MAP_MIPTEX);
#endif
            SafeRead(texfiles[source->iTexFile], dest, source->disksize);
            return source->disksize;
        }
    }

#ifdef HLCSG_ERROR_MISSINGTEXTURE
	Error("::LoadLump() texture %s not found!", source->name);
#else
    Warning("::LoadLump() texture %s not found!", source->name);
#endif
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %rbx
movq $0x0, (%r8)
movl $0xffffffff, (%r9)      # imm = 0xFFFFFFFF
movl $0x0, (%rdx)
movslq (%rdi), %rsi
testq %rsi, %rsi
je 0x19961
movq %r9, %r14
movq %r8, %r15
movl %ecx, %ebp
movq %rdx, %r13
movslq 0x20(%rbx), %rax
leaq 0x61b42dd(%rip), %rcx   # 0x61cdb50
movq (%rcx,%rax,8), %rdi
xorl %edx, %edx
callq 0x4350
testl %eax, %eax
je 0x198a0
movl (%rbx), %esi
leaq 0x857e(%rip), %rdi      # 0x21e09
xorl %eax, %eax
callq 0xa4d6
leaq 0x4120(%rip), %rdi      # 0x1d9b9
xorl %eax, %eax
callq 0xa164
movl 0x4(%rbx), %eax
movl %eax, (%r13)
movslq 0x20(%rbx), %rax
leaq 0x61b3e8e(%rip), %rcx   # 0x61cd740
movq (%rcx,%rax,8), %rax
cmpb $0x1, 0x1000(%rax)
jne 0x1997a
xorl %edi, %edi
cmpl $0x28, %ebp
setge %dil
movl $0x25, %esi
callq 0xa91d
movslq 0x20(%rbx), %rax
leaq 0x61b426f(%rip), %r13   # 0x61cdb50
movq (%r13,%rax,8), %rdi
movl $0x28, %ebp
movq %r12, %rsi
movl $0x28, %edx
callq 0x9a4c
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
movslq 0x4(%rbx), %rdi
callq 0x4420
movq %rax, (%r15)
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa91d
movslq 0x20(%rbx), %rax
movq (%r13,%rax,8), %rdi
movslq (%rbx), %rsi
xorl %edx, %edx
callq 0x4350
testl %eax, %eax
je 0x19945
leaq 0x407b(%rip), %rdi      # 0x1d9b9
xorl %eax, %eax
callq 0xa164
movslq 0x20(%rbx), %rax
movq (%r13,%rax,8), %rdi
movq (%r15), %rsi
movl 0x4(%rbx), %edx
callq 0x9a4c
movl 0x4(%rbx), %eax
movl %eax, (%r14)
jmp 0x199c1
addq $0x10, %rbx
leaq 0x84c7(%rip), %rdi      # 0x21e33
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa164
jmp 0x199c1
leaq 0x10(%rbx), %rdx
leaq 0x8498(%rip), %rsi      # 0x21e1d
movl $0x3, %edi
xorl %eax, %eax
callq 0xa676
xorl %edi, %edi
cmpl %ebp, 0x4(%rbx)
setle %dil
movl $0x25, %esi
callq 0xa91d
movslq 0x20(%rbx), %rax
leaq 0x61b41a1(%rip), %rcx   # 0x61cdb50
movq (%rcx,%rax,8), %rdi
movl 0x4(%rbx), %edx
movq %r12, %rsi
callq 0x9a4c
movl 0x4(%rbx), %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq