// File: /workspace/github_c_makefile_star2_O2/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 0xb3638
movl %edx, %eax
movl -0x4(%rdi,%rax,4), %eax
jmp 0xb363a
xorl %eax, %eax
cmpl $0x4, %ecx
je 0xb3782
cmpl $0x3, %ecx
je 0xb3690
cmpl $0x1, %ecx
jne 0xb38bb
movslq %edx, %rcx
addl (%rsi,%rcx,4), %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %ebp
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x584c0
movq %rax, %r15
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x584c0
movq %rax, %r14
incl %eax
negl %r14d
cmpq $0x1, %r15
cmovel %eax, %r14d
addl %ebp, %r14d
jmp 0xb38bf
movslq %edx, %rcx
movl (%rsi,%rcx,4), %ebp
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
movl %ebp, %r12d
andl %ecx, %r12d
addl %edx, %r12d
shrl %r12d
movl %eax, %edx
shrl $0x8, %edx
movl %ebp, %r13d
shrl $0x8, %r13d
andl %ecx, %edx
andl %ecx, %r13d
addl %edx, %r13d
shrl %r13d
shrl $0x10, %eax
shrl $0x10, %ebp
andl %ecx, %eax
andl %ecx, %ebp
addl %eax, %ebp
shrl %ebp
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x584c0
leal 0x2(%rax), %r14d
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x584c0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl %r14d, 0x14(%rsp)
callq 0x584c0
movq %rax, %r15
incl %eax
negl %r15d
cmpq $0x1, 0x8(%rsp)
cmovel %eax, %r15d
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x584c0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x584c0
movq %rax, %r14
incl %eax
negl %r14d
cmpq $0x1, 0x8(%rsp)
cmovel %eax, %r14d
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x584c0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl 0x14(%rsp), %esi
callq 0x584c0
leal 0x1(%rax), %ecx
negl %eax
cmpq $0x1, 0x8(%rsp)
cmovel %ecx, %eax
addl %r12d, %r15d
addl %r13d, %r14d
addl %ebp, %eax
shll $0x10, %eax
shll $0x8, %r14d
orl %r15d, %r14d
orl %eax, %r14d
jmp 0xb38bf
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, 0x24(%rsp)
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x584c0
leal 0x2(%rax), %r14d
pushq $0x1
popq %r13
movq %rbx, %rdi
movl %r13d, %esi
callq 0x584c0
movq %rax, %r12
movq %rbx, %rdi
movl %r14d, %esi
callq 0x584c0
movq %rax, %r15
incl %eax
negl %r15d
cmpq $0x1, %r12
cmovel %eax, %r15d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x584c0
movq %rax, %r13
movq %rbx, %rdi
movl %r14d, %esi
callq 0x584c0
movq %rax, %r12
incl %eax
negl %r12d
cmpq $0x1, %r13
cmovel %eax, %r12d
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x584c0
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x584c0
movq %rax, %r13
incl %eax
negl %r13d
cmpq $0x1, 0x18(%rsp)
cmovel %eax, %r13d
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x584c0
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x584c0
movq %rax, %r14
incl %eax
negl %r14d
cmpq $0x1, 0x18(%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 0x24(%rsp), %r14d
shll $0x18, %r14d
orl %r13d, %r14d
orl %r12d, %r14d
jmp 0xb38bf
pushq $0x1
popq %r14
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq