// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/png2tlg.cpp
// Function: SlideCompressor::Encode(unsigned char const*, long, unsigned char*, long&)
void SlideCompressor::Encode(const unsigned char *in, long inlen,
		unsigned char *out, long & outlen)
{
	unsigned char code[40], codeptr, mask;

	if(inlen == 0) return;

	outlen = 0;
	code[0] = 0;
	codeptr = mask = 1;

	int s = S;
	while(inlen > 0)
	{
		int pos = 0;
		int len = GetMatch(in, inlen, pos, s);
		if(len >= 3)
		{
			code[0] |= mask;
			if(len >= 18)
			{
				code[codeptr++] = pos & 0xff;
				code[codeptr++] = ((pos &0xf00)>> 8) | 0xf0;
				code[codeptr++] = len - 18;
			}
			else
			{
				code[codeptr++] = pos & 0xff;
				code[codeptr++] = ((pos&0xf00)>> 8) | ((len-3)<<4);
			}
			while(len--)
			{
				unsigned char c = 0[in++];
				DeleteMap((s - 1) & (SLIDE_N - 1));
				DeleteMap(s);
				if(s < SLIDE_M - 1) Text[s + SLIDE_N] = c;
				Text[s] = c;
				AddMap((s - 1) & (SLIDE_N - 1));
				AddMap(s);
				s++;
				inlen--;
				s &= (SLIDE_N - 1);
			}
		}
		else
		{
			unsigned char c = 0[in++];
			DeleteMap((s - 1) & (SLIDE_N - 1));
			DeleteMap(s);
			if(s < SLIDE_M - 1) Text[s + SLIDE_N] = c;
			Text[s] = c;
	 		AddMap((s - 1) & (SLIDE_N - 1));
			AddMap(s);
			s++;
			inlen--;
			s &= (SLIDE_N - 1);
			code[codeptr++] = c;
		}
		mask <<= 1;

		if(mask == 0)
		{
			for(int i = 0; i < codeptr; i++)
				out[outlen++] = code[i];
			mask = codeptr = 1;
			code[0] = 0;
		}
	}

	if(mask != 1)
	{
		for(int i = 0; i < codeptr; i++)
			out[outlen++] = code[i];
	}

	S = s;
}

