// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/misc/codecs.cpp
// Function: DecompressDelta(int*, int*, int, int, smooth::IO::InStream*)
int DecompressDelta(int line[], int prevline[], int x, int parts, PCIIn in)
{
	int	 pixb1 = (x > 0 ? line[x - 1] : 0);

	int	 md;
	int	 bias;
	int	 redbias;
	int	 greenbias;
	int	 bluebias;
	int	 alphabias;
	int	 gray;
	int	 red;
	int	 green;
	int	 blue;
	int	 alpha;

	switch (parts)
	{
		case 1:
			gray = (pixb1 + prevline[x]) / 2;

			if (in->InputBits(1) == 1) bias =     in->InputBits(3) + 1;
			else			   bias = 0 - in->InputBits(3);

			return gray + bias;
		case 3:
			red   = (Color(pixb1).GetRed()	 + Color(prevline[x]).GetRed())	  / 2;
			green = (Color(pixb1).GetGreen() + Color(prevline[x]).GetGreen()) / 2;
			blue  = (Color(pixb1).GetBlue()	 + Color(prevline[x]).GetBlue())  / 2;

			md = in->InputBits(2) + 2;

			if (in->InputBits(1) == 1) redbias   =	   in->InputBits(md) + 1;
			else			   redbias   = 0 - in->InputBits(md);

			if (in->InputBits(1) == 1) greenbias =	   in->InputBits(md) + 1;
			else			   greenbias = 0 - in->InputBits(md);

			if (in->InputBits(1) == 1) bluebias  =	   in->InputBits(md) + 1;
			else			   bluebias  = 0 - in->InputBits(md);

			return Color(red + redbias, green + greenbias, blue + bluebias);
		case 4:
			red   = (Color(pixb1).GetRed()	 + Color(prevline[x]).GetRed())	  / 2;
			green = (Color(pixb1).GetGreen() + Color(prevline[x]).GetGreen()) / 2;
			blue  = (Color(pixb1).GetBlue()	 + Color(prevline[x]).GetBlue())  / 2;
			alpha = (Color(pixb1).GetAlpha() + Color(prevline[x]).GetAlpha()) / 2;

			md = in->InputBits(2) + 2;

			if (in->InputBits(1) == 1) redbias   =	   in->InputBits(md) + 1;
			else			   redbias   = 0 - in->InputBits(md);

			if (in->InputBits(1) == 1) greenbias =	   in->InputBits(md) + 1;
			else			   greenbias = 0 - in->InputBits(md);

			if (in->InputBits(1) == 1) bluebias  =	   in->InputBits(md) + 1;
			else			   bluebias  = 0 - in->InputBits(md);

			if (in->InputBits(1) == 1) alphabias =	   in->InputBits(md) + 1;
			else			   alphabias = 0 - in->InputBits(md);

			return Color( (red   + redbias	)	 |
				     ((green + greenbias) <<  8) |
				     ((blue  + bluebias	) << 16) |
				     ((alpha + alphabias) << 24));
	}

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
testl %edx, %edx
jle 0xba146
movl %edx, %eax
movl -0x4(%rdi,%rax,4), %eax
jmp 0xba148
xorl %eax, %eax
cmpl $0x4, %ecx
je 0xba2a6
cmpl $0x3, %ecx
je 0xba1a9
movl $0x1, %r14d
cmpl $0x1, %ecx
jne 0xba3e5
movslq %edx, %rcx
addl (%rsi,%rcx,4), %eax
movl %eax, %ebp
shrl $0x1f, %ebp
addl %eax, %ebp
sarl %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, %r15
movq %rbx, %rdi
movl $0x3, %esi
callq 0x572d0
movq %rax, %r14
incl %eax
negl %r14d
cmpq $0x1, %r15
cmovel %eax, %r14d
addl %ebp, %r14d
jmp 0xba3e5
movslq %edx, %rcx
movl (%rsi,%rcx,4), %r13d
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
movl %r13d, %ebp
andl %ecx, %ebp
addl %edx, %ebp
shrl %ebp
movl %eax, %edx
shrl $0x8, %edx
movl %r13d, %r12d
shrl $0x8, %r12d
andl %ecx, %edx
andl %ecx, %r12d
addl %edx, %r12d
shrl %r12d
shrl $0x10, %eax
shrl $0x10, %r13d
andl %ecx, %eax
andl %ecx, %r13d
addl %eax, %r13d
shrl %r13d
movq %rbx, %rdi
movl $0x2, %esi
callq 0x572d0
leal 0x2(%rax), %r14d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl %r14d, 0x14(%rsp)
callq 0x572d0
movq %rax, %r15
incl %eax
negl %r15d
cmpq $0x1, 0x8(%rsp)
cmovel %eax, %r15d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x572d0
movq %rax, %r14
incl %eax
negl %r14d
cmpq $0x1, 0x8(%rsp)
cmovel %eax, %r14d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl 0x14(%rsp), %esi
callq 0x572d0
leal 0x1(%rax), %ecx
negl %eax
cmpq $0x1, 0x8(%rsp)
cmovel %ecx, %eax
addl %ebp, %r15d
addl %r12d, %r14d
addl %r13d, %eax
shll $0x10, %eax
shll $0x8, %r14d
orl %r15d, %r14d
orl %eax, %r14d
jmp 0xba3e5
movslq %edx, %rcx
movl (%rsi,%rcx,4), %esi
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
movl %esi, %edi
andl %ecx, %edi
addl %edx, %edi
shrl %edi
movl %edi, 0x14(%rsp)
movl %eax, %edx
shrl $0x8, %edx
movl %esi, %edi
shrl $0x8, %edi
andl %ecx, %edx
andl %ecx, %edi
addl %edx, %edi
shrl %edi
movl %edi, 0x8(%rsp)
movl %eax, %edx
shrl $0x10, %edx
movl %esi, %ebp
shrl $0x10, %ebp
andl %ecx, %edx
andl %ecx, %ebp
addl %edx, %ebp
shrl %ebp
shrl $0x18, %eax
shrl $0x18, %esi
addl %eax, %esi
shrl %esi
movl %esi, 0x1c(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
callq 0x572d0
leal 0x2(%rax), %r13d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, %r14
movq %rbx, %rdi
movl %r13d, %esi
callq 0x572d0
movq %rax, %r15
incl %eax
negl %r15d
cmpq $0x1, %r14
cmovel %eax, %r15d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, %r14
movq %rbx, %rdi
movl %r13d, %esi
movl %r13d, 0x18(%rsp)
callq 0x572d0
movq %rax, %r12
incl %eax
negl %r12d
cmpq $0x1, %r14
cmovel %eax, %r12d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, %r14
movq %rbx, %rdi
movl %r13d, %esi
callq 0x572d0
movq %rax, %r13
incl %eax
negl %r13d
cmpq $0x1, %r14
cmovel %eax, %r13d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x572d0
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
movl 0x18(%rsp), %esi
callq 0x572d0
movq %rax, %r14
incl %eax
negl %r14d
cmpq $0x1, 0x20(%rsp)
cmovel %eax, %r14d
addl 0x14(%rsp), %r15d
addl 0x8(%rsp), %r12d
shll $0x8, %r12d
orl %r15d, %r12d
addl %ebp, %r13d
shll $0x10, %r13d
addl 0x1c(%rsp), %r14d
shll $0x18, %r14d
orl %r13d, %r14d
orl %r12d, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq