// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/palmbitmap.c
// Function: do_decompress_scanline_compression
static void do_decompress_scanline_compression(deark *c, lctx *d, struct page_ctx *pg,
	struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
	struct de_dfilter_results *dres)
{
	i64 srcpos = dcmpri->pos;
	i64 j;
	i64 blocknum;
	i64 blocksperrow;
	i64 nbytes_written = 0;
	u8 bf;
	u8 dstb;
	unsigned int k;

	blocksperrow = (pg->rowbytes+7)/8;

	for(j=0; j<pg->h; j++) {
		i64 bytes_written_this_row = 0;

		if(nbytes_written >= dcmpro->expected_len) goto done;

		for(blocknum=0; blocknum<blocksperrow; blocknum++) {
			// For each byte-per-row, we expect a lead byte, which is a
			// bitfield that tells us which of the next 8 bytes are stored
			// in the file, versus being copied from the previous row.
			bf = dbuf_getbyte(dcmpri->f, srcpos++);
			for(k=0; k<8; k++) {
				if(bytes_written_this_row>=pg->rowbytes) break;

				if(bf&(1<<(7-k))) {
					// byte is present
					dstb = dbuf_getbyte(dcmpri->f, srcpos++);
				}
				else {
					// copy from previous row
					dstb = dbuf_getbyte(dcmpro->f, dcmpro->f->len - pg->rowbytes);
				}
				dbuf_writebyte(dcmpro->f, dstb);

				bytes_written_this_row++;
				nbytes_written++;
			}
		}
	}
done:
	dres->bytes_consumed = srcpos - dcmpri->pos;
	dres->bytes_consumed_valid = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0xfe305
movq $0x0, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jl 0xfe1f3
jmp 0xfe307
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0xfe2f2
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movb %al, -0x59(%rbp)
movl $0x0, -0x60(%rbp)
cmpl $0x8, -0x60(%rbp)
jae 0xfe2df
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0xfe24b
jmp 0xfe2df
movzbl -0x59(%rbp), %eax
movl $0x7, %ecx
subl -0x60(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xfe287
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movb %al, -0x5a(%rbp)
jmp 0xfe2a9
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
subq 0x18(%rax), %rsi
callq 0x165060
movb %al, -0x5a(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movzbl -0x5a(%rbp), %esi
callq 0x168380
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xfe22e
jmp 0xfe2e1
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xfe1fb
jmp 0xfe2f4
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xfe1c6
jmp 0xfe307
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
subq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movb $0x1, 0x4(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)