// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/misc/codecs.cpp
// Function: PCIIO::ReadLine(smooth::IO::InStream*, int)
bool PCIIO::ReadLine(PCIIn in, int y)
{
	/* Check compression type.
	 */
	if (compression != PCI	 &&
	    compression != RLE	 &&
	    compression != BZIP2 &&
	    compression != UNCOMPRESSED) return false;

	/* Read image line.
	 */
	int	*line = new int [sizex];
	int	 ctsize;
	int	 maxpalentries;

	switch (colorspace)
	{
		case Color::RGB:
		case Color::YUV:
		case Color::HSV:
		case Color::CMY:
			ctsize = 3;
			maxpalentries = 338;

			break;
		case Color::CMYK:
			ctsize = 4;
			maxpalentries = 338;

			break;
		case Color::GRAY:
			ctsize = 1;
			maxpalentries = 338;

			break;
		default:
			ctsize = 3;
			maxpalentries = 338;

			break;
	}

	switch (compression)
	{
		case BZIP2:
		case UNCOMPRESSED:
			for (int x = 0; x < sizex; x++)
			{
				line[x] = in->InputBits(ctsize * bpcc);
			}

			break;
		case RLE:
			for (int x = 0; x < sizex; x++)
			{
				int	 col = in->InputBits(ctsize * bpcc);
				int	 rle = in->InputBits(rlebits);

				for (int i = x; i <= x + rle; i++) line[i] = col;

				x += rle;
			}

			break;
		case PCI:
			if (in->InputBits(1) == 1)
			{
				DecompressSLAL(line, previousLine, sizex);
			}
			else
			{
				int	 allinpal = 0;
				int	 gallinpal = 0;
				int	 mod04 = 0;
				int	 mod16 = 0;

				int	 dosaa = in->InputBits(1);
				int	 dorle = in->InputBits(1);

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

					if ( (x % 16) == mod16		     ) gallinpal = in->InputBits(1);
					if (((x %  4) == mod04) && !gallinpal) allinpal	 = in->InputBits(1);

					int	 col = 0;
					int	 inpal = 1;

					if (!allinpal && !gallinpal) inpal = in->InputBits(1);

					if (inpal == 0)
					{
						if (in->InputBits(1)) col = DecompressDelta(line, previousLine, x, ctsize, in);
						else		      col = in->InputBits(ctsize * bpcc);

						if (palentries < maxpalentries)
						{
							palette[palentries] = col;
							palentries++;
						}
						else
						{
							RotatePalette(col);
						}
					}
					else
					{
						int	 saa = 0;

						if (dosaa) saa = in->InputBits(1);

						if (saa)
						{
							col = previousLine[x];
						}
						else
						{
							if (in->InputBits(1) == 1)
							{
								col = palette[(palentries - 1) - in->InputBits(1)];
							}
							else
							{
								if (in->InputBits(1) == 1)
								{
									int	 lbits = Math::Min(GetMinimumBits(palentries - 2), 4);

									col = palette[(palentries - 1) - in->InputBits(lbits) - 2];
								}
								else
								{
									if (in->InputBits(1) == 1)
									{
										int	 lbits = Math::Min(GetMinimumBits(palentries - 18), 6);

										col = palette[(palentries - 1) - in->InputBits(lbits) - 18];
									}
									else
									{
										col = palette[(palentries - 1) - in->InputBits(GetMinimumBits(palentries - 83)) - 82];
									}
								}
							}
						}

						int	 paletteEntry = GetPaletteEntry(col);

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

					line[x] = col;

					if (col == previousColor)
					{
						if (in->InputBits(1) == 1)
						{
							int	 pcirle;

							if (in->InputBits(1) == 1) pcirle = in->InputBits(8) + 2;
							else			   pcirle = in->InputBits(3) + 2;

							for (int i = x + 1; i <= x + pcirle; i++) line[i] = line[x];

							x = x + pcirle;

							allinpal = 0;
							gallinpal = 0;

							mod04 = (x + 1) %  4;
							mod16 = (x + 1) % 16;
						}
					}
					else if ((col == previousLine[x]) && dorle)
					{
						if (in->InputBits(1) == 1)
						{
							int	 pcirle;

							if (in->InputBits(1) == 1) pcirle = in->InputBits(8) + 2;
							else			   pcirle = in->InputBits(3) + 2;

							for (int i = x + 1; i <= x + pcirle; i++) line[i] = previousLine[i];

							x = x + pcirle;

							allinpal = 0;
							gallinpal = 0;

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

			for (int x = 0; x < sizex; x++) previousLine[x] = line[x];

			break;
	}

	for (int x = 0; x < sizex; x++) bmp.SetPixel(Point(x, y), Color(line[x], colorspace).Upsample(bpcc).ConvertTo(Color::RGB));

	delete [] line;

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
cmpl $0x1, 0x50(%rax)
je 0x115897
movq -0xd8(%rbp), %rax
cmpl $0x3, 0x50(%rax)
je 0x115897
movq -0xd8(%rbp), %rax
cmpl $0x4, 0x50(%rax)
je 0x115897
movq -0xd8(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x115897
movb $0x0, -0x1(%rbp)
jmp 0x11612b
movq -0xd8(%rbp), %rax
movslq 0x10(%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x5ab20
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x28(%rbp)
movl 0x58(%rax), %eax
movq %rax, -0xe0(%rbp)
subq $0x6, %rax
ja 0x115922
movq -0xe0(%rbp), %rax
leaq 0x90d6f(%rip), %rcx     # 0x1a6658
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x3, -0x2c(%rbp)
movl $0x152, -0x30(%rbp)     # imm = 0x152
jmp 0x115930
movl $0x4, -0x2c(%rbp)
movl $0x152, -0x30(%rbp)     # imm = 0x152
jmp 0x115930
movl $0x1, -0x2c(%rbp)
movl $0x152, -0x30(%rbp)     # imm = 0x152
jmp 0x115930
movl $0x3, -0x2c(%rbp)
movl $0x152, -0x30(%rbp)     # imm = 0x152
movq -0xd8(%rbp), %rax
movl 0x50(%rax), %eax
movq %rax, -0xe8(%rbp)
subq $0x4, %rax
ja 0x11603e
movq -0xe8(%rbp), %rax
leaq 0x90d1b(%rip), %rcx     # 0x1a6674
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x34(%rbp)
movq -0xd8(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x1159a7
movq -0xd8(%rbp), %rax
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
imull 0x54(%rax), %esi
callq 0x5b960
movl %eax, %edx
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x115969
jmp 0x11603e
movl $0x0, -0x38(%rbp)
movq -0xd8(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x115a38
movq -0xd8(%rbp), %rax
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
imull 0x54(%rax), %esi
callq 0x5b960
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movl %ecx, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
movl 0x60(%rax), %esi
callq 0x5b960
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl -0x38(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jg 0x115a21
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1159fb
movl -0x40(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1159b3
jmp 0x11603e
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115a70
movq -0xd8(%rbp), %rax
movq -0x28(%rbp), %rdi
movq 0xfe43d(%rip), %rsi     # 0x213ea0
movl 0x10(%rax), %edx
callq 0x118940
jmp 0x115ff0
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movl %eax, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0xd8(%rbp), %rcx
movl -0x60(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x115fee
cmpl $0x0, -0x60(%rbp)
jle 0x115ae6
movq -0x28(%rbp), %rax
movl -0x60(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xec(%rbp)
jmp 0x115af0
xorl %eax, %eax
movl %eax, -0xec(%rbp)
jmp 0x115af0
movl -0xec(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x60(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl -0x54(%rbp), %edx
jne 0x115b1a
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movl %eax, -0x4c(%rbp)
movl -0x60(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl -0x50(%rbp), %edx
jne 0x115b41
cmpl $0x0, -0x4c(%rbp)
jne 0x115b41
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movl %eax, -0x48(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x1, -0x6c(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x115b6c
cmpl $0x0, -0x4c(%rbp)
jne 0x115b6c
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0x115c00
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x0, %rax
je 0x115ba9
movq -0x28(%rbp), %rdi
movq 0xfe30b(%rip), %rsi     # 0x213ea0
movl -0x60(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %r8
callq 0x118990
movl %eax, -0x68(%rbp)
jmp 0x115bc3
movq -0xd8(%rbp), %rax
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
imull 0x54(%rax), %esi
callq 0x5b960
movl %eax, -0x68(%rbp)
movl 0xfe8f7(%rip), %eax     # 0x2144c0
cmpl -0x30(%rbp), %eax
jge 0x115bf3
movl -0x68(%rbp), %edx
movslq 0xfe8e8(%rip), %rcx     # 0x2144c0
leaq 0xfe2d1(%rip), %rax     # 0x213eb0
movl %edx, (%rax,%rcx,4)
movl 0xfe8d8(%rip), %eax     # 0x2144c0
addl $0x1, %eax
movl %eax, 0xfe8cf(%rip)     # 0x2144c0
jmp 0x115bfb
movl -0x68(%rbp), %edi
callq 0x1186e0
jmp 0x115dda
movl $0x0, -0x70(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x115c1e
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x115c3a
movq 0xfe275(%rip), %rax     # 0x213ea0
movslq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
jmp 0x115dbf
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115c8a
movl 0xfe86c(%rip), %eax     # 0x2144c0
subl $0x1, %eax
cltq
movq %rax, -0xf8(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
movq -0xf8(%rbp), %rcx
subq %rax, %rcx
leaq 0xfe231(%rip), %rax     # 0x213eb0
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
jmp 0x115dbd
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115cf9
movl 0xfe81c(%rip), %edi     # 0x2144c0
subl $0x2, %edi
callq 0x118790
movl %eax, %edi
movl $0x4, %esi
callq 0x5ce90
movl %eax, -0x74(%rbp)
movl 0xfe7ff(%rip), %eax     # 0x2144c0
subl $0x1, %eax
cltq
movq %rax, -0x100(%rbp)
movq -0x18(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x5b960
movq -0x100(%rbp), %rcx
subq %rax, %rcx
subq $0x2, %rcx
leaq 0xfe1c2(%rip), %rax     # 0x213eb0
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
jmp 0x115dbb
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115d65
movl 0xfe7ad(%rip), %edi     # 0x2144c0
subl $0x12, %edi
callq 0x118790
movl %eax, %edi
movl $0x6, %esi
callq 0x5ce90
movl %eax, -0x78(%rbp)
movl 0xfe790(%rip), %eax     # 0x2144c0
subl $0x1, %eax
cltq
movq %rax, -0x108(%rbp)
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x5b960
movq -0x108(%rbp), %rcx
subq %rax, %rcx
subq $0x12, %rcx
leaq 0xfe153(%rip), %rax     # 0x213eb0
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
jmp 0x115db9
movl 0xfe755(%rip), %eax     # 0x2144c0
subl $0x1, %eax
cltq
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x118(%rbp)
movl 0xfe738(%rip), %edi     # 0x2144c0
subl $0x53, %edi
callq 0x118790
movq -0x118(%rbp), %rdi
movl %eax, %esi
callq 0x5b960
movq -0x110(%rbp), %rcx
subq %rax, %rcx
subq $0x52, %rcx
leaq 0xfe0fd(%rip), %rax     # 0x213eb0
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
jmp 0x115dbb
jmp 0x115dbd
jmp 0x115dbf
movl -0x68(%rbp), %edi
callq 0x116910
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
jl 0x115dd8
movl -0x7c(%rbp), %edi
callq 0x1187f0
jmp 0x115dda
movl -0x68(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x60(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jne 0x115ed0
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115ecb
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115e37
movq -0x18(%rbp), %rdi
movl $0x8, %esi
callq 0x5b960
addq $0x2, %rax
movl %eax, -0x80(%rbp)
jmp 0x115e4c
movq -0x18(%rbp), %rdi
movl $0x3, %esi
callq 0x5b960
addq $0x2, %rax
movl %eax, -0x80(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl -0x60(%rbp), %ecx
addl -0x80(%rbp), %ecx
cmpl %ecx, %eax
jg 0x115e92
movq -0x28(%rbp), %rax
movslq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movslq -0x84(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x115e58
movl -0x60(%rbp), %eax
addl -0x80(%rbp), %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0x50(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x54(%rbp)
jmp 0x115fde
movl -0x68(%rbp), %eax
movq 0xfdfc6(%rip), %rcx     # 0x213ea0
movslq -0x60(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x115fdc
cmpl $0x0, -0x5c(%rbp)
je 0x115fdc
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115fda
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x5b960
cmpq $0x1, %rax
jne 0x115f37
movq -0x18(%rbp), %rdi
movl $0x8, %esi
callq 0x5b960
addq $0x2, %rax
movl %eax, -0x88(%rbp)
jmp 0x115f4f
movq -0x18(%rbp), %rdi
movl $0x3, %esi
callq 0x5b960
addq $0x2, %rax
movl %eax, -0x88(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl -0x60(%rbp), %ecx
addl -0x88(%rbp), %ecx
cmpl %ecx, %eax
jg 0x115f9e
movq 0xfdf2b(%rip), %rax     # 0x213ea0
movslq -0x8c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x115f5b
movl -0x60(%rbp), %eax
addl -0x88(%rbp), %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0x50(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x54(%rbp)
jmp 0x115fdc
jmp 0x115fde
jmp 0x115fe0
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x115ab5
jmp 0x115ff0
movl $0x0, -0x90(%rbp)
movq -0xd8(%rbp), %rcx
movl -0x90(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x11603c
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0xfde7f(%rip), %rax     # 0x213ea0
movslq -0x90(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x115ffa
jmp 0x11603e
movl $0x0, -0x94(%rbp)
movq -0xd8(%rbp), %rcx
movl -0x94(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x11610a
movq -0xd8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x120(%rbp)
movl -0x94(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq -0x9c(%rbp), %rdi
callq 0x5c2c0
movq -0xd8(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x94(%rbp), %rdx
movslq (%rcx,%rdx,4), %rsi
movl 0x58(%rax), %edx
leaq -0xd0(%rbp), %rdi
callq 0x59be0
movq -0xd8(%rbp), %rax
movl 0x54(%rax), %edx
leaq -0xc0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5bfe0
leaq -0xb0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %edx, %edx
callq 0x5c5e0
movq -0x120(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x5a3d0
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x116048
movq -0x28(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpq $0x0, %rax
je 0x116127
movq -0x128(%rbp), %rdi
callq 0x5a5e0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax)