// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/spectrum512.c
// Function: spc_decompress_pixels
static void spc_decompress_pixels(deark *c, struct de_dfilter_in_params *dcmpri,
	struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres)
{
	i64 pos;
	u8 b, b2;
	i64 count;
	i64 endpos;
	i64 nbytes_written = 0;

	pos = dcmpri->pos;
	endpos = dcmpri->pos + dcmpri->len;

	while(1) {
		if(dcmpro->len_known && nbytes_written >= dcmpro->expected_len) {
			break; // Decompressed the requested amount of dst data.
		}

		if(pos+2 > endpos) { // Min item size is 2 bytes
			break; // Reached the end of source data
		}
		b = dbuf_getbyte(dcmpri->f, pos++);

		if(b>=128) { // A compressed run
			count = 258 - (i64)b;
			b2 = dbuf_getbyte(dcmpri->f, pos++);
			dbuf_write_run(dcmpro->f, b2, count);
			nbytes_written += count;
		}
		else { // An uncompressed run
			count = 1 + (i64)b;
			if(pos+count > endpos) {
				pos--;
				break;
			}
			dbuf_copy(dcmpri->f, pos, count, dcmpro->f);
			pos += count;
			nbytes_written += count;
		}
	}

	dbuf_flush(dcmpro->f);
	dres->bytes_consumed = pos - dcmpri->pos;
	dres->bytes_consumed_valid = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x127550
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jl 0x127550
jmp 0x127640
movq -0x28(%rbp), %rax
addq $0x2, %rax
cmpq -0x40(%rbp), %rax
jle 0x127563
jmp 0x127640
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0x80, %eax
jl 0x1275e0
movzbl -0x29(%rbp), %eax
movl %eax, %ecx
movl $0x102, %eax            # imm = 0x102
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movb %al, -0x2a(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movb -0x2a(%rbp), %al
movq -0x38(%rbp), %rdx
movzbl %al, %esi
callq 0x168800
movq -0x38(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x12763b
movzbl -0x29(%rbp), %eax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x127608
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x127640
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
callq 0x166070
movq -0x38(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x127530
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x167c30
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
subq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x4(%rax)
addq $0x50, %rsp
popq %rbp
retq
nop