// File: /workspace/github_c_makefile_star2_O0/zhiyb[P]png2tlg/png2tlg.cpp
// Function: SlideCompressor::GetMatch(unsigned char const*, int, int&, int)
int SlideCompressor::GetMatch(const unsigned char*cur, int curlen, int &pos, int s)
{
	// get match length
	if(curlen < 3) return 0;

	int place = cur[0] + ((int)cur[1] << 8);

	int maxlen = 0;
	if((place = Map[place]) != -1)
	{
		int place_org;
		curlen -= 1;
		do
		{
			place_org = place;
			if(s == place || s == ((place + 1) & (SLIDE_N -1))) continue;
			place += 2;
			int lim = (SLIDE_M < curlen ? SLIDE_M : curlen) + place_org;
			const unsigned char *c = cur + 2;
			if(lim >= SLIDE_N)
			{
				if(place_org <= s && s < SLIDE_N)
					lim = s;
				else if(s < (lim&(SLIDE_N-1)))
					lim = s + SLIDE_N;
			}
			else
			{
				if(place_org <= s && s < lim)
					lim = s;
			}
			while(Text[place] == *(c++) && place < lim) place++;
			int matchlen = place - place_org;
			if(matchlen > maxlen) pos = place_org, maxlen = matchlen;
			if(matchlen == SLIDE_M) return maxlen;

		} while((place = Chains[place_org].Next) != -1);
	}
	return maxlen;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpl $0x3, -0x1c(%rbp)
jge 0x4131
movl $0x0, -0x4(%rbp)
jmp 0x42ca
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movzbl (%rcx), %ecx
movq -0x18(%rbp), %rdx
movzbl 0x1(%rdx), %edx
shll $0x8, %edx
addl %edx, %ecx
movl %ecx, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movslq -0x30(%rbp), %rcx
movl 0x1118(%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
cmpl $-0x1, %eax
je 0x42c4
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x4194
movl -0x2c(%rbp), %eax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
andl $0xfff, %ecx            # imm = 0xFFF
cmpl %ecx, %eax
jne 0x4199
jmp 0x42a7
movl -0x30(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
movl $0x111, %eax            # imm = 0x111
cmpl -0x1c(%rbp), %eax
jge 0x41b6
movl $0x111, %eax            # imm = 0x111
movl %eax, -0x5c(%rbp)
jmp 0x41bc
movl -0x1c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
cmpl $0x1000, -0x3c(%rbp)    # imm = 0x1000
jl 0x4212
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x41f3
cmpl $0x1000, -0x2c(%rbp)    # imm = 0x1000
jge 0x41f3
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x4210
movl -0x2c(%rbp), %eax
movl -0x3c(%rbp), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
cmpl %ecx, %eax
jge 0x420e
movl -0x2c(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x3c(%rbp)
jmp 0x4210
jmp 0x422a
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x4228
movl -0x2c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x4228
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x422a
jmp 0x422c
movq -0x58(%rbp), %rax
movslq -0x30(%rbp), %rcx
movzbl 0x8(%rax,%rcx), %ecx
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movzbl (%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x5d(%rbp)
jne 0x4260
movl -0x30(%rbp), %eax
cmpl -0x3c(%rbp), %eax
setl %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x4269
jmp 0x4274
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x422c
movl -0x30(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x4294
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x4c(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x111, -0x4c(%rbp)     # imm = 0x111
jne 0x42a5
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x42ca
jmp 0x42a7
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl 0x4111c(%rax,%rcx,8), %eax
movl %eax, -0x30(%rbp)
cmpl $-0x1, %eax
jne 0x4173
jmp 0x42c4
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nop