// File: /workspace/github_c_makefile_star2_O3/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 0x213a6
cmpl $0x4001, %r15d          # imm = 0x4001
movl $0x1, %r13d
movl %r15d, %ebx
cmovael %r13d, %ebx
cmovael %r15d, %r13d
movq 0x1971aa(%rip), %rsi    # 0x1b89c8
movq %r14, %rdi
movl %ebx, %edx
callq 0x4d437
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 0x218a9
movq 0x19717d(%rip), %rdi    # 0x1b89c8
movq 0x19716e(%rip), %rdx    # 0x1b89c0
callq 0x219eb
movl %eax, %r15d
leaq 0xa(%rsp), %rsi
movw %r15w, (%rsi)
movl $0x2, %edx
movl %ebp, %edi
callq 0x6af0
cmpq $0x2, %rax
jne 0x219c5
movq 0x197140(%rip), %rsi    # 0x1b89c0
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 0x219c8
imull %r12d, %r13d
cmpl $0x2, %r13d
jb 0x2196a
movl %esi, %r12d
movl $0x1, %ebx
movl %r13d, 0x14(%rsp)
testl %esi, %esi
je 0x218ef
movl %r15d, %eax
leaq (%r14,%r12), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %r8b
subb (%r14,%rdx), %r8b
movq 0x1970e8(%rip), %rdi    # 0x1b89c8
addq %rax, %rdi
movb %r8b, (%rdx,%rdi)
incq %rdx
cmpq %rdx, %r12
jne 0x218d1
addl %esi, %r15d
cmpl %r9d, %r15d
jbe 0x2195c
movq 0x1970ca(%rip), %rdi    # 0x1b89c8
movq 0x1970bb(%rip), %rdx    # 0x1b89c0
movl %r15d, %esi
callq 0x219eb
movl %eax, %r15d
movw %r15w, 0xa(%rsp)
movl $0x2, %edx
movl %ebp, %edi
leaq 0xa(%rsp), %rsi
callq 0x6af0
cmpq $0x2, %rax
jne 0x219c5
movq 0x197088(%rip), %rsi    # 0x1b89c0
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 0x219c8
addq %r12, %r14
incl %ebx
cmpl %r13d, %ebx
jne 0x218c4
testl %r15d, %r15d
je 0x219c0
movq 0x197052(%rip), %rdi    # 0x1b89c8
movq 0x197043(%rip), %rdx    # 0x1b89c0
movl %r15d, %esi
callq 0x219eb
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 0x219c8
movq 0x197013(%rip), %rsi    # 0x1b89c0
movzwl %bp, %r14d
movl %ebx, %edi
movq %r14, %rdx
callq 0x6af0
cmpq %r14, %rax
jne 0x219c8
movl %r13d, %r15d
jmp 0x219c8
xorl %r15d, %r15d
movb $0x1, 0x197005(%rip)    # 0x1b89d4
movl $0x1010101, 0x196ff7(%rip) # imm = 0x1010101
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq