// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cdiimage.c
// Function: cdi_imag_decompress_rl7
static int cdi_imag_decompress_rl7(deark *c, struct cdi_imag_ctx *d, struct de_iffctx *ictx,
	dbuf *unc_pixels)
{
	i64 pos, endpos;
	i64 xpos = 0;
	i64 ypos = 0;
	int need_errmsg = 0;

	pos = ictx->chunkctx->dpos;
	endpos = pos + ictx->chunkctx->dlen;

	while(1) {
		u8 x;
		u8 palent;
		u8 eoln_flag = 0;
		i64 count;

		if(ypos >= d->h) break;

		if(pos >= endpos) {
			need_errmsg = 1;
			goto done;
		}

		x = dbuf_getbyte_p(ictx->f, &pos);
		palent = x & 0x7f;
		if(x & 0x80) { // run
			u8 r;

			r = dbuf_getbyte_p(ictx->f, &pos);
			if(r>=2) {
				count = (i64)r;
			}
			else if(r==0) {
				eoln_flag = 1;
				count = d->npwidth - xpos;
			}
			else {
				de_err(c, "Unsupported compression feature");
				goto done;
			}
		}
		else { // single pixel
			count = 1;
		}

		if(xpos+count > d->npwidth) {
			need_errmsg = 1;
			count = d->npwidth - xpos;
		}
		dbuf_write_run(unc_pixels, palent, count);
		xpos += count;

		if(eoln_flag) {
			ypos++;
			xpos = 0;
		}
	}

done:
	dbuf_flush(unc_pixels);
	if(need_errmsg) {
		de_err(c, "Image decompression failed");
	}
	return (unc_pixels->len>0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x128(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x128(%rcx), %rcx
addq 0x48(%rcx), %rax
movq %rax, -0x30(%rbp)
movb $0x0, -0x47(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jl 0x88aa0
jmp 0x88bac
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jl 0x88ab6
movl $0x1, -0x44(%rbp)
jmp 0x88bae
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x45(%rbp)
movzbl -0x45(%rbp), %eax
andl $0x7f, %eax
movb %al, -0x46(%rbp)
movzbl -0x45(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x88b3f
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x51(%rbp)
movzbl -0x51(%rbp), %eax
cmpl $0x2, %eax
jl 0x88b09
movzbl -0x51(%rbp), %eax
movq %rax, -0x50(%rbp)
jmp 0x88b3d
movzbl -0x51(%rbp), %eax
cmpl $0x0, %eax
jne 0x88b27
movb $0x1, -0x47(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x88b3b
movq -0x8(%rbp), %rdi
leaq 0x1260cb(%rip), %rsi    # 0x1aebfd
movb $0x0, %al
callq 0x15bfb0
jmp 0x88bae
jmp 0x88b3d
jmp 0x88b47
movq $0x1, -0x50(%rbp)
movq -0x38(%rbp), %rax
addq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x88b6e
movl $0x1, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movb -0x46(%rbp), %al
movq -0x50(%rbp), %rdx
movzbl %al, %esi
callq 0x168800
movq -0x50(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpb $0x0, -0x47(%rbp)
je 0x88ba7
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x88a89
jmp 0x88bae
movq -0x20(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0x44(%rbp)
je 0x88bcf
movq -0x8(%rbp), %rdi
leaq 0x126055(%rip), %rsi    # 0x1aec1d
movb $0x0, %al
callq 0x15bfb0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
setg %al
andb $0x1, %al
movzbl %al, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)