// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/cache1d.c
// Function: kdfread
unsigned kdfread(void *buffer, unsigned dasizeof, unsigned count, int fil)
{
	size_t i, j;
	int k, kgoal;
	unsigned short leng;
	unsigned char *ptr;

	lzwallocate();

	if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; }
	ptr = (unsigned char *)buffer;

	if (kread(fil,&leng,2) != 2) { lzwrelease(); return 0; }
	leng = B_LITTLE16(leng);
	if (kread(fil,lzwbuf5,(int)leng) != leng) { lzwrelease(); return 0; }
	k = 0; kgoal = lzwuncompress(lzwbuf5,(int)leng,lzwbuf4);

	copybufbyte(lzwbuf4,ptr,(int)dasizeof);
	k += (int)dasizeof;

	for(i=1;i<count;i++)
	{
		if (k >= kgoal)
		{
			if (kread(fil,&leng,2) != 2) { lzwrelease(); return -1; }
			leng = B_LITTLE16(leng);
			if (kread(fil,lzwbuf5,(int)leng) != leng) { lzwrelease(); return -1; }
			k = 0; kgoal = lzwuncompress(lzwbuf5,(int)leng,lzwbuf4);
		}
		for(j=0;j<dasizeof;j++) ptr[j+dasizeof] = ((ptr[j]+lzwbuf4[j+k])&255);
		k += dasizeof;
		ptr += dasizeof;
	}
	lzwrelease();
	return count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebx
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %r14
callq 0x20fa4
cmpl $0x4001, %r12d          # imm = 0x4001
movl $0x1, %ebp
movl %r12d, %eax
cmovael %ebp, %eax
movl %eax, 0xc(%rsp)
cmovael %r12d, %ebp
leaq 0xa(%rsp), %rsi
movl %ebx, %edi
movl $0x2, %edx
callq 0x201c2
xorl %r12d, %r12d
cmpl $0x2, %eax
jne 0x20f81
movzwl 0xa(%rsp), %edx
movq 0x196b69(%rip), %rsi    # 0x1b79c0
movl %ebx, 0x14(%rsp)
movl %ebx, %edi
callq 0x201c2
movzwl 0xa(%rsp), %esi
cmpl %esi, %eax
jne 0x20f81
movl %ebp, %ebx
imull %r15d, %ebx
movq 0x196b44(%rip), %rdi    # 0x1b79c0
movq 0x196b45(%rip), %rdx    # 0x1b79c8
callq 0x21063
movl %eax, %r12d
movq 0x196b36(%rip), %rdi    # 0x1b79c8
movq %r14, %rsi
movl 0xc(%rsp), %ebp
movl %ebp, %edx
callq 0x4ac52
cmpl $0x2, %ebx
jb 0x20f7e
movl %ebx, 0x10(%rsp)
movl %ebx, %edi
movl %ebp, %r8d
movq %r8, %r15
negq %r15
leaq (%r14,%r8), %r13
movl $0x1, %ebx
movl %ebp, %eax
movq %rdi, 0x20(%rsp)
movq %r8, 0x18(%rsp)
cmpl %r12d, %eax
jl 0x20f38
movl 0x14(%rsp), %ebp
movl %ebp, %edi
leaq 0xa(%rsp), %rsi
movl $0x2, %edx
callq 0x201c2
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jne 0x20f81
movzwl 0xa(%rsp), %edx
movq 0x196abe(%rip), %rsi    # 0x1b79c0
movl %ebp, %edi
callq 0x201c2
movzwl 0xa(%rsp), %esi
cmpl %esi, %eax
jne 0x20f81
movq 0x196aa7(%rip), %rdi    # 0x1b79c0
movq 0x196aa8(%rip), %rdx    # 0x1b79c8
callq 0x21063
movl %eax, %r12d
xorl %eax, %eax
movl 0xc(%rsp), %ebp
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r8
testl %ebp, %ebp
je 0x20f63
movslq %eax, %rcx
xorl %edx, %edx
movq 0x196a80(%rip), %rsi    # 0x1b79c8
addq %rcx, %rsi
movb (%rdx,%rsi), %sil
addb (%r14,%rdx), %sil
movb %sil, (%r13,%rdx)
incq %rdx
movq %r15, %rsi
addq %rdx, %rsi
jne 0x20f41
addl %ebp, %eax
addq %r8, %r14
incq %rbx
addq %r8, %r13
cmpq %rdi, %rbx
jne 0x20ecd
movl 0x10(%rsp), %r12d
jmp 0x20f81
movl %ebx, %r12d
movb $0x1, 0x196a4c(%rip)    # 0x1b79d4
movl $0x1010101, 0x196a3e(%rip) # imm = 0x1010101
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq