// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rdi, %r15
cmpb $0x7c, (%rdi)
je 0x455d3
leaq 0x310c9(%rip), %rsi     # 0x7663f
movq %r15, %rdi
callq 0x6ce0
movq %rax, 0x570a43(%rip)    # 0x5b5fc8
testq %rax, %rax
je 0x455d3
xorl %ebx, %ebx
movl %ebx, 0x570a3e(%rip)    # 0x5b5fd0
movl %ebx, 0x570a40(%rip)    # 0x5b5fd8
movq %rax, %rdi
callq 0x6c60
movq %rsp, %rsi
movl %eax, %edi
callq 0x6970
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x455b7
movl 0x30(%rsp), %ecx
movl %ecx, 0x570a33(%rip)    # 0x5b5ff0
movl %ebx, 0x570a35(%rip)    # 0x5b5ff8
movl %ebx, 0x570a47(%rip)    # 0x5b6010
movl $0x1, %ebx
jmp 0x4577b
movq 0x5705ce(%rip), %r14    # 0x5b5ba8
movb $0x1, %bpl
xorl %ebx, %ebx
testq %r14, %r14
je 0x456a9
xorl %r12d, %r12d
cmpb $0x7c, (%r15)
sete %r12b
leaq (%r15,%r12), %rdi
callq 0x45513
movl %eax, %eax
leaq 0x5705bb(%rip), %rcx    # 0x5b5bc0
movl (%rcx,%rax,4), %edx
testl %edx, %edx
js 0x456a9
leaq (%r15,%r12), %rax
incq %rax
movb -0x1(%rax), %cl
xorl %r15d, %r15d
movl %edx, %esi
leaq (%r14,%rsi), %rdx
addq %r14, %rsi
addq $0x10, %rsi
xorl %edi, %edi
testb %cl, %cl
je 0x45693
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 0x45679
movl %r8d, %r11d
cmpb $0x2f, %r9b
je 0x45682
movl %r9d, %r10d
cmpb %r10b, %r11b
jne 0x4569d
movb (%rax,%rdi), %r8b
incq %rdi
testb %r8b, %r8b
jne 0x45633
cmpb $0x0, (%rsi,%rdi)
je 0x4578d
movl (%rdx), %edx
testl %edx, %edx
jns 0x4561d
jmp 0x456ac
xorl %r15d, %r15d
testb %bpl, %bpl
jne 0x4577b
leaq 0x30f83(%rip), %rsi     # 0x7663f
movq %r14, %rdi
callq 0x6ce0
testq %rax, %rax
je 0x4577b
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 0x45773
cmpl $0x4034b50, (%rsp)      # imm = 0x4034B50
jne 0x45773
movzwl 0x1a(%rsp), %eax
movzwl 0x1c(%rsp), %esi
addq %rax, %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x6c70
movq %r14, 0x5708a4(%rip)    # 0x5b5fc8
movswl 0x8(%rsp), %eax
movl %eax, 0x5708a1(%rip)    # 0x5b5fd0
movq %r14, %rdi
callq 0x6280
movl %eax, 0x57089b(%rip)    # 0x5b5fd8
movl 0x16(%rsp), %eax
movl %eax, 0x5708a9(%rip)    # 0x5b5ff0
movl $0x0, 0x5708a7(%rip)    # 0x5b5ff8
testl %eax, %eax
js 0x4579f
movl 0x570875(%rip), %eax    # 0x5b5fd0
cmpl $0x8, %eax
je 0x457b8
testl %eax, %eax
jne 0x4579f
movl $0x0, 0x5708a2(%rip)    # 0x5b6010
jmp 0x455c9
movq %r14, %rdi
callq 0x6480
movl %ebx, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movslq 0x8(%rdx), %rax
addq %rax, %r14
movl 0xc(%rdx), %r15d
xorl %ebp, %ebp
jmp 0x456ac
movq 0x570822(%rip), %rdi    # 0x5b5fc8
callq 0x6480
movq $0x0, 0x570812(%rip) # 0x5b5fc8
jmp 0x4577b
cmpb $0x0, 0x57085d(%rip)    # 0x5b601c
jne 0x457cd
movb $0x1, 0x570854(%rip)    # 0x5b601c
callq 0x457f0
movl $0x0, 0x570811(%rip)    # 0x5b5fe8
movl 0x12(%rsp), %eax
movl %eax, 0x5707ff(%rip)    # 0x5b5fe0
movl $0x7fffffff, 0x570835(%rip) # imm = 0x7FFFFFFF
jmp 0x455c9