// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: kzopen
int kzopen (const char *filnam)
{
	FILE *fil;
	unsigned int zipseek;
	char tempbuf[46+260], *zipnam;

	//kzfs.fil = 0;
	if (filnam[0] != '|')
	{
		kzfs.fil = fopen(filnam,"rb");
		if (kzfs.fil)
		{
			kzfs.comptyp = 0;
			kzfs.seek0 = 0;
			kzfs.leng = _filelength(_fileno(kzfs.fil));
			kzfs.pos = 0;
			kzfs.i = 0;
			return(1);
		}
	}
	if (kzcheckhash(filnam,&zipnam,&zipseek))
	{
		fil = fopen(zipnam,"rb"); if (!fil) return(0);
		fseek(fil,zipseek,SEEK_SET);
		if (fread(tempbuf,30,1,fil) != 1) { fclose(fil); return(0); }
		if (*(int *)&tempbuf[0] != LSWAPIB(0x04034b50)) { fclose(fil); return(0); }
		fseek(fil,SSWAPIB(*(unsigned short *)&tempbuf[26])+SSWAPIB(*(unsigned short *)&tempbuf[28]),SEEK_CUR);

		kzfs.fil = fil;
		kzfs.comptyp = SSWAPIB(*(short *)&tempbuf[8]);
		kzfs.seek0 = (unsigned int)ftell(fil);
		kzfs.leng = LSWAPIB(*(int *)&tempbuf[22]);
		kzfs.pos = 0;
		if (kzfs.leng < 0) { fclose(kzfs.fil); kzfs.fil = 0; return(0); }   // File is ≥ 2GiB.
		switch(kzfs.comptyp) //Compression method
		{
			case 0: kzfs.i = 0; return(1);
			case 8:
				if (!pnginited) { pnginited = 1; initpngtables(); }
				kzfs.comptell = 0;
				kzfs.compleng = LSWAPIB(*(int *)&tempbuf[18]);

					//WARNING: No file in ZIP can be > 2GB-32K bytes
				gslidew = 0x7fffffff; //Force reload at beginning

				return(1);
			default: fclose(kzfs.fil); kzfs.fil = 0; return(0);
		}
	}
	return(0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, %r15
cmpb $0x7c, (%rdi)
je 0x47860
leaq 0x2ffa7(%rip), %rsi     # 0x777aa
movq %r15, %rdi
callq 0x6ce0
movq %rax, 0x56f7b6(%rip)    # 0x5b6fc8
testq %rax, %rax
je 0x47860
xorl %ebx, %ebx
movl %ebx, 0x56f7b1(%rip)    # 0x5b6fd0
movl %ebx, 0x56f7b3(%rip)    # 0x5b6fd8
movq %rax, %rdi
callq 0x6c60
movq %rsp, %rsi
movl %eax, %edi
callq 0x6970
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x47844
movl 0x30(%rsp), %ecx
movl %ecx, 0x56f7a6(%rip)    # 0x5b6ff0
movl %ebx, 0x56f7a8(%rip)    # 0x5b6ff8
movl %ebx, 0x56f7ba(%rip)    # 0x5b7010
movl $0x1, %ebx
jmp 0x47a04
movq 0x56f341(%rip), %r14    # 0x5b6ba8
xorl %ebx, %ebx
testq %r14, %r14
je 0x47a04
xorl %r12d, %r12d
cmpb $0x7c, (%r15)
sete %r12b
leaq (%r15,%r12), %rdi
callq 0x477a1
movl %eax, %eax
leaq 0x56f331(%rip), %rcx    # 0x5b6bc0
movl (%rcx,%rax,4), %edx
testl %edx, %edx
js 0x47a04
leaq (%r15,%r12), %rax
incq %rax
movb -0x1(%rax), %cl
movl %edx, %esi
leaq (%r14,%rsi), %rdx
addq %r14, %rsi
addq $0x10, %rsi
xorl %edi, %edi
testb %cl, %cl
je 0x4791a
movl %ecx, %r8d
leal -0x61(%r8), %r9d
leal -0x20(%r8), %r10d
cmpb $0x1a, %r9b
movzbl %r8b, %r9d
movzbl %r10b, %r8d
cmovael %r9d, %r8d
movzbl (%rsi,%rdi), %r10d
leal -0x61(%r10), %r9d
leal -0x20(%r10), %r11d
cmpb $0x1a, %r9b
movzbl %r11b, %r9d
cmovael %r10d, %r9d
movl $0x5c, %r10d
movl $0x5c, %r11d
cmpb $0x2f, %r8b
je 0x47900
movl %r8d, %r11d
cmpb $0x2f, %r9b
je 0x47909
movl %r9d, %r10d
cmpb %r10b, %r11b
jne 0x47920
movb (%rax,%rdi), %r8b
incq %rdi
testb %r8b, %r8b
jne 0x478ba
cmpb $0x0, (%rsi,%rdi)
je 0x4792f
movl (%rdx), %edx
testl %edx, %edx
jns 0x478a4
jmp 0x479f8
movslq 0x8(%rdx), %rax
addq %rax, %r14
movl 0xc(%rdx), %r15d
leaq 0x2fe69(%rip), %rsi     # 0x777aa
movq %r14, %rdi
callq 0x6ce0
testq %rax, %rax
je 0x479f8
movq %rax, %r14
xorl %ebx, %ebx
movq %rax, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6c70
movq %rsp, %rdi
movl $0x1e, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x479fc
cmpl $0x4034b50, (%rsp)      # imm = 0x4034B50
jne 0x479fc
movzwl 0x1a(%rsp), %eax
movzwl 0x1c(%rsp), %esi
addq %rax, %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x6c70
movq %r14, 0x56f61f(%rip)    # 0x5b6fc8
movswl 0x8(%rsp), %eax
movl %eax, 0x56f61c(%rip)    # 0x5b6fd0
movq %r14, %rdi
callq 0x6280
movl %eax, 0x56f616(%rip)    # 0x5b6fd8
movl 0x16(%rsp), %eax
movl %eax, 0x56f624(%rip)    # 0x5b6ff0
movl $0x0, 0x56f622(%rip)    # 0x5b6ff8
testl %eax, %eax
js 0x47a15
movl 0x56f5f0(%rip), %eax    # 0x5b6fd0
cmpl $0x8, %eax
je 0x47a2e
testl %eax, %eax
jne 0x47a15
movl $0x0, 0x56f61d(%rip)    # 0x5b7010
jmp 0x47856
xorl %ebx, %ebx
jmp 0x47a04
movq %r14, %rdi
callq 0x6480
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x56f5ac(%rip), %rdi    # 0x5b6fc8
callq 0x6480
movq $0x0, 0x56f59c(%rip) # 0x5b6fc8
jmp 0x47a04
cmpb $0x0, 0x56f5e7(%rip)    # 0x5b701c
jne 0x47a43
movb $0x1, 0x56f5de(%rip)    # 0x5b701c
callq 0x47a66
movl $0x0, 0x56f59b(%rip)    # 0x5b6fe8
movl 0x12(%rsp), %eax
movl %eax, 0x56f589(%rip)    # 0x5b6fe0
movl $0x7fffffff, 0x56f5bf(%rip) # imm = 0x7FFFFFFF
jmp 0x47856