// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/cache1d.c
// Function: lzwcompress
static int lzwcompress(unsigned char *lzwinbuf, int uncompleng, unsigned char *lzwoutbuf)
{
	int i, addr, newaddr, addrcnt, zx;
	int *intptr;
	int bytecnt1, bitcnt, numbits, oneupnumbits;
	short *shortptr;

	for(i=255;i>=0;i--) { lzwbuf1[i] = i; lzwbuf3[i] = (i+1)&255; }
	clearbuf(lzwbuf2,256>>1,0xffffffff);
	clearbuf(lzwoutbuf,((uncompleng+15)+3)>>2,0L);

	addrcnt = 256; bytecnt1 = 0; bitcnt = (4<<3);
	numbits = 8; oneupnumbits = (1<<8);
	do
	{
		addr = lzwinbuf[bytecnt1];
		do
		{
			bytecnt1++;
			if (bytecnt1 == uncompleng) break;
			if (lzwbuf2[addr] < 0) {lzwbuf2[addr] = addrcnt; break;}
			newaddr = lzwbuf2[addr];
			while (lzwbuf1[newaddr] != lzwinbuf[bytecnt1])
			{
				zx = lzwbuf3[newaddr];
				if (zx < 0) {lzwbuf3[newaddr] = addrcnt; break;}
				newaddr = zx;
			}
			if (lzwbuf3[newaddr] == addrcnt) break;
			addr = newaddr;
		} while (addr >= 0);
		lzwbuf1[addrcnt] = lzwinbuf[bytecnt1];
		lzwbuf2[addrcnt] = -1;
		lzwbuf3[addrcnt] = -1;

		intptr = (int *)&lzwoutbuf[bitcnt>>3];
		intptr[0] |= B_LITTLE32(addr<<(bitcnt&7));
		bitcnt += numbits;
		if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1)))
			bitcnt--;

		addrcnt++;
		if (addrcnt > oneupnumbits) { numbits++; oneupnumbits <<= 1; }
	} while ((bytecnt1 < uncompleng) && (bitcnt < (uncompleng<<3)));

	intptr = (int *)&lzwoutbuf[bitcnt>>3];
	intptr[0] |= B_LITTLE32(addr<<(bitcnt&7));
	bitcnt += numbits;
	if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1)))
		bitcnt--;

	shortptr = (short *)lzwoutbuf;
	shortptr[0] = B_LITTLE16((short)uncompleng);
	if (((bitcnt+7)>>3) < uncompleng)
	{
		shortptr[1] = B_LITTLE16((short)addrcnt);
		return((bitcnt+7)>>3);
	}
	shortptr[1] = 0;
	for(i=0;i<uncompleng;i++) lzwoutbuf[i+4] = lzwinbuf[i];
	return(uncompleng+4);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movl %esi, %r14d
movq %rdi, %r15
movl $0xff, %eax
movq 0x196fca(%rip), %rcx    # 0x1b89d8
movb %al, (%rcx,%rax)
leal 0x1(%rax), %ecx
movzbl %cl, %ecx
movq 0x196fca(%rip), %rdx    # 0x1b89e8
movw %cx, (%rdx,%rax,2)
addq $-0x1, %rax
jb 0x21a07
movq 0x196fb1(%rip), %rdi    # 0x1b89e0
movl $0x80, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4d2d8
leal 0x12(%r14), %esi
shrl $0x2, %esi
xorl %r12d, %r12d
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4d2d8
leal (,%r14,8), %eax
movl %eax, 0xc(%rsp)
movslq %r14d, %r9
movl $0x100, %esi            # imm = 0x100
movl $0x8, %eax
movl $0x20, %edx
movl $0x100, %r13d           # imm = 0x100
movw $0xffff, %r11w          # imm = 0xFFFF
movq %r13, %rdi
movslq %r12d, %r12
movzbl (%r15,%r12), %ecx
movl %ecx, %r10d
incq %r12
cmpq %r9, %r12
je 0x21aee
movq 0x196f43(%rip), %rcx    # 0x1b89e0
movl %r10d, %r8d
movzwl (%rcx,%r8,2), %ebx
testw %bx, %bx
js 0x21af3
movq 0x196f27(%rip), %rbp    # 0x1b89d8
movb (%r15,%r12), %r8b
movq 0x196f2c(%rip), %r13    # 0x1b89e8
movzwl %bx, %ecx
cmpb %r8b, (%rbp,%rcx)
je 0x21ade
movzwl (%r13,%rcx,2), %ebx
testw %bx, %bx
jns 0x21abc
movw %di, (%r13,%rcx,2)
movq 0x196f0a(%rip), %r13    # 0x1b89e8
movswq (%r13,%rcx,2), %r8
movl %r8d, %r8d
cmpq %r8, %rdi
jne 0x21a8b
jmp 0x21af8
movl %r14d, %r12d
jmp 0x21af8
movw %di, (%rcx,%r8,2)
movslq %r12d, %rbp
movb (%r15,%rbp), %cl
movq 0x196ed2(%rip), %r8     # 0x1b89d8
movb %cl, (%r8,%rdi)
movq 0x196ecf(%rip), %rcx    # 0x1b89e0
movw %r11w, (%rcx,%rdi,2)
movq 0x196ecb(%rip), %rcx    # 0x1b89e8
movw %r11w, (%rcx,%rdi,2)
movl %edx, %r8d
sarl $0x3, %r8d
movl %edx, %ecx
andb $0x7, %cl
movl %r10d, %ebx
shll %cl, %ebx
movslq %r8d, %rcx
movq 0x10(%rsp), %r8
orl %ebx, (%r8,%rcx)
addl %eax, %edx
movl %esi, %ecx
sarl %ecx
decl %ecx
movl %r10d, %r8d
andl %ecx, %r8d
leal -0x1(%rdi), %ebx
andl %ecx, %ebx
xorl %ecx, %ecx
cmpl %ebx, %r8d
setg %cl
subl %ecx, %edx
leaq 0x1(%rdi), %r13
movslq %esi, %rsi
xorl %ecx, %ecx
cmpq %rsi, %rdi
setge %cl
addl %ecx, %eax
shll %cl, %esi
cmpl %r14d, %ebp
jge 0x21b7e
cmpl 0xc(%rsp), %edx
jl 0x21a80
movl %edx, %r8d
sarl $0x3, %r8d
movl %edx, %ecx
andb $0x7, %cl
movl %r10d, %r9d
shll %cl, %r9d
movslq %r8d, %rcx
movq 0x10(%rsp), %r8
orl %r9d, (%r8,%rcx)
sarl %esi
decl %esi
andl %esi, %r10d
andl %edi, %esi
cmpl %r10d, %esi
sbbl $0x0, %eax
movw %r14w, (%r8)
addl %edx, %eax
addl $0x7, %eax
sarl $0x3, %eax
cmpl %r14d, %eax
jge 0x21bc3
movw %r13w, 0x2(%r8)
jmp 0x21bec
movw $0x0, 0x2(%r8)
testl %r14d, %r14d
jle 0x21be5
movl %r14d, %eax
xorl %ecx, %ecx
movb (%r15,%rcx), %dl
movb %dl, 0x4(%r8,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x21bd4
addl $0x4, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq