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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %r14
callq 0x20fa4
cmpl $0x4001, %r15d          # imm = 0x4001
movl $0x1, %r13d
movl %r15d, %ebx
cmovael %r13d, %ebx
cmovael %r15d, %r13d
movq 0x1965bd(%rip), %rsi    # 0x1b79c8
movq %r14, %rdi
movl %ebx, %edx
callq 0x4ac52
movl %ebx, %esi
movl $0x4000, %r9d           # imm = 0x4000
subl %ebx, %r9d
movl %ebx, %r15d
cmpl %r9d, %ebx
movl %ebx, 0x10(%rsp)
movl %r9d, 0xc(%rsp)
jbe 0x21496
movq 0x196590(%rip), %rdi    # 0x1b79c8
movq 0x196581(%rip), %rdx    # 0x1b79c0
callq 0x215d8
movl %eax, %r15d
leaq 0xa(%rsp), %rsi
movw %r15w, (%rsi)
movl $0x2, %edx
movl %ebp, %edi
callq 0x6af0
cmpq $0x2, %rax
jne 0x215b2
movq 0x196553(%rip), %rsi    # 0x1b79c0
movl %r13d, %ebx
movzwl %r15w, %r13d
movl %ebp, %edi
movq %r13, %rdx
callq 0x6af0
xorl %r15d, %r15d
cmpq %r13, %rax
movl %ebx, %r13d
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %r9d
jne 0x215b5
imull %r12d, %r13d
cmpl $0x2, %r13d
jb 0x21557
movl %esi, %r12d
movl $0x1, %ebx
movl %r13d, 0x14(%rsp)
testl %esi, %esi
je 0x214dc
movl %r15d, %eax
leaq (%r14,%r12), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %r8b
subb (%r14,%rdx), %r8b
movq 0x1964fb(%rip), %rdi    # 0x1b79c8
addq %rax, %rdi
movb %r8b, (%rdx,%rdi)
incq %rdx
cmpq %rdx, %r12
jne 0x214be
addl %esi, %r15d
cmpl %r9d, %r15d
jbe 0x21549
movq 0x1964dd(%rip), %rdi    # 0x1b79c8
movq 0x1964ce(%rip), %rdx    # 0x1b79c0
movl %r15d, %esi
callq 0x215d8
movl %eax, %r15d
movw %r15w, 0xa(%rsp)
movl $0x2, %edx
movl %ebp, %edi
leaq 0xa(%rsp), %rsi
callq 0x6af0
cmpq $0x2, %rax
jne 0x215b2
movq 0x19649b(%rip), %rsi    # 0x1b79c0
movzwl %r15w, %r13d
movl %ebp, %edi
movq %r13, %rdx
callq 0x6af0
xorl %r15d, %r15d
cmpq %r13, %rax
movl 0x14(%rsp), %r13d
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %r9d
jne 0x215b5
addq %r12, %r14
incl %ebx
cmpl %r13d, %ebx
jne 0x214b1
testl %r15d, %r15d
je 0x215ad
movq 0x196465(%rip), %rdi    # 0x1b79c8
movq 0x196456(%rip), %rdx    # 0x1b79c0
movl %r15d, %esi
callq 0x215d8
movl %ebp, %ebx
movl %eax, %ebp
leaq 0xa(%rsp), %rsi
movw %bp, (%rsi)
movl $0x2, %edx
movl %ebx, %edi
callq 0x6af0
xorl %r15d, %r15d
cmpq $0x2, %rax
jne 0x215b5
movq 0x196426(%rip), %rsi    # 0x1b79c0
movzwl %bp, %r14d
movl %ebx, %edi
movq %r14, %rdx
callq 0x6af0
cmpq %r14, %rax
jne 0x215b5
movl %r13d, %r15d
jmp 0x215b5
xorl %r15d, %r15d
movb $0x1, 0x196418(%rip)    # 0x1b79d4
movl $0x1010101, 0x19640a(%rip) # imm = 0x1010101
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq