// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttexcache.c
// Function: ptcache_load
static PTCacheTile * ptcache_load(off_t offset)
{
	int32_t tsizx, tsizy;
	int32_t sizx, sizy;
	int32_t flags;
	int32_t format;
	int32_t nmipmaps, i;
	int32_t length;

	PTCacheTile * tdef = 0;
	FILE * fh;

	if (cachereplace) {
		// cache is in a broken state, so don't try loading
		return 0;
	}

	fh = fopen(CACHESTORAGEFILE, "rb");
	if (!fh) {
		cachedisabled = 1;
		buildprintf("PolymostTexCache: error opening %s, texture cache disabled\n", CACHESTORAGEFILE);
		return 0;
	}

	fseek(fh, offset, SEEK_SET);

	if (fread(&tsizx, 4, 1, fh) != 1 ||
	    fread(&tsizy, 4, 1, fh) != 1 ||
	    fread(&flags, 4, 1, fh) != 1 ||
	    fread(&format, 4, 1, fh) != 1 ||
	    fread(&nmipmaps, 4, 1, fh) != 1) {
		// truncated entry, so throw the whole cache away
		goto fail;
	}

	tsizx = B_LITTLE32(tsizx);
	tsizy = B_LITTLE32(tsizy);
	flags = B_LITTLE32(flags);
	format = B_LITTLE32(format);
	nmipmaps = B_LITTLE32(nmipmaps);

	tdef = PTCacheAllocNewTile(nmipmaps);
	tdef->tsizx = tsizx;
	tdef->tsizy = tsizy;
	tdef->flags = flags;
	tdef->format = format;

	for (i = 0; i < nmipmaps; i++) {
		if (fread(&sizx, 4, 1, fh) != 1 ||
		    fread(&sizy, 4, 1, fh) != 1 ||
		    fread(&length, 4, 1, fh) != 1) {
			// truncated entry, so throw the whole cache away
			goto fail;
		}

		sizx = B_LITTLE32(sizx);
		sizy = B_LITTLE32(sizy);
		length = B_LITTLE32(length);

		tdef->mipmap[i].sizx = sizx;
		tdef->mipmap[i].sizy = sizy;
		tdef->mipmap[i].length = length;
		tdef->mipmap[i].data = (unsigned char *) malloc(length);

		if (fread(tdef->mipmap[i].data, length, 1, fh) != 1) {
			// truncated data
			goto fail;
		}
	}

	fclose(fh);

	return tdef;
fail:
	cachereplace = 1;
	buildprintf("PolymostTexCache: corrupt texture cache detected, cache will be replaced\n");
	PTCacheUnloadIndex();
	fclose(fh);
	if (tdef) {
		PTCacheFreeTile(tdef);
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
cmpl $0x0, 0x61aaf5(%rip)    # 0x6b7170
je 0x9c68a
movq $0x0, -0x8(%rbp)
jmp 0x9c94b
movq 0x4556f(%rip), %rdi     # 0xe1c00
leaq 0x16fba(%rip), %rsi     # 0xb3652
callq 0x6c10
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x9c6d4
movl $0x1, 0x61aac2(%rip)    # 0x6b7174
movq 0x45547(%rip), %rsi     # 0xe1c00
leaq 0x1ba44(%rip), %rdi     # 0xb8104
movb $0x0, %al
callq 0x37c90
movq $0x0, -0x8(%rbp)
jmp 0x9c94b
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x6ba0
movq -0x48(%rbp), %rcx
leaq -0x14(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c774
movq -0x48(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c774
movq -0x48(%rbp), %rcx
leaq -0x24(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c774
movq -0x48(%rbp), %rcx
leaq -0x28(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c774
movq -0x48(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
je 0x9c779
jmp 0x9c90d
movl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0x9ca40
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x18(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x24(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x9c8fa
movq -0x48(%rbp), %rcx
leaq -0x1c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c835
movq -0x48(%rbp), %rcx
leaq -0x20(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c835
movq -0x48(%rbp), %rcx
leaq -0x34(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
je 0x9c83a
jmp 0x9c90d
movl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x40(%rbp), %rax
addq $0x20, %rax
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x20(%rbp), %ecx
movq -0x40(%rbp), %rax
addq $0x20, %rax
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rax
addq $0x20, %rax
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movslq -0x34(%rbp), %rdi
callq 0x68f0
movq %rax, %rcx
movq -0x40(%rbp), %rax
addq $0x20, %rax
movslq -0x30(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movslq -0x30(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movslq -0x34(%rbp), %rsi
movq -0x48(%rbp), %rcx
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
je 0x9c8ea
jmp 0x9c90d
jmp 0x9c8ec
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x9c7d2
movq -0x48(%rbp), %rdi
callq 0x6420
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9c94b
movl $0x1, 0x61a859(%rip)    # 0x6b7170
leaq 0x1b97d(%rip), %rdi     # 0xb829b
movb $0x0, %al
callq 0x37c90
callq 0x9c3d0
movq -0x48(%rbp), %rdi
callq 0x6420
cmpq $0x0, -0x40(%rbp)
je 0x9c943
movq -0x40(%rbp), %rdi
callq 0x9c9b0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)