// File: /workspace/github_c_makefile_star2_O1/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 0x4a2a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq -0x58(%rsp), %rsp
movq %rdi, %r15
movq $0x0, (%r8)
movb $0x0, 0x30(%rsp)
movl 0x92228(%rdi), %ebp
jle 0x49e6
movq %rdx, %r12
movb $0x1, 0x3(%rsp)
movb $0x1, %r14b
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movl $0x0, 0x4(%rsp)
movq %r15, %rdi
movl %r12d, %edx
leaq 0x4(%rsp), %rcx
movl %ebp, %r8d
movq %rsi, %rbx
callq 0x4506
movq %r14, %rdi
movzbl %r14b, %r14d
cmpl $0x3, %eax
movq %rbx, 0x8(%rsp)
jl 0x4769
movb 0x3(%rsp), %cl
orb %cl, 0x30(%rsp)
movl 0x4(%rsp), %esi
leal 0x1(%r14), %ecx
movb %sil, 0x30(%rsp,%r14)
shrl $0x8, %esi
cmpl $0x12, %eax
movq %r12, 0x18(%rsp)
jl 0x4862
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 0x487a
movq %r12, %r13
movb (%rbx), %bl
leal -0x1(%rbp), %r12d
andl $0xfff, %r12d           # imm = 0xFFF
movq %r15, %rdi
movl %r12d, %esi
callq 0x4632
movq %r15, %rdi
movl %ebp, %esi
callq 0x4632
movslq %ebp, %rax
cmpl $0x10f, %ebp            # imm = 0x10F
jg 0x47a1
movb %bl, 0x1008(%r15,%rax)
movb %bl, 0x8(%r15,%rax)
movzbl 0x8(%r15,%r12), %ecx
movl %ebp, %edx
andl $0xfff, %edx            # imm = 0xFFF
movzbl 0x8(%r15,%rdx), %edx
shll $0xa, %edx
leal (%rdx,%rcx,4), %edx
movslq 0x1118(%r15,%rdx), %rcx
movl %r12d, 0x1118(%r15,%rdx)
cmpq $-0x1, %rcx
je 0x47f2
movl %r12d, 0x41118(%r15,%rcx,8)
movl %ecx, 0x4111c(%r15,%r12,8)
movl $0xffffffff, 0x41118(%r15,%r12,8) # imm = 0xFFFFFFFF
movzbl 0x8(%r15,%rax), %edx
leal 0x1(%rbp), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movzbl 0x8(%r15,%rcx), %esi
shll $0xa, %esi
leal (%rsi,%rdx,4), %esi
movslq 0x1118(%r15,%rsi), %rdx
movl %ebp, 0x1118(%r15,%rsi)
cmpq $-0x1, %rdx
movq 0x8(%rsp), %rsi
je 0x4844
movl %ebp, 0x41118(%r15,%rdx,8)
movl %edx, 0x4111c(%r15,%rax,8)
movl $0xffffffff, 0x41118(%r15,%rax,8) # imm = 0xFFFFFFFF
incq %rsi
movq %r13, %r12
decq %r12
leal 0x1(%r14), %eax
movq %rax, 0x10(%rsp)
movb %bl, 0x30(%rsp,%r14)
movl %ecx, %ebp
jmp 0x497f
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, %ebx
xorl %r14d, %r14d
movb (%rsi,%r14), %r13b
leal -0x1(%rbp), %r12d
andl $0xfff, %r12d           # imm = 0xFFF
movq %r15, %rdi
movl %r12d, %esi
callq 0x4632
movq %r15, %rdi
movl %ebp, %esi
callq 0x4632
movslq %ebp, %rax
cmpl $0x10f, %ebp            # imm = 0x10F
jg 0x48c5
movb %r13b, 0x1008(%r15,%rax)
movb %r13b, 0x8(%r15,%rax)
movzbl 0x8(%r15,%r12), %ecx
movl %eax, %edx
andl $0xfff, %edx            # imm = 0xFFF
movzbl 0x8(%r15,%rdx), %edx
shll $0xa, %edx
leal (%rdx,%rcx,4), %edx
movslq 0x1118(%r15,%rdx), %rcx
movl %r12d, 0x1118(%r15,%rdx)
cmpq $-0x1, %rcx
je 0x4916
movl %r12d, 0x41118(%r15,%rcx,8)
movl %ecx, 0x4111c(%r15,%r12,8)
movl $0xffffffff, 0x41118(%r15,%r12,8) # imm = 0xFFFFFFFF
movzbl 0x8(%r15,%rax), %ecx
leal 0x1(%rax), %ebp
andl $0xfff, %ebp            # imm = 0xFFF
movzbl 0x8(%r15,%rbp), %edx
shll $0xa, %edx
leal (%rdx,%rcx,4), %edx
movslq 0x1118(%r15,%rdx), %rcx
movl %eax, 0x1118(%r15,%rdx)
cmpq $-0x1, %rcx
movq 0x8(%rsp), %rsi
je 0x4968
movl %eax, 0x41118(%r15,%rcx,8)
movl %ecx, 0x4111c(%r15,%rax,8)
movl $0xffffffff, 0x41118(%r15,%rax,8) # imm = 0xFFFFFFFF
incq %r14
cmpl %r14d, %ebx
jne 0x488e
addq %r14, %rsi
movq 0x18(%rsp), %r12
subq %r14, %r12
movb 0x3(%rsp), %al
addb %al, %al
movb %al, 0x3(%rsp)
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rcx
je 0x499c
movq 0x10(%rsp), %r14
jmp 0x49d3
movq 0x10(%rsp), %rax
testb %al, %al
je 0x49c6
movzbl %al, %eax
xorl %r9d, %r9d
movb 0x30(%rsp,%r9), %dl
movq (%r8), %r10
leaq 0x1(%r10), %rdi
movq %rdi, (%r8)
movb %dl, (%rcx,%r10)
incq %r9
cmpq %r9, %rax
jne 0x49ab
movb $0x0, 0x30(%rsp)
movb $0x1, %r14b
movb $0x1, 0x3(%rsp)
testq %r12, %r12
jg 0x46f0
cmpb $0x1, 0x3(%rsp)
sete %al
jmp 0x49eb
movb $0x1, %r14b
movb $0x1, %al
testb %al, %al
jne 0x4a15
testb %r14b, %r14b
je 0x4a15
movzbl %r14b, %eax
xorl %r9d, %r9d
movb 0x30(%rsp,%r9), %dl
movq (%r8), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, (%r8)
movb %dl, (%rcx,%rsi)
incq %r9
cmpq %r9, %rax
jne 0x49fb
movl %ebp, 0x92228(%r15)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop