// File: /workspace/github_c_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movq %rdi, %r15
leaq 0x2c3d6(%rip), %rsi     # 0x6c66a
callq 0x6ce0
pushq $-0x1
popq %rbx
testq %rax, %rax
je 0x40508
movq %rax, %r14
movq %r15, %rdi
callq 0x6420
movq %rax, %r12
incl %r12d
movl %r12d, %edi
callq 0x4051c
testl %eax, %eax
je 0x4045c
movslq 0x56f8e7(%rip), %r13    # 0x5afbb4
movq %r13, %rdi
addq 0x56f8d1(%rip), %rdi    # 0x5afba8
movq %r15, %rsi
callq 0x6430
movq %r13, 0x10(%rsp)
addl %r13d, %r12d
movl %r12d, 0x56f8c6(%rip)   # 0x5afbb4
pushq $-0x16
popq %rsi
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0x6c70
leaq 0x20(%rsp), %r13
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x4045c
cmpl $0x6054b50, 0x20(%rsp)  # imm = 0x6054B50
jne 0x40469
movzwl 0x2a(%rsp), %ebx
movl 0x30(%rsp), %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x6c70
pushq $0x1
popq %rbp
subl $0x1, %ebx
jb 0x404dc
movq %r13, %rdi
pushq $0x2e
popq %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x404fd
cmpl $0x2014b50, 0x20(%rsp)  # imm = 0x2014B50
jne 0x404dc
movzwl 0x3c(%rsp), %r15d
leaq 0x4e(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x404fd
movb $0x0, 0x2e(%r15,%r13)
movq %r12, %rdi
callq 0x6420
movq %rax, %r15
addl $0x11, %r15d
movl %r15d, %edi
callq 0x4051c
testl %eax, %eax
je 0x404fd
movq %r12, %rdi
callq 0x405bf
movq %rbx, 0x18(%rsp)
movq %r14, %rbx
movq %rbp, %r14
movl %eax, %ebp
leaq 0x56f7e7(%rip), %rax    # 0x5afbc0
movl (%rax,%rbp,4), %eax
movq 0x56f7c5(%rip), %rcx    # 0x5afba8
movq %r12, %rsi
movq %r13, %r12
movslq 0x56f7c4(%rip), %r13    # 0x5afbb4
leaq 0x10(%rcx,%r13), %rdi
movl %eax, -0x10(%rdi)
movl 0x56fbc2(%rip), %eax    # 0x5affc0
movl %eax, -0xc(%rdi)
movq 0x10(%rsp), %rax
movl %eax, -0x8(%rdi)
movl 0x4a(%rsp), %eax
movl %eax, -0x4(%rdi)
callq 0x6430
leaq 0x56f7a4(%rip), %rax    # 0x5afbc0
movl %r13d, (%rax,%rbp,4)
movq %r14, %rbp
movq %rbx, %r14
movq 0x18(%rsp), %rbx
movl %r13d, 0x56fb8e(%rip)   # 0x5affc0
addl %r13d, %r15d
movq %r12, %r13
movl %r15d, 0x56f775(%rip)   # 0x5afbb4
movzwl 0x3e(%rsp), %eax
movzwl 0x40(%rsp), %esi
addq %rax, %rsi
movq %r14, %rdi
pushq $0x1
popq %rdx
callq 0x6c70
jmp 0x40340
movq %r14, %rdi
callq 0x6480
jmp 0x40508
xorl %ebx, %ebx
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6c70
leaq 0xc(%rsp), %r12
pushq $0x4
popq %r15
pushq $0x1
popq %rbp
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x6550
testq %rax, %rax
je 0x404fd
movl 0xc(%rsp), %eax
cmpl $0x4034b50, %eax        # imm = 0x4034B50
jne 0x404e8
leaq 0x20(%rsp), %rdi
pushq $0x1a
popq %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x404fd
movzwl 0x38(%rsp), %eax
addl 0x2e(%rsp), %eax
movzwl 0x36(%rsp), %esi
addl %eax, %esi
movq %r14, %rdi
pushq $0x1
popq %rdx
callq 0x6c70
incl %ebx
jmp 0x40483
movq %r14, %rdi
callq 0x6480
xorl %ebx, %ebx
jmp 0x40508
cmpl $0x2014b50, %eax        # imm = 0x2014B50
jne 0x404fd
pushq $-0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
jmp 0x40338
movq %r14, %rdi
callq 0x6480
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq