// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttex.c
// Function: ptm_loadcachedtexturefile
static int ptm_loadcachedtexturefile(const char* filename, PTMHead* ptmh, int flags, int effects)
{
	int mipmap = 0, i = 0;
	PTCacheTile * tdef = 0;
	int compress = PTCOMPRESS_NONE;

	tdef = PTCacheLoadTile(filename, effects, flags & (PTH_CLAMPED));
	if (!tdef) {
		return -1;
	}

	switch (tdef->format) {
#if GL_EXT_texture_compression_dxt1 || GL_EXT_texture_compression_s3tc
		case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
			compress = PTCOMPRESS_DXT1;
			if (!glinfo.texcomprdxt1) goto incompatible;
			break;
#endif
#if GL_EXT_texture_compression_s3tc
		case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
			compress = PTCOMPRESS_DXT5;
			if (!glinfo.texcomprdxt5) goto incompatible;
			break;
#endif
#if GL_OES_compressed_ETC1_RGB8_texture
		case GL_ETC1_RGB8_OES:
			compress = PTCOMPRESS_ETC1;
			if (!glinfo.texcompretc1) goto incompatible;
			break;
#endif
		default:
incompatible:
			if (polymosttexverbosity >= 2) {
				buildprintf("PolymostTex: cached %s (effects %d, flags %d) has incompatible format %s (0x%x)\n",
						   tdef->filename, tdef->effects, tdef->flags,
						   compress ? compressfourcc[compress] : "?",
						   tdef->format);
			}
			PTCacheFreeTile(tdef);
			return -1;
	}

	if (polymosttexverbosity >= 2) {
		buildprintf("PolymostTex: loaded %s (effects %d, flags %d, %s) from cache\n",
				   tdef->filename, tdef->effects, tdef->flags, compressfourcc[compress]);
	}

	if (ptmh->glpic == 0) {
		glfunc.glGenTextures(1, &ptmh->glpic);
	}
	ptmh->tsizx = tdef->tsizx;
	ptmh->tsizy = tdef->tsizy;
	ptmh->sizx  = tdef->mipmap[0].sizx;
	ptmh->sizy  = tdef->mipmap[0].sizy;
	ptmh->flags = tdef->flags & PTH_HASALPHA;
	glfunc.glBindTexture(GL_TEXTURE_2D, ptmh->glpic);

	mipmap = 0;
	if (! (flags & PTH_NOMIPLEVEL)) {
		// if we aren't instructed to preserve all mipmap levels,
		// immediately throw away gltexmiplevel mipmaps
		mipmap = max(0, gltexmiplevel);
	}
	while (tdef->mipmap[mipmap].sizx > (1 << gltexmaxsize) ||
		   tdef->mipmap[mipmap].sizy > (1 << gltexmaxsize)) {
		// throw away additional mipmaps until the texture fits within
		// the maximum size permitted by the GL driver
		mipmap++;
	}

	for (i = 0; i + mipmap < tdef->nummipmaps; i++) {
		glfunc.glCompressedTexImage2D(GL_TEXTURE_2D, i,
								   tdef->format,
								   tdef->mipmap[i + mipmap].sizx,
								   tdef->mipmap[i + mipmap].sizy,
								   0, tdef->mipmap[i + mipmap].length,
								   (const GLvoid *) tdef->mipmap[i + mipmap].data);
	}

	PTCacheFreeTile(tdef);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
andl $0x1, %edx
callq 0x9c5c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x9915c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x99486
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x38(%rbp)
subl $0x83f1, %eax           # imm = 0x83F1
je 0x9917b
jmp 0x9916f
movl -0x38(%rbp), %eax
subl $0x83f3, %eax           # imm = 0x83F3
je 0x99196
jmp 0x991b1
movl $0x1, -0x34(%rbp)
leaq 0x121c27(%rip), %rax    # 0x1badb0
cmpb $0x0, 0x1a(%rax)
jne 0x99191
jmp 0x991b3
jmp 0x9923c
movl $0x2, -0x34(%rbp)
leaq 0x121c0c(%rip), %rax    # 0x1badb0
cmpb $0x0, 0x1b(%rax)
jne 0x991ac
jmp 0x991b3
jmp 0x9923c
jmp 0x991b3
cmpl $0x2, 0x48a16(%rip)     # 0xe1bd0
jl 0x99227
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x991f6
movslq -0x34(%rbp), %rcx
leaq 0x489f4(%rip), %rax     # 0xe1be0
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
jmp 0x99203
leaq 0x16fe4(%rip), %rax     # 0xb01e1
movq %rax, -0x50(%rbp)
jmp 0x99203
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %edx
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %r8
movq -0x30(%rbp), %rax
movl 0x10(%rax), %r9d
leaq 0x1edb2(%rip), %rdi     # 0xb7fd2
movb $0x0, %al
callq 0x37c90
movq -0x30(%rbp), %rdi
callq 0x9c9b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x99486
cmpl $0x2, 0x4898d(%rip)     # 0xe1bd0
jl 0x99277
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
movslq -0x34(%rbp), %rdi
leaq 0x4897b(%rip), %rax     # 0xe1be0
movq (%rax,%rdi,8), %r8
leaq 0x1edb3(%rip), %rdi     # 0xb8023
movb $0x0, %al
callq 0x37c90
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x99299
leaq 0x554489(%rip), %rax    # 0x5ed710
movq 0xb8(%rax), %rax
movq -0x18(%rbp), %rsi
movl $0x1, %edi
callq *%rax
movq -0x30(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x30(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x8, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
leaq 0x554427(%rip), %rax    # 0x5ed710
movq 0xc8(%rax), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq *%rax
movl $0x0, -0x24(%rbp)
movl -0x1c(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x99335
xorl %eax, %eax
leaq 0x554654(%rip), %rcx    # 0x5ed96c
cmpl (%rcx), %eax
jle 0x99323
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x9932f
leaq 0x554642(%rip), %rax    # 0x5ed96c
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x99337
movq -0x30(%rbp), %rax
addq $0x20, %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
leaq 0x554612(%rip), %rax    # 0x5ed968
movl (%rax), %ecx
movl $0x1, %edx
shll %cl, %edx
movl -0x5c(%rbp), %ecx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x55(%rbp)
jg 0x9939b
movq -0x30(%rbp), %rax
addq $0x20, %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
leaq 0x5545e0(%rip), %rcx    # 0x5ed968
movl (%rcx), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
setg %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x993a4
jmp 0x993af
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x99337
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl -0x24(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x99476
leaq 0x554340(%rip), %rax    # 0x5ed710
movq 0xf0(%rax), %rax
movl -0x28(%rbp), %esi
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %edx
movq -0x30(%rbp), %rcx
addq $0x20, %rcx
movl -0x28(%rbp), %edi
addl -0x24(%rbp), %edi
movslq %edi, %rdi
imulq $0x18, %rdi, %rdi
addq %rdi, %rcx
movl (%rcx), %ecx
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
movl -0x28(%rbp), %r8d
addl -0x24(%rbp), %r8d
movslq %r8d, %r8
imulq $0x18, %r8, %r8
addq %r8, %rdi
movl 0x4(%rdi), %r8d
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
movl -0x28(%rbp), %r9d
addl -0x24(%rbp), %r9d
movslq %r9d, %r9
imulq $0x18, %r9, %r9
addq %r9, %rdi
movl 0x8(%rdi), %r11d
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
movl -0x28(%rbp), %r9d
addl -0x24(%rbp), %r9d
movslq %r9d, %r9
imulq $0x18, %r9, %r9
addq %r9, %rdi
movq 0x10(%rdi), %r10
movl $0xde1, %edi            # imm = 0xDE1
xorl %r9d, %r9d
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
callq *%rax
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x993b6
movq -0x30(%rbp), %rdi
callq 0x9c9b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop