// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttexcache.c
// Function: PTCacheLoadIndex
void PTCacheLoadIndex(void)
{
	FILE * fh = 0;
	int8_t sig[16];
	const int8_t indexsig[16] = { 'P','o','l','y','m','o','s','t','T','e','x','I','n','d','x',CACHEVER };
	const int8_t storagesig[16] = { 'P','o','l','y','m','o','s','t','T','e','x','S','t','o','r',CACHEVER };

	char filename[PTCACHEINDEXFILENAMELEN];
	int32_t effects;
	int32_t flags;
	uint32_t offset;
	int32_t mtime;
	PTCacheIndex * pci;

	int total = 0, dups = 0;
	int haveindex = 0, havestore = 0;

	memset(filename, 0, sizeof(filename));

	// first, check the cache storage file's signature.
	// we open for reading and writing to test permission
	fh = fopen(CACHESTORAGEFILE, "r+b");
	if (fh) {
		havestore = 1;

		if (fread(sig, 16, 1, fh) != 1 || memcmp(sig, storagesig, 16)) {
			cachereplace = 1;
		}
		fclose(fh);
	} else {
		if (errno == ENOENT) {
			// file doesn't exist, which is fine
			;
		} else {
			buildprintf("PolymostTexCache: error opening %s, texture cache disabled\n", CACHESTORAGEFILE);
			cachedisabled = 1;
			return;
		}
	}

	// next, check the index
	fh = fopen(CACHEINDEXFILE, "r+b");
	if (fh) {
		haveindex = 1;

		if (fread(sig, 16, 1, fh) != 1 || memcmp(sig, indexsig, 16)) {
			cachereplace = 1;
		}
	} else {
		if (errno == ENOENT) {
			// file doesn't exist, which is fine
			return;
		} else {
			buildprintf("PolymostTexCache: error opening %s, texture cache disabled\n", CACHEINDEXFILE);
			cachedisabled = 1;
			return;
		}
	}

	// if we're missing either the index or the store, but not both at the same
	// time, the cache is broken and should be replaced
	if ((!haveindex || !havestore) && !(!haveindex && !havestore)) {
		cachereplace = 1;
	}

	if (cachereplace) {
		buildprintf("PolymostTexCache: texture cache will be replaced\n");
		if (fh) {
			fclose(fh);
		}
		return;
	}

	// now that the index is sitting at the first entry, load everything
	while (!feof(fh)) {
		if (fread(filename, PTCACHEINDEXFILENAMELEN, 1, fh) != 1 && feof(fh)) {
			break;
		}
		if (fread(&effects, 4,         1, fh) != 1 ||
		    fread(&flags,   4,         1, fh) != 1 ||
		    fread(&offset,  4,         1, fh) != 1 ||
		    fread(&mtime,   4,         1, fh) != 1) {
			// truncated entry, so throw the whole cache away
			buildprintf("PolymostTexCache: corrupt texture cache index detected, cache will be replaced\n");
			cachereplace = 1;
			PTCacheUnloadIndex();
			break;
		}

		effects = B_LITTLE32(effects);
		flags   = B_LITTLE32(flags);
		offset  = B_LITTLE32(offset);
		mtime   = B_LITTLE32(mtime);

		filename[sizeof(filename)-1] = 0;
		pci = ptcache_findhash(filename, (int) effects, (int) flags);
		if (pci) {
			// superseding an old hash entry
			pci->offset = offset;
			dups++;
		} else {
			ptcache_addhash(filename, (int) effects, (int) flags, offset);
		}
		total++;
	}

	fclose(fh);

	buildprintf("PolymostTexCache: cache index loaded (%d entries, %d old entries skipped)\n", total, dups);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq $0x0, -0x8(%rbp)
movq 0x1c0f6(%rip), %rax     # 0xb80e0
movq %rax, -0x30(%rbp)
movq 0x1c0f3(%rip), %rax     # 0xb80e8
movq %rax, -0x28(%rbp)
movq 0x1c0f0(%rip), %rax     # 0xb80f0
movq %rax, -0x40(%rbp)
movq 0x1c0ed(%rip), %rax     # 0xb80f8
movq %rax, -0x38(%rbp)
movl $0x0, -0x16c(%rbp)
movl $0x0, -0x170(%rbp)
movl $0x0, -0x174(%rbp)
movl $0x0, -0x178(%rbp)
leaq -0x150(%rbp), %rdi
xorl %esi, %esi
movl $0x104, %edx            # imm = 0x104
callq 0x62d0
movq 0x45baf(%rip), %rdi     # 0xe1c00
leaq 0x1c0a8(%rip), %rsi     # 0xb8100
callq 0x6c10
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x9c0ca
movl $0x1, -0x178(%rbp)
leaq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x10, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c0b5
leaq -0x20(%rbp), %rax
leaq -0x40(%rbp), %rcx
movups (%rcx), %xmm1
movups (%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x9c0bf
movl $0x1, 0x61b0b1(%rip)    # 0x6b7170
movq -0x8(%rbp), %rdi
callq 0x6420
jmp 0x9c0fc
callq 0x69c0
cmpl $0x2, (%rax)
jne 0x9c0d6
jmp 0x9c0fa
movq 0x45b23(%rip), %rsi     # 0xe1c00
leaq 0x1c020(%rip), %rdi     # 0xb8104
movb $0x0, %al
callq 0x37c90
movl $0x1, 0x61b07f(%rip)    # 0x6b7174
jmp 0x9c3c4
jmp 0x9c0fc
movq 0x45b05(%rip), %rdi     # 0xe1c08
leaq 0x1bff6(%rip), %rsi     # 0xb8100
callq 0x6c10
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x9c173
movl $0x1, -0x174(%rbp)
leaq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x10, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c167
leaq -0x20(%rbp), %rax
leaq -0x30(%rbp), %rcx
movups (%rcx), %xmm1
movups (%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x9c171
movl $0x1, 0x61afff(%rip)    # 0x6b7170
jmp 0x9c1a6
callq 0x69c0
cmpl $0x2, (%rax)
jne 0x9c182
jmp 0x9c3c4
movq 0x45a7f(%rip), %rsi     # 0xe1c08
leaq 0x1bf74(%rip), %rdi     # 0xb8104
movb $0x0, %al
callq 0x37c90
movl $0x1, 0x61afd3(%rip)    # 0x6b7174
jmp 0x9c3c4
cmpl $0x0, -0x174(%rbp)
je 0x9c1b8
cmpl $0x0, -0x178(%rbp)
jne 0x9c1d4
cmpl $0x0, -0x174(%rbp)
jne 0x9c1ca
cmpl $0x0, -0x178(%rbp)
je 0x9c1d4
movl $0x1, 0x61af9c(%rip)    # 0x6b7170
cmpl $0x0, 0x61af95(%rip)    # 0x6b7170
je 0x9c200
leaq 0x1bf5c(%rip), %rdi     # 0xb8140
movb $0x0, %al
callq 0x37c90
cmpq $0x0, -0x8(%rbp)
je 0x9c1fb
movq -0x8(%rbp), %rdi
callq 0x6420
jmp 0x9c3c4
jmp 0x9c202
movq -0x8(%rbp), %rdi
callq 0x6090
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x9c21c
jmp 0x9c3a1
leaq -0x150(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x104, %esi            # imm = 0x104
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
je 0x9c24f
movq -0x8(%rbp), %rdi
callq 0x6090
cmpl $0x0, %eax
je 0x9c24f
jmp 0x9c3a1
movq -0x8(%rbp), %rcx
leaq -0x154(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c2cf
movq -0x8(%rbp), %rcx
leaq -0x158(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c2cf
movq -0x8(%rbp), %rcx
leaq -0x15c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
jne 0x9c2cf
movq -0x8(%rbp), %rcx
leaq -0x160(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
je 0x9c2f1
leaq 0x1be9c(%rip), %rdi     # 0xb8172
movb $0x0, %al
callq 0x37c90
movl $0x1, 0x61ae89(%rip)    # 0x6b7170
callq 0x9c3d0
jmp 0x9c3a1
movl -0x154(%rbp), %eax
movl %eax, -0x154(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x158(%rbp)
movl -0x15c(%rbp), %eax
movl %eax, -0x15c(%rbp)
movl -0x160(%rbp), %eax
movl %eax, -0x160(%rbp)
movb $0x0, -0x4d(%rbp)
leaq -0x150(%rbp), %rdi
movl -0x154(%rbp), %esi
movl -0x158(%rbp), %edx
callq 0x9c460
movq %rax, -0x168(%rbp)
cmpq $0x0, -0x168(%rbp)
je 0x9c36f
movl -0x15c(%rbp), %ecx
movq -0x168(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x9c38d
leaq -0x150(%rbp), %rdi
movl -0x154(%rbp), %esi
movl -0x158(%rbp), %edx
movl -0x15c(%rbp), %ecx
callq 0x9c510
movl -0x16c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16c(%rbp)
jmp 0x9c202
movq -0x8(%rbp), %rdi
callq 0x6420
movl -0x16c(%rbp), %esi
movl -0x170(%rbp), %edx
leaq 0x1be05(%rip), %rdi     # 0xb81c2
movb $0x0, %al
callq 0x37c90
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nopl (%rax)