// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/msp.c
// Function: do_decompress_scanline
static void do_decompress_scanline(deark *c, lctx *d, de_bitmap *img,
	i64 rownum, i64 rowoffset, i64 bytes_in_row)
{
	i64 i;
	u8 runtype;
	i64 runcount;
	u8 value;

	de_dbg2(c, "decompressing row %d", (int)rownum);

	if(!d->rowbuf) {
		d->rowbuf = dbuf_create_membuf(c, (d->width+7)/8, 1);
	}

	dbuf_empty(d->rowbuf);

	// Read the compressed data byte by byte
	i = 0;
	while(i<bytes_in_row) {
		runtype = de_getbyte(rowoffset+i);
		i++;
		if(runtype==0x00) {
			runcount = (i64)de_getbyte(rowoffset+i);
			i++;
			value = de_getbyte(rowoffset+i);
			i++;
			// write value runcount times
			de_dbg2(c, "compressed, %d bytes of %d", (int)runcount, value);
			dbuf_write_run(d->rowbuf, value, runcount);
		}
		else {
			runcount = (i64)runtype;
			de_dbg2(c, "%d bytes uncompressed", (int)runcount);
			dbuf_copy(c->infile, rowoffset+i, runcount, d->rowbuf);
			i+=runcount;
		}
	}

	de_convert_row_bilevel(d->rowbuf, 0, img, rownum, 0);
}

// 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 %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xd7f4e(%rip), %rsi     # 0x1bcfff
movb $0x0, %al
callq 0x15b350
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xe50f5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x169310
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0xe521c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq -0x38(%rbp), %rsi
callq 0x165060
movb %al, -0x39(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0xe51ca
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq -0x38(%rbp), %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq -0x38(%rbp), %rsi
callq 0x165060
movb %al, -0x49(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movzbl -0x49(%rbp), %ecx
leaq 0xd7e6a(%rip), %rsi     # 0x1bd014
movb $0x0, %al
callq 0x15b350
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movb -0x49(%rbp), %al
movq -0x48(%rbp), %rdx
movzbl %al, %esi
callq 0x168800
jmp 0xe5217
movzbl -0x39(%rbp), %eax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0xd7e4c(%rip), %rsi     # 0x1bd02f
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0x166070
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xe510a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x16be90
addq $0x50, %rsp
popq %rbp
retq
nop