// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rdi, %rbx
cmpb $0x7c, (%rdi)
je 0x4065a
leaq 0x2c055(%rip), %rsi     # 0x6c66a
movq %rbx, %rdi
callq 0x6ce0
movq %rax, 0x56f9a4(%rip)    # 0x5affc8
testq %rax, %rax
je 0x4065a
andl $0x0, 0x56f9a0(%rip)    # 0x5affd0
andl $0x0, 0x56f9a1(%rip)    # 0x5affd8
movq %rax, %rdi
callq 0x6c60
movq %rsp, %rsi
movl %eax, %edi
callq 0x6970
testl %eax, %eax
js 0x407cd
movl 0x30(%rsp), %eax
jmp 0x407d0
movq 0x56f547(%rip), %r14    # 0x5afba8
testq %r14, %r14
je 0x407f1
xorl %r15d, %r15d
cmpb $0x7c, (%rbx)
sete %r15b
addq %rbx, %r15
movq %r15, %rdi
callq 0x405bf
movl %eax, %eax
leaq 0x56f538(%rip), %rcx    # 0x5afbc0
leaq (%rcx,%rax,4), %rax
xorl %ebx, %ebx
pushq $0x5c
popq %rcx
movslq (%rax), %rdx
testq %rdx, %rdx
js 0x407f3
leaq (%r14,%rdx), %rax
addq %r14, %rdx
addq $0x10, %rdx
xorl %esi, %esi
movb (%r15,%rsi), %dil
testb %dil, %dil
je 0x40705
leal -0x61(%rdi), %r8d
leal -0x20(%rdi), %r9d
cmpb $0x1a, %r8b
movzbl %dil, %r8d
movzbl %r9b, %edi
cmovael %r8d, %edi
movzbl (%rdx,%rsi), %r8d
leal -0x61(%r8), %r9d
leal -0x20(%r8), %r10d
cmpb $0x1a, %r9b
movzbl %r10b, %r9d
cmovael %r8d, %r9d
movl %ecx, %r8d
cmpb $0x2f, %dil
je 0x406f0
movl %edi, %r8d
movl %ecx, %edi
cmpb $0x2f, %r9b
je 0x406fb
movl %r9d, %edi
incq %rsi
cmpb %dil, %r8b
je 0x406aa
jmp 0x40691
cmpb $0x0, (%rdx,%rsi)
jne 0x40691
movslq 0x8(%rax), %rcx
addq %rcx, %r14
movl 0xc(%rax), %r15d
leaq 0x2bf4d(%rip), %rsi     # 0x6c66a
movq %r14, %rdi
callq 0x6ce0
testq %rax, %rax
je 0x407f3
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6c70
movq %rsp, %rdi
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x407e9
cmpl $0x4034b50, (%rsp)      # imm = 0x4034B50
jne 0x407e9
movzwl 0x1a(%rsp), %eax
movzwl 0x1c(%rsp), %esi
addq %rax, %rsi
pushq $0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %edx
callq 0x6c70
movq %r14, 0x56f841(%rip)    # 0x5affc8
movswl 0x8(%rsp), %eax
movl %eax, 0x56f83e(%rip)    # 0x5affd0
movq %r14, %rdi
callq 0x6280
movl %eax, 0x56f838(%rip)    # 0x5affd8
movl 0x16(%rsp), %eax
movl %eax, 0x56f846(%rip)    # 0x5afff0
andl $0x0, 0x56f847(%rip)    # 0x5afff8
testl %eax, %eax
js 0x40802
movl 0x56f815(%rip), %eax    # 0x5affd0
cmpl $0x8, %eax
je 0x40818
testl %eax, %eax
jne 0x40802
andl $0x0, 0x56f845(%rip)    # 0x5b0010
jmp 0x407f3
pushq $-0x1
popq %rax
movl %eax, 0x56f81a(%rip)    # 0x5afff0
andl $0x0, 0x56f81b(%rip)    # 0x5afff8
andl $0x0, 0x56f82c(%rip)    # 0x5b0010
pushq $0x1
popq %rbx
jmp 0x407f3
movq %r14, %rdi
callq 0x6480
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r14
popq %r15
retq
movq 0x56f7bf(%rip), %rdi    # 0x5affc8
callq 0x6480
andq $0x0, 0x56f7b2(%rip)    # 0x5affc8
jmp 0x407f1
cmpb $0x0, 0x56f7fd(%rip)    # 0x5b001c
jne 0x4082d
movb $0x1, 0x56f7f4(%rip)    # 0x5b001c
callq 0x4084a
andl $0x0, 0x56f7b4(%rip)    # 0x5affe8
movl 0x12(%rsp), %eax
movl %eax, 0x56f7a2(%rip)    # 0x5affe0
movl $0x7fffffff, 0x56f7d8(%rip) # imm = 0x7FFFFFFF
jmp 0x407f3