// File: /workspace/github_c_makefile_star2_O3/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, %r15
leaq 0x3036d(%rip), %rsi     # 0x777aa
callq 0x6ce0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x476e2
movq %rax, %r14
movq %r15, %rdi
callq 0x6420
movq %rax, %r12
incl %r12d
movl %r12d, %edi
callq 0x476f6
testl %eax, %eax
je 0x47612
movslq 0x56f73c(%rip), %r13    # 0x5b6bb4
movq %r13, %rdi
addq 0x56f726(%rip), %rdi    # 0x5b6ba8
movq %r15, %rsi
callq 0x6430
movq %r13, 0x8(%rsp)
addl %r13d, %r12d
movl %r12d, 0x56f71b(%rip)   # 0x5b6bb4
movq %r14, %rdi
movq $-0x16, %rsi
movl $0x2, %edx
callq 0x6c70
leaq 0x10(%rsp), %rbp
movl $0x16, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x47612
cmpl $0x6054b50, 0x10(%rsp)  # imm = 0x6054B50
jne 0x4761f
movzwl 0x1a(%rsp), %r15d
movl 0x20(%rsp), %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x6c70
testl %r15d, %r15d
je 0x47603
movl $0x2e, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x476d5
cmpl $0x2014b50, 0x10(%rsp)  # imm = 0x2014B50
jne 0x47603
movzwl 0x2c(%rsp), %r13d
movl $0x1, %edx
leaq 0x3e(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x476d5
movb $0x0, 0x2e(%r13,%rbp)
movq %rbx, %rdi
callq 0x6420
movq %rax, %r13
addl $0x11, %r13d
movl %r13d, %edi
callq 0x476f6
testl %eax, %eax
je 0x476d5
movq %rbx, %rdi
callq 0x477a1
movq %rbp, %r12
movl %eax, %ebp
leaq 0x56f636(%rip), %rax    # 0x5b6bc0
movl (%rax,%rbp,4), %eax
movq 0x56f614(%rip), %rcx    # 0x5b6ba8
movq %rbx, %rsi
movslq 0x56f616(%rip), %rbx    # 0x5b6bb4
leaq 0x10(%rcx,%rbx), %rdi
movl %eax, -0x10(%rdi)
movl 0x56fa14(%rip), %eax    # 0x5b6fc0
movl %eax, -0xc(%rdi)
movq 0x8(%rsp), %rax
movl %eax, -0x8(%rdi)
movl 0x3a(%rsp), %eax
movl %eax, -0x4(%rdi)
callq 0x6430
leaq 0x56f5f6(%rip), %rax    # 0x5b6bc0
movl %ebx, (%rax,%rbp,4)
movq %r12, %rbp
movl %ebx, 0x56f9ea(%rip)    # 0x5b6fc0
addl %ebx, %r13d
movl %r13d, 0x56f5d4(%rip)   # 0x5b6bb4
movzwl 0x2e(%rsp), %eax
movzwl 0x30(%rsp), %esi
addq %rax, %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x6c70
decl %r15d
jne 0x474fc
movq %r14, %rdi
callq 0x6480
xorl %ebx, %ebx
jmp 0x476e2
movq %r14, %rdi
callq 0x6480
jmp 0x476e2
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6c70
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x6550
testq %rax, %rax
je 0x476d5
leaq 0x10(%rsp), %r12
leaq 0x4(%rsp), %r13
movl 0x4(%rsp), %eax
cmpl $0x4034b50, %eax        # imm = 0x4034B50
jne 0x476ba
movl $0x1a, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x6550
cmpq $0x1, %rax
jne 0x476d5
movzwl 0x28(%rsp), %eax
addl 0x1e(%rsp), %eax
movzwl 0x26(%rsp), %esi
addl %eax, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x6c70
incl %r15d
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r14, %rcx
callq 0x6550
testq %rax, %rax
jne 0x47658
jmp 0x476d5
cmpl $0x2014b50, %eax        # imm = 0x2014B50
jne 0x476d5
movq %r14, %rdi
movq $-0x4, %rsi
movl $0x1, %edx
jmp 0x474ee
movq %r14, %rdi
callq 0x6480
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq