// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
callq 0x31780
cmpl $0x4000, -0x14(%rbp)    # imm = 0x4000
jbe 0x315a4
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x1c(%rbp), %edi
leaq -0x3a(%rbp), %rsi
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x315d3
callq 0x31870
movl $0x0, -0x4(%rbp)
jmp 0x31773
movw -0x3a(%rbp), %ax
movw %ax, -0x3a(%rbp)
movl -0x1c(%rbp), %edi
movq 0x1c3f3b(%rip), %rsi    # 0x1f5520
movzwl -0x3a(%rbp), %edx
callq 0x302b0
movzwl -0x3a(%rbp), %ecx
cmpl %ecx, %eax
je 0x31607
callq 0x31870
movl $0x0, -0x4(%rbp)
jmp 0x31773
movl $0x0, -0x34(%rbp)
movq 0x1c3f0b(%rip), %rdi    # 0x1f5520
movzwl -0x3a(%rbp), %esi
movq 0x1c3f08(%rip), %rdx    # 0x1f5528
callq 0x318a0
movl %eax, -0x38(%rbp)
movq 0x1c3ef9(%rip), %rdi    # 0x1f5528
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x6ef00
movl -0x14(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq $0x1, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x31768
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x316e0
movl -0x1c(%rbp), %edi
leaq -0x3a(%rbp), %rsi
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x3168b
callq 0x31870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31773
movw -0x3a(%rbp), %ax
movw %ax, -0x3a(%rbp)
movl -0x1c(%rbp), %edi
movq 0x1c3e83(%rip), %rsi    # 0x1f5520
movzwl -0x3a(%rbp), %edx
callq 0x302b0
movzwl -0x3a(%rbp), %ecx
cmpl %ecx, %eax
je 0x316bf
callq 0x31870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31773
movl $0x0, -0x34(%rbp)
movq 0x1c3e53(%rip), %rdi    # 0x1f5520
movzwl -0x3a(%rbp), %esi
movq 0x1c3e50(%rip), %rdx    # 0x1f5528
callq 0x318a0
movl %eax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
cmpq %rcx, %rax
jae 0x3173e
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x1c3e21(%rip), %rcx    # 0x1f5528
movq -0x30(%rbp), %rdx
movslq -0x34(%rbp), %rsi
addq %rsi, %rdx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x14(%rbp), %esi
addq %rsi, %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x316e8
movl -0x14(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x14(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3164c
callq 0x31870
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)