// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/kplib.c
// Function: kzaddstack
int kzaddstack (const char *zipnam)
{
	FILE *fil;
	int i, j, hashind, zipnamoffs, numfiles;
	char tempbuf[260+46];

	fil = fopen(zipnam,"rb"); if (!fil) return(-1);

		//Write ZIP filename to hash
	i = (int)strlen(zipnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); }
	strcpy(&kzhashbuf[kzhashpos],zipnam);
	zipnamoffs = kzhashpos; kzhashpos += i;

	fseek(fil,-22,SEEK_END);
	if (fread(tempbuf,22,1,fil) != 1) { fclose(fil); return(-1); }
	if (*(unsigned int *)&tempbuf[0] == LSWAPIB(0x06054b50)) //Fast way of finding dir info
	{
		numfiles = SSWAPIB(*(unsigned short *)&tempbuf[10]);
		fseek(fil,LSWAPIB(*(unsigned int *)&tempbuf[16]),SEEK_SET);
	}
	else //Slow way of finding dir info (used when ZIP has junk at end)
	{
		fseek(fil,0,SEEK_SET); numfiles = 0;
		while (1)
		{
			if (!fread(&j,4,1,fil)) { numfiles = -1; break; }
			if ((unsigned)j == LSWAPIB(0x02014b50)) break; //Found central file header :)
			if ((unsigned)j != LSWAPIB(0x04034b50)) { numfiles = -1; break; }
			if (fread(tempbuf,26,1,fil) != 1) { fclose(fil); return(-1); }
			fseek(fil,LSWAPIB(*(unsigned int *)&tempbuf[14]) + SSWAPIB(*(unsigned short *)&tempbuf[24]) + SSWAPIB(*(unsigned short *)&tempbuf[22]),SEEK_CUR);
			numfiles++;
		}
		if (numfiles < 0) { fclose(fil); return(-1); }
		fseek(fil,-4,SEEK_CUR);
	}
	for(i=0;i<numfiles;i++)
	{
		if (fread(tempbuf,46,1,fil) != 1) { fclose(fil); return(-1); }
		if (*(int *)&tempbuf[0] != LSWAPIB(0x02014b50)) { fclose(fil); return(0); }

		j = SSWAPIB(*(unsigned short *)&tempbuf[28]); //filename length
		if (fread(&tempbuf[46],j,1,fil) != 1) { fclose(fil); return(-1); }
		tempbuf[j+46] = 0;

			//Write information into hash
		j = (int)strlen(&tempbuf[46])+17; if (!kzcheckhashsiz(j)) { fclose(fil); return(-1); }
		hashind = kzcalchash(&tempbuf[46]);
		*(int *)&kzhashbuf[kzhashpos] = kzhashead[hashind];
		*(int *)&kzhashbuf[kzhashpos+4] = kzlastfnam;
		*(int *)&kzhashbuf[kzhashpos+8] = zipnamoffs;
		*(unsigned int *)&kzhashbuf[kzhashpos+12] = LSWAPIB(*(unsigned int *)&tempbuf[42]); //zipseek
		strcpy(&kzhashbuf[kzhashpos+16],&tempbuf[46]);
		kzhashead[hashind] = kzhashpos; kzlastfnam = kzhashpos; kzhashpos += j;

		j  = SSWAPIB(*(unsigned short *)&tempbuf[30]); //extra field length
		j += SSWAPIB(*(unsigned short *)&tempbuf[32]); //file comment length
		fseek(fil,j,SEEK_CUR);
	}
	fclose(fil);
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %r14
leaq 0x314b5(%rip), %rsi     # 0x7663f
callq 0x6ce0
testq %rax, %rax
je 0x4523c
movq %rax, %rbx
movq %r14, %rdi
callq 0x6420
movq %rax, %r15
incl %r15d
movl %r15d, %edi
callq 0x4546d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x45451
movslq 0x5709ef(%rip), %r12    # 0x5b5bb4
movq %r12, %rdi
addq 0x5709d9(%rip), %rdi    # 0x5b5ba8
movq %r14, %rsi
callq 0x6430
movq %r12, 0x8(%rsp)
addl %r12d, %r15d
movl %r15d, 0x5709ce(%rip)   # 0x5b5bb4
movq %rbx, %rdi
movq $-0x16, %rsi
movl $0x2, %edx
callq 0x6c70
leaq 0x10(%rsp), %r13
movl $0x16, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x45451
cmpl $0x6054b50, 0x10(%rsp)  # imm = 0x6054B50
jne 0x45246
movzwl 0x1a(%rsp), %r14d
movl 0x20(%rsp), %esi
movq %rbx, %rdi
xorl %edx, %edx
jmp 0x4531e
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x45459
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6c70
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x6550
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x45306
leaq 0x10(%rsp), %r14
leaq 0x4(%rsp), %r12
movl 0x4(%rsp), %eax
cmpl $0x4034b50, %eax        # imm = 0x4034B50
jne 0x452f6
movl $0x1a, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x4544c
movzwl 0x28(%rsp), %eax
addl 0x1e(%rsp), %eax
movzwl 0x26(%rsp), %esi
addl %eax, %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x6c70
incl %r15d
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x6550
testq %rax, %rax
jne 0x4528a
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x45306
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x2014b50, %eax        # imm = 0x2014B50
jne 0x45306
movl %r15d, %r14d
testl %r14d, %r14d
js 0x45451
movq %rbx, %rdi
movq $-0x4, %rsi
movl $0x1, %edx
callq 0x6c70
movl 0x4(%rsp), %r12d
testl %r14d, %r14d
jle 0x4543e
movl $0x2e, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x45447
cmpl $0x2014b50, 0x10(%rsp)  # imm = 0x2014B50
jne 0x4543e
movzwl 0x2c(%rsp), %r12d
movl $0x1, %edx
leaq 0x3e(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x45447
movb $0x0, 0x2e(%r12,%r13)
movq %r15, %rdi
callq 0x6420
movq %rax, %r12
addl $0x11, %r12d
movl %r12d, %edi
callq 0x4546d
testl %eax, %eax
je 0x45447
movq %r15, %rdi
callq 0x45513
movl %eax, %ebp
leaq 0x570804(%rip), %rax    # 0x5b5bc0
movl (%rax,%rbp,4), %eax
movq 0x5707e2(%rip), %rcx    # 0x5b5ba8
movq %r15, %rsi
movq %r13, %r15
movslq 0x5707e1(%rip), %r13    # 0x5b5bb4
leaq 0x10(%rcx,%r13), %rdi
movl %eax, -0x10(%rdi)
movl 0x570bdf(%rip), %eax    # 0x5b5fc0
movl %eax, -0xc(%rdi)
movq 0x8(%rsp), %rax
movl %eax, -0x8(%rdi)
movl 0x3a(%rsp), %eax
movl %eax, -0x4(%rdi)
callq 0x6430
leaq 0x5707c1(%rip), %rax    # 0x5b5bc0
movl %r13d, (%rax,%rbp,4)
movl %r13d, 0x570bb6(%rip)   # 0x5b5fc0
addl %r13d, %r12d
movq %r15, %r13
movl %r12d, 0x57079d(%rip)   # 0x5b5bb4
movzwl 0x2e(%rsp), %eax
movzwl 0x30(%rsp), %r12d
addl %eax, %r12d
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x6c70
decl %r14d
jne 0x45331
movl %r12d, 0x4(%rsp)
xorl %ebp, %ebp
jmp 0x45451
movl %r12d, 0x4(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x6480
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq