// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %ecx, %ebp
movl %edx, 0x10(%rsp)
movl %esi, %r13d
movq %rdi, %r14
callq 0x1ea64
cmpl $0x4001, %r13d          # imm = 0x4001
pushq $0x1
popq %rbx
movl %r13d, %r15d
cmovael %ebx, %r15d
cmovbl %ebx, %r13d
movq 0x192b21(%rip), %rsi    # 0x1b19c8
movq %r14, %rdi
movl %r15d, %edx
callq 0x44524
movl %r15d, %esi
movl %ebx, %edi
movl $0x4000, %r9d           # imm = 0x4000
subl %r15d, %r9d
movl %r15d, %r12d
cmpl %r9d, %r15d
movl %r15d, 0x18(%rsp)
movl %r9d, 0x14(%rsp)
jbe 0x1ef3b
movl %edi, %r15d
movq 0x192aec(%rip), %rdi    # 0x1b19c8
movq 0x192add(%rip), %rdx    # 0x1b19c0
callq 0x1f089
movl %eax, %r12d
leaq 0xe(%rsp), %rsi
movw %r12w, (%rsi)
pushq $0x2
popq %rdx
movl %ebp, %edi
callq 0x6af0
cmpq $0x2, %rax
jne 0x1f00a
movq 0x192ab1(%rip), %rsi    # 0x1b19c0
movl %r13d, %ebx
movzwl %r12w, %r13d
movl %ebp, %edi
movq %r13, %rdx
callq 0x6af0
xorl %r12d, %r12d
cmpq %r13, %rax
movl %ebx, %r13d
movl %r15d, %edi
movl 0x18(%rsp), %esi
movl 0x14(%rsp), %r9d
jne 0x1f066
imull 0x10(%rsp), %r13d
movl %esi, %r10d
movq %r10, %rbx
negq %rbx
leaq (%r14,%r10), %r15
movl %r13d, 0x1c(%rsp)
movq %r10, 0x20(%rsp)
cmpl %r13d, %edi
jae 0x1f00f
movl %r12d, %eax
xorl %ecx, %ecx
movq %rbx, %rdx
addq %rcx, %rdx
je 0x1ef89
movb (%r15,%rcx), %dl
subb (%r14,%rcx), %dl
movq 0x192a4b(%rip), %r8     # 0x1b19c8
addq %rax, %r8
movb %dl, (%rcx,%r8)
incq %rcx
jmp 0x1ef66
addl %esi, %r12d
cmpl %r9d, %r12d
jbe 0x1effd
movl %edi, 0x10(%rsp)
movq 0x192a2c(%rip), %rdi    # 0x1b19c8
movq 0x192a1d(%rip), %rdx    # 0x1b19c0
movl %r12d, %esi
callq 0x1f089
movl %eax, %r12d
movw %r12w, 0xe(%rsp)
movl %ebp, %edi
leaq 0xe(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x6af0
cmpq $0x2, %rax
jne 0x1f00a
movq 0x1929f0(%rip), %rsi    # 0x1b19c0
movzwl %r12w, %r13d
movl %ebp, %edi
movq %r13, %rdx
callq 0x6af0
xorl %r12d, %r12d
cmpq %r13, %rax
movl 0x1c(%rsp), %r13d
movl 0x10(%rsp), %edi
movl 0x18(%rsp), %esi
movl 0x14(%rsp), %r9d
movq 0x20(%rsp), %r10
jne 0x1f066
addq %r10, %r14
incl %edi
addq %r10, %r15
jmp 0x1ef58
xorl %r12d, %r12d
jmp 0x1f066
testl %r12d, %r12d
je 0x1f063
movq 0x1929ad(%rip), %rdi    # 0x1b19c8
movq 0x19299e(%rip), %rdx    # 0x1b19c0
movl %r12d, %esi
callq 0x1f089
movl %eax, %r14d
leaq 0xe(%rsp), %rsi
movw %r14w, (%rsi)
pushq $0x2
popq %rdx
movl %ebp, %edi
callq 0x6af0
xorl %r12d, %r12d
cmpq $0x2, %rax
jne 0x1f066
movq 0x192970(%rip), %rsi    # 0x1b19c0
movzwl %r14w, %r14d
movl %ebp, %edi
movq %r14, %rdx
callq 0x6af0
cmpq %r14, %rax
jne 0x1f066
movl %r13d, %r12d
movb $0x1, 0x192967(%rip)    # 0x1b19d4
movl $0x1010101, 0x192959(%rip) # imm = 0x1010101
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq