// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7c, %eax
je 0x683ab
movq -0x10(%rbp), %rdi
leaq 0x4b30c(%rip), %rsi     # 0xb3652
callq 0x6c10
movq %rax, 0x540c36(%rip)    # 0x5a8f88
cmpq $0x0, 0x540c2e(%rip)    # 0x5a8f88
je 0x683a9
movl $0x0, 0x540c2a(%rip)    # 0x5a8f90
movl $0x0, 0x540c24(%rip)    # 0x5a8f94
movq 0x540c11(%rip), %rdi    # 0x5a8f88
callq 0x6b90
movl %eax, %edi
callq 0x68590
movl %eax, 0x540c17(%rip)    # 0x5a8fa0
movl $0x0, 0x540c11(%rip)    # 0x5a8fa4
movl $0x0, 0x540c13(%rip)    # 0x5a8fb0
movl $0x1, -0x4(%rbp)
jmp 0x68579
jmp 0x683ab
movq -0x10(%rbp), %rdi
leaq -0x158(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
callq 0x685d0
cmpl $0x0, %eax
je 0x68572
movq -0x158(%rbp), %rdi
leaq 0x4b27c(%rip), %rsi     # 0xb3652
callq 0x6c10
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x683f2
movl $0x0, -0x4(%rbp)
jmp 0x68579
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x6ba0
leaq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1e, %esi
movl $0x1, %edx
callq 0x64f0
cmpq $0x1, %rax
je 0x68437
movq -0x18(%rbp), %rdi
callq 0x6420
movl $0x0, -0x4(%rbp)
jmp 0x68579
cmpl $0x4034b50, -0x150(%rbp) # imm = 0x4034B50
je 0x68458
movq -0x18(%rbp), %rdi
callq 0x6420
movl $0x0, -0x4(%rbp)
jmp 0x68579
movq -0x18(%rbp), %rdi
movzwl -0x136(%rbp), %eax
movzwl -0x134(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
movl $0x1, %edx
callq 0x6ba0
movq -0x18(%rbp), %rax
movq %rax, 0x540b04(%rip)    # 0x5a8f88
movswl -0x148(%rbp), %eax
movl %eax, 0x540aff(%rip)    # 0x5a8f90
movq -0x18(%rbp), %rdi
callq 0x6270
movl %eax, 0x540af4(%rip)    # 0x5a8f94
movl -0x13a(%rbp), %eax
movl %eax, 0x540af4(%rip)    # 0x5a8fa0
movl $0x0, 0x540aee(%rip)    # 0x5a8fa4
cmpl $0x0, 0x540ae3(%rip)    # 0x5a8fa0
jge 0x684e2
movq 0x540ac2(%rip), %rdi    # 0x5a8f88
callq 0x6420
movq $0x0, 0x540ab2(%rip) # 0x5a8f88
movl $0x0, -0x4(%rbp)
jmp 0x68579
movl 0x540aa8(%rip), %eax    # 0x5a8f90
movl %eax, -0x15c(%rbp)
testl %eax, %eax
je 0x68501
jmp 0x684f4
movl -0x15c(%rbp), %eax
subl $0x8, %eax
je 0x68514
jmp 0x68552
movl $0x0, 0x540aa5(%rip)    # 0x5a8fb0
movl $0x1, -0x4(%rbp)
jmp 0x68579
cmpb $0x0, 0x540a9d(%rip)    # 0x5a8fb8
jne 0x68529
movb $0x1, 0x540a94(%rip)    # 0x5a8fb8
callq 0x686c0
movl $0x0, 0x540a69(%rip)    # 0x5a8f9c
movl -0x13e(%rbp), %eax
movl %eax, 0x540a59(%rip)    # 0x5a8f98
movl $0x7fffffff, 0x540a73(%rip) # imm = 0x7FFFFFFF
movl $0x1, -0x4(%rbp)
jmp 0x68579
movq 0x540a2f(%rip), %rdi    # 0x5a8f88
callq 0x6420
movq $0x0, 0x540a1f(%rip) # 0x5a8f88
movl $0x0, -0x4(%rbp)
jmp 0x68579
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopw %cs:(%rax,%rax)