// File: /workspace/github_c_makefile_star2_O2/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 0x45a9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbp
movq %rdi, %r15
andq $0x0, (%r8)
movb $0x0, 0x30(%rsp)
movl 0x92228(%rdi), %r12d
movb $0x1, %bl
movb $0x1, 0x3(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movzbl %bl, %r14d
testq %rdx, %rdx
jle 0x458d
andl $0x0, 0x4(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq %rdx, 0x8(%rsp)
leaq 0x4(%rsp), %rcx
movl %r12d, %r8d
callq 0x41fe
cmpl $0x3, %eax
jl 0x4428
movl %eax, %r13d
movb 0x3(%rsp), %al
orb %al, 0x30(%rsp)
movl 0x4(%rsp), %edx
leal 0x1(%r14), %eax
movb %dl, 0x30(%rsp,%r14)
shrl $0x8, %edx
cmpl $0x12, %r13d
jb 0x44a1
orb $-0x10, %dl
movzbl %al, %eax
leal 0x2(%rbx), %esi
movb %dl, 0x30(%rsp,%rax)
leal -0x12(%r13), %ecx
movb $0x3, %dl
movl %esi, %eax
jmp 0x44b1
movb (%rbp), %bl
leal -0x1(%r12), %r13d
andl $0xfff, %r13d           # imm = 0xFFF
movq %r15, %rdi
movl %r13d, %esi
callq 0x42fa
movq %r15, %rdi
movl %r12d, %esi
callq 0x42fa
movslq %r12d, %rax
cmpl $0x10f, %r12d           # imm = 0x10F
jg 0x4461
movb %bl, 0x1008(%r15,%rax)
incq %rbp
movb %bl, 0x8(%r15,%rax)
movq %r15, %rdi
movl %r13d, %esi
callq 0x41aa
movq %r15, %rdi
movl %r12d, %esi
callq 0x41aa
incl %r12d
movq 0x8(%rsp), %rdx
decq %rdx
andl $0xfff, %r12d           # imm = 0xFFF
movl %ebx, %eax
leal 0x1(%r14), %ebx
movb %al, 0x30(%rsp,%r14)
jmp 0x453f
andl $0xf, %edx
movl %r13d, %ecx
shll $0x4, %ecx
orl %edx, %ecx
addb $-0x30, %cl
movb $0x2, %dl
addb %dl, %bl
movq %rbx, 0x18(%rsp)
movzbl %al, %eax
movb %cl, 0x30(%rsp,%rax)
movl %r13d, %eax
movq %rax, 0x10(%rsp)
subl $0x1, %r13d
jb 0x4530
movb (%rbp), %bl
leal -0x1(%r12), %r14d
andl $0xfff, %r14d           # imm = 0xFFF
movq %r15, %rdi
movl %r14d, %esi
callq 0x42fa
movq %r15, %rdi
movl %r12d, %esi
callq 0x42fa
cmpl $0x10f, %r12d           # imm = 0x10F
movslq %r12d, %r12
jg 0x4506
movb %bl, 0x1008(%r15,%r12)
incq %rbp
movb %bl, 0x8(%r15,%r12)
movq %r15, %rdi
movl %r14d, %esi
callq 0x41aa
movq %r15, %rdi
movl %r12d, %esi
callq 0x41aa
incl %r12d
andl $0xfff, %r12d           # imm = 0xFFF
jmp 0x44c7
movq 0x8(%rsp), %rdx
subq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rbx
movb 0x3(%rsp), %al
addb %al, %al
movb %al, 0x3(%rsp)
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rcx
jne 0x43ba
movzbl %bl, %eax
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x457c
movb 0x30(%rsp,%r9), %r10b
movq (%r8), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, (%r8)
movb %r10b, (%rcx,%rsi)
incq %r9
jmp 0x455f
movb $0x0, 0x30(%rsp)
movb $0x1, %bl
movb $0x1, 0x3(%rsp)
jmp 0x43ba
cmpb $0x1, 0x3(%rsp)
jne 0x45aa
movl %r12d, 0x92228(%r15)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpq %rax, %r14
je 0x4594
movb 0x30(%rsp,%rax), %dil
movq (%r8), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r8)
movb %dil, (%rcx,%rdx)
incq %rax
jmp 0x45ac
nop