// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/misc/codecs.cpp
// Function: ProbeComp(int, int, int*, int*, int, int, bool, int&, int&)
int ProbeComp(int s, int e, int line[], int prevline[], int sx, int ctsize, bool nvRLE, int &rBits, int &rBitsSAA)
{
	int	 pcirle;
	int	 allinpal = 0;
	int	 gallinpal = 0;
	int	 lbits = 0;
	int	 mod04 = 0;
	int	 mod16 = 0;
	int	 comp = 0;
	int	 compsaa = 0;

	int	 oldpalette[388];
	int	 oldpalentries = palentries;

	for (int i = 0; i < 388; i++) oldpalette[i] = palette[i];

	for (int x = s; x < e; x++)
	{
		int	 previousColor = (x > 0 ? line[x - 1] : 0);

		if ((x % 16) == mod16)
		{
			gallinpal = 1;

			for (int x2 = 0; x2 < 16; x2++)
			{
				if ((x + x2) < sx) if (GetPaletteEntry(line[x + x2]) == -1 ) { gallinpal = 0; break; }
			}

			comp++;
		}

		if (((x % 4) == mod04) && !gallinpal)
		{
			allinpal = 1;

			for (int x2 = 0; x2 < 4; x2++)
			{
				if ((x + x2) < sx) if (GetPaletteEntry(line[x + x2]) == -1 ) { allinpal = 0; break; }
			}

			comp++;
		}

		if ((GetPaletteEntry(line[x]) == -1))
		{
			if (GetDelta(line, prevline, x, ctsize)) comp +=  9;
			else					 comp += 26;

			if (palentries < 338)
			{
				palette[palentries] = line[x];
				palentries++;
			}
			else
			{
				RotatePalette(line[x]);
			}
		}
		else
		{
			if (!allinpal && !gallinpal) comp++;

			compsaa++;

			int	 saa = 0;

			if (GetSAA(line, prevline, x)) saa = 1;

			if ((palentries - 1) - GetPaletteEntry(line[x]) < 2)
			{
				comp += 2;

				if (saa) compsaa -= 2;
			}
			else
			{
				if ((palentries - 1) - GetPaletteEntry(line[x]) < 18)
				{
					lbits = Math::Min(GetMinimumBits(palentries - 2), 4);

					comp += (lbits + 2);

					if (saa) compsaa -= (lbits + 2);
				}
				else
				{
					if ((palentries - 1) - GetPaletteEntry(line[x]) < 82)
					{
						lbits = Math::Min(GetMinimumBits(palentries - 18), 6);

						comp += (lbits + 3);

						if (saa) compsaa -= (lbits + 3);
					}
					else
					{
						comp += (GetMinimumBits(palentries - 83) + 3);

						if (saa) compsaa -= (GetMinimumBits(palentries - 83) + 3);
					}
				}
			}


			int	 paletteEntry = GetPaletteEntry(line[x]);

			if (paletteEntry >= 0) RotatePaletteEntry(paletteEntry);
		}

		if (line[x] == previousColor)
		{
			pcirle = GetRLE(line, sx, x, 8);

			if (pcirle >= 2)
			{
				if (pcirle > 9) comp += 10;
				else		comp += 5;

				x = x + pcirle;

				allinpal = 0;
				gallinpal = 0;

				mod04 = (x + 1) %  4;
				mod16 = (x + 1) % 16;
			}
			else
			{
				comp++;
			}
		}
		else if (line[x] == prevline[x] && !nvRLE)
		{
			pcirle = GetVRLE(line, prevline, sx, x, 8);

			if (pcirle >= 2)
			{
				if (pcirle > 9) comp += 10;
				else		comp += 5;

				x = x + pcirle;

				allinpal = 0;
				gallinpal = 0;

				mod04 = (x + 1) %  4;
				mod16 = (x + 1) % 16;
			}
			else
			{
				comp++;
			}
		}
	}

	palentries = oldpalentries;

	for (int j = 0; j < 388; j++) palette[j] = oldpalette[j];

	rBits	 = comp;
	rBitsSAA = comp + compsaa;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6a0, %rsp            # imm = 0x6A0
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movb 0x10(%rbp), %al
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl 0xfe1e8(%rip), %eax     # 0x2144c0
movl %eax, -0x664(%rbp)
movl $0x0, -0x668(%rbp)
cmpl $0x184, -0x668(%rbp)    # imm = 0x184
jge 0x116324
movslq -0x668(%rbp), %rcx
leaq 0xfdbae(%rip), %rax     # 0x213eb0
movl (%rax,%rcx,4), %ecx
movslq -0x668(%rbp), %rax
movl %ecx, -0x660(%rbp,%rax,4)
movl -0x668(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x668(%rbp)
jmp 0x1162e8
movl -0x4(%rbp), %eax
movl %eax, -0x66c(%rbp)
movl -0x66c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x116897
cmpl $0x0, -0x66c(%rbp)
jle 0x116360
movq -0x10(%rbp), %rax
movl -0x66c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x688(%rbp)
jmp 0x11636a
xorl %eax, %eax
movl %eax, -0x688(%rbp)
jmp 0x11636a
movl -0x688(%rbp), %eax
movl %eax, -0x670(%rbp)
movl -0x66c(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl -0x3c(%rbp), %edx
jne 0x1163fb
movl $0x1, -0x30(%rbp)
movl $0x0, -0x674(%rbp)
cmpl $0x10, -0x674(%rbp)
jge 0x1163f2
movl -0x66c(%rbp), %eax
addl -0x674(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1163df
movq -0x10(%rbp), %rax
movl -0x66c(%rbp), %ecx
addl -0x674(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
cmpl $-0x1, %eax
jne 0x1163dd
movl $0x0, -0x30(%rbp)
jmp 0x1163f2
jmp 0x1163df
jmp 0x1163e1
movl -0x674(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x674(%rbp)
jmp 0x11639a
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x66c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl -0x38(%rbp), %edx
jne 0x116486
cmpl $0x0, -0x30(%rbp)
jne 0x116486
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x678(%rbp)
cmpl $0x4, -0x678(%rbp)
jge 0x11647d
movl -0x66c(%rbp), %eax
addl -0x678(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x11646a
movq -0x10(%rbp), %rax
movl -0x66c(%rbp), %ecx
addl -0x678(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
cmpl $-0x1, %eax
jne 0x116468
movl $0x0, -0x2c(%rbp)
jmp 0x11647d
jmp 0x11646a
jmp 0x11646c
movl -0x678(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x678(%rbp)
jmp 0x116425
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
cmpl $-0x1, %eax
jne 0x116525
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x66c(%rbp), %edx
movl -0x20(%rbp), %ecx
callq 0x116960
cmpl $0x0, %eax
je 0x1164c8
movl -0x40(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x40(%rbp)
jmp 0x1164d1
movl -0x40(%rbp), %eax
addl $0x1a, %eax
movl %eax, -0x40(%rbp)
cmpl $0x152, 0xfdfe5(%rip)   # imm = 0x152
jge 0x11650d
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movslq 0xfdfce(%rip), %rcx     # 0x2144c0
leaq 0xfd9b7(%rip), %rax     # 0x213eb0
movl %edx, (%rax,%rcx,4)
movl 0xfdfbe(%rip), %eax     # 0x2144c0
addl $0x1, %eax
movl %eax, 0xfdfb5(%rip)     # 0x2144c0
jmp 0x116520
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x1186e0
jmp 0x116719
cmpl $0x0, -0x2c(%rbp)
jne 0x11653a
cmpl $0x0, -0x30(%rbp)
jne 0x11653a
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x67c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x66c(%rbp), %edx
callq 0x118750
cmpl $0x0, %eax
je 0x11656f
movl $0x1, -0x67c(%rbp)
movl 0xfdf4b(%rip), %eax     # 0x2144c0
subl $0x1, %eax
movl %eax, -0x68c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
movl %eax, %ecx
movl -0x68c(%rbp), %eax
subl %ecx, %eax
cmpl $0x2, %eax
jge 0x1165c0
movl -0x40(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x67c(%rbp)
je 0x1165bb
movl -0x44(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x44(%rbp)
jmp 0x1166ea
movl 0xfdefa(%rip), %eax     # 0x2144c0
subl $0x1, %eax
movl %eax, -0x690(%rbp)
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
movl %eax, %ecx
movl -0x690(%rbp), %eax
subl %ecx, %eax
cmpl $0x12, %eax
jge 0x116636
movl 0xfdec9(%rip), %edi     # 0x2144c0
subl $0x2, %edi
callq 0x118790
movl %eax, %edi
movl $0x4, %esi
callq 0x5ce90
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $0x2, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x67c(%rbp)
je 0x116631
movl -0x34(%rbp), %ecx
addl $0x2, %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x1166e8
movl 0xfde84(%rip), %eax     # 0x2144c0
subl $0x1, %eax
movl %eax, -0x694(%rbp)
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
movl %eax, %ecx
movl -0x694(%rbp), %eax
subl %ecx, %eax
cmpl $0x52, %eax
jge 0x1166a9
movl 0xfde53(%rip), %edi     # 0x2144c0
subl $0x12, %edi
callq 0x118790
movl %eax, %edi
movl $0x6, %esi
callq 0x5ce90
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $0x3, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x67c(%rbp)
je 0x1166a7
movl -0x34(%rbp), %ecx
addl $0x3, %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x1166e6
movl 0xfde11(%rip), %edi     # 0x2144c0
subl $0x53, %edi
callq 0x118790
addl $0x3, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x67c(%rbp)
je 0x1166e4
movl 0xfddf1(%rip), %edi     # 0x2144c0
subl $0x53, %edi
callq 0x118790
movl %eax, %ecx
addl $0x3, %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x1166e6
jmp 0x1166e8
jmp 0x1166ea
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x116910
movl %eax, -0x680(%rbp)
cmpl $0x0, -0x680(%rbp)
jl 0x116717
movl -0x680(%rbp), %edi
callq 0x1187f0
jmp 0x116719
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x670(%rbp), %eax
jne 0x1167c2
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x66c(%rbp), %edx
movl $0x8, %ecx
callq 0x116140
movl %eax, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
jl 0x1167b4
cmpl $0x9, -0x28(%rbp)
jle 0x116764
movl -0x40(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x40(%rbp)
jmp 0x11676d
movl -0x40(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x40(%rbp)
movl -0x66c(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x66c(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x66c(%rbp), %eax
addl $0x1, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0x38(%rbp)
movl -0x66c(%rbp), %eax
addl $0x1, %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x3c(%rbp)
jmp 0x1167bd
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x116881
movq -0x10(%rbp), %rax
movslq -0x66c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movslq -0x66c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x11687f
testb $0x1, -0x21(%rbp)
jne 0x11687f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x66c(%rbp), %ecx
movl $0x8, %r8d
callq 0x118870
movl %eax, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
jl 0x116874
cmpl $0x9, -0x28(%rbp)
jle 0x116824
movl -0x40(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x40(%rbp)
jmp 0x11682d
movl -0x40(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x40(%rbp)
movl -0x66c(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x66c(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x66c(%rbp), %eax
addl $0x1, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0x38(%rbp)
movl -0x66c(%rbp), %eax
addl $0x1, %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x3c(%rbp)
jmp 0x11687d
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x11687f
jmp 0x116881
jmp 0x116883
movl -0x66c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x66c(%rbp)
jmp 0x11632d
movl -0x664(%rbp), %eax
movl %eax, 0xfdc1d(%rip)     # 0x2144c0
movl $0x0, -0x684(%rbp)
cmpl $0x184, -0x684(%rbp)    # imm = 0x184
jge 0x1168e9
movslq -0x684(%rbp), %rax
movl -0x660(%rbp,%rax,4), %edx
movslq -0x684(%rbp), %rcx
leaq 0xfd5db(%rip), %rax     # 0x213eb0
movl %edx, (%rax,%rcx,4)
movl -0x684(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x684(%rbp)
jmp 0x1168ad
movl -0x40(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %ecx
addl -0x44(%rbp), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
xorl %eax, %eax
addq $0x6a0, %rsp            # imm = 0x6A0
popq %rbp
retq
nopl (%rax)