// Assembly:
testq %rdx, %rdx
je 0x4b88
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq -0x58(%rsp), %rsp
movq %rdi, %rbx
movq $0x0, (%r8)
movb $0x0, 0x30(%rsp)
movl 0x92228(%rdi), %ebp
jle 0x4b74
movq %rdx, %r12
movb $0x1, 0x3(%rsp)
movb $0x1, %r15b
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movl $0x0, 0x4(%rsp)
movq %rbx, %rdi
movl %r12d, %edx
leaq 0x4(%rsp), %rcx
movl %ebp, %r8d
movq %rsi, %r14
callq 0x467c
movq %r15, %rdi
movzbl %r15b, %r15d
cmpl $0x3, %eax
movq %r14, 0x8(%rsp)
jl 0x48df
movb 0x3(%rsp), %cl
orb %cl, 0x30(%rsp)
movl 0x4(%rsp), %esi
leal 0x1(%r15), %ecx
movb %sil, 0x30(%rsp,%r15)
shrl $0x8, %esi
cmpl $0x12, %eax
movq %r12, 0x18(%rsp)
jb 0x49d2
orb $-0x10, %sil
movzbl %cl, %ecx
movq %rdi, %r9
addl $0x2, %edi
movb %sil, 0x30(%rsp,%rcx)
leal -0x12(%rax), %edx
movb $0x3, %r8b
movl %edi, %ecx
movq 0x8(%rsp), %rsi
jmp 0x49ea
movq %r12, %r13
movb (%r14), %r14b
leal -0x1(%rbp), %r12d
andl $0xfff, %r12d           # imm = 0xFFF
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4796
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4796
movslq %ebp, %rax
cmpl $0x10f, %ebp            # imm = 0x10F
jg 0x4918
movb %r14b, 0x1008(%rbx,%rax)
movb %r14b, 0x8(%rbx,%rax)
movzbl 0x8(%rbx,%r12), %ecx
movl %ebp, %edx
andl $0xfff, %edx            # imm = 0xFFF
movzbl 0x8(%rbx,%rdx), %edx
shll $0xa, %edx
leal (%rdx,%rcx,4), %edx
movslq 0x1118(%rbx,%rdx), %rcx
movl %r12d, 0x1118(%rbx,%rdx)
cmpq $-0x1, %rcx
je 0x4968
movl %r12d, 0x41118(%rbx,%rcx,8)
movl %ecx, 0x4111c(%rbx,%r12,8)
movl $0xffffffff, 0x41118(%rbx,%r12,8) # imm = 0xFFFFFFFF
movzbl 0x8(%rbx,%rax), %edx
leal 0x1(%rbp), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movzbl 0x8(%rbx,%rcx), %esi
shll $0xa, %esi
leal (%rsi,%rdx,4), %esi
movslq 0x1118(%rbx,%rsi), %rdx
movl %ebp, 0x1118(%rbx,%rsi)
cmpq $-0x1, %rdx
movq 0x8(%rsp), %rsi
je 0x49b4
movl %ebp, 0x41118(%rbx,%rdx,8)
movl %edx, 0x4111c(%rbx,%rax,8)
movl $0xffffffff, 0x41118(%rbx,%rax,8) # imm = 0xFFFFFFFF
incq %rsi
movq %r13, %r12
decq %r12
leal 0x1(%r15), %eax
movq %rax, 0x10(%rsp)
movb %r14b, 0x30(%rsp,%r15)
movl %ecx, %ebp
jmp 0x4ae9
andl $0xf, %esi
movl %eax, %edx
shll $0x4, %edx
orl %esi, %edx
addb $-0x30, %dl
movb $0x2, %r8b
movq 0x8(%rsp), %rsi
movq %rdi, %r9
addb %r8b, %r9b
movq %r9, 0x10(%rsp)
movzbl %cl, %ecx
movb %dl, 0x30(%rsp,%rcx)
movl %eax, %r14d
xorl %r15d, %r15d
movb (%rsi,%r15), %r13b
leal -0x1(%rbp), %r12d
andl $0xfff, %r12d           # imm = 0xFFF
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4796
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4796
movslq %ebp, %rax
cmpl $0x10f, %ebp            # imm = 0x10F
jg 0x4a36
movb %r13b, 0x1008(%rbx,%rax)
movb %r13b, 0x8(%rbx,%rax)
movzbl 0x8(%rbx,%r12), %ecx
movl %eax, %edx
andl $0xfff, %edx            # imm = 0xFFF
movzbl 0x8(%rbx,%rdx), %edx
shll $0xa, %edx
leal (%rdx,%rcx,4), %edx
movslq 0x1118(%rbx,%rdx), %rcx
movl %r12d, 0x1118(%rbx,%rdx)
cmpq $-0x1, %rcx
je 0x4a86
movl %r12d, 0x41118(%rbx,%rcx,8)
movl %ecx, 0x4111c(%rbx,%r12,8)
movl $0xffffffff, 0x41118(%rbx,%r12,8) # imm = 0xFFFFFFFF
movzbl 0x8(%rbx,%rax), %ecx
leal 0x1(%rax), %ebp
andl $0xfff, %ebp            # imm = 0xFFF
movzbl 0x8(%rbx,%rbp), %edx
shll $0xa, %edx
leal (%rdx,%rcx,4), %edx
movslq 0x1118(%rbx,%rdx), %rcx
movl %eax, 0x1118(%rbx,%rdx)
cmpq $-0x1, %rcx
movq 0x8(%rsp), %rsi
je 0x4ad2
movl %eax, 0x41118(%rbx,%rcx,8)
movl %ecx, 0x4111c(%rbx,%rax,8)
movl $0xffffffff, 0x41118(%rbx,%rax,8) # imm = 0xFFFFFFFF
incq %r15
cmpl %r15d, %r14d
jne 0x49ff
addq %r15, %rsi
movq 0x18(%rsp), %r12
subq %r15, %r12
movb 0x3(%rsp), %al
addb %al, %al
movb %al, 0x3(%rsp)
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
je 0x4b0f
testq %r12, %r12
movq 0x10(%rsp), %r15
jg 0x4866
jmp 0x4b4f
movq 0x10(%rsp), %rax
testb %al, %al
je 0x4b37
movzbl %al, %eax
xorl %ecx, %ecx
movb 0x30(%rsp,%rcx), %dl
movq (%r8), %r10
leaq 0x1(%r10), %rdi
movq %rdi, (%r8)
movb %dl, (%r9,%r10)
incq %rcx
cmpq %rcx, %rax
jne 0x4b1d
movb $0x0, 0x30(%rsp)
movb $0x1, 0x3(%rsp)
movb $0x1, %r15b
testq %r12, %r12
jg 0x4866
jmp 0x4b74
testb %r15b, %r15b
je 0x4b74
movzbl %r15b, %eax
xorl %ecx, %ecx
movb 0x30(%rsp,%rcx), %dl
movq (%r8), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, (%r8)
movb %dl, (%r9,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0x4b5a
movl %ebp, 0x92228(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop