// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ilbm.c
// Function: decompress_deep_5
static int decompress_deep_5(deark *c, struct deep_ctx *d, dbuf *inf,
	i64 pos1, i64 len, dbuf *unc_pixels)
{
	i64 xpos = 0;
	i64 ypos = 0;
	i64 output_pos = 0;
	i64 curr_component = 0;
	u8 v = 0;
	int retval = 0;
	struct de_bitreader bitrd;

	de_zeromem(&bitrd, sizeof(struct de_bitreader));
	bitrd.f = inf;
	bitrd.curpos = pos1;
	bitrd.endpos = pos1+len;
	bitrd.bbll.is_lsb = 0;
	dbuf_disable_wbuffer(unc_pixels);

	if(!d->found_TVDC) {
		de_err(c, "Missing TVDC chunk");
		goto done;
	}
	retval = 1;

	while(1) {
		UI n;
		UI k;
		UI count;

		n = (UI)de_bitreader_getbits(&bitrd, 4);
		if(bitrd.eof_flag) goto done;

		if(d->tvdc_data[n*2+1]!=0 || d->tvdc_data[n*2]!=0) {
			v += (u8)(d->tvdc_data[n*2+1]);
			count = 1;
		}
		else {
			n = (UI)de_bitreader_getbits(&bitrd, 4);
			count = n+1;
		}

		for(k=0; k<count; k++) {
			dbuf_writebyte_at(unc_pixels, output_pos, v);
			output_pos += d->num_components;
			xpos++;
			if(xpos >= d->width) break;
		}

		if(xpos >= d->width) {
			de_bitreader_skip_to_byte_boundary(&bitrd);
			xpos = 0;
			v = 0;
			curr_component++;
			if(curr_component >= d->num_components) {
				ypos++;
				if(ypos >= d->height) goto done;
				curr_component = 0;
			}
			output_pos = ypos*(d->width * d->num_components) + curr_component;
		}
	}

done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %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 $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movb $0x0, -0x51(%rbp)
movl $0x0, -0x58(%rbp)
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x19140
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movb $0x0, -0x68(%rbp)
movq -0x30(%rbp), %rdi
callq 0x167be0
movq -0x10(%rbp), %rax
cmpb $0x0, 0xa(%rax)
jne 0xb71ae
movq -0x8(%rbp), %rdi
leaq 0xfdfd0(%rip), %rsi     # 0x1b5172
movb $0x0, %al
callq 0x15bfb0
jmp 0xb7356
movl $0x1, -0x58(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x4, %esi
callq 0x16a390
movl %eax, -0x8c(%rbp)
cmpb $0x0, -0x70(%rbp)
je 0xb71d7
jmp 0xb7356
movq -0x10(%rbp), %rax
movl -0x8c(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl 0xb4(%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xb7210
movq -0x10(%rbp), %rax
movl -0x8c(%rbp), %ecx
shll %ecx
movl %ecx, %ecx
movzbl 0xb4(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xb723e
movq -0x10(%rbp), %rax
movl -0x8c(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl 0xb4(%rax,%rcx), %ecx
movzbl -0x51(%rbp), %eax
addl %ecx, %eax
movb %al, -0x51(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0xb7264
leaq -0x88(%rbp), %rdi
movl $0x4, %esi
callq 0x16a390
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x94(%rbp), %eax
jae 0xb72cc
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movzbl -0x51(%rbp), %edx
callq 0x168790
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jl 0xb72b9
jmp 0xb72cc
jmp 0xb72bb
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0xb726e
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jl 0xb7351
leaq -0x88(%rbp), %rdi
callq 0x16a460
movq $0x0, -0x38(%rbp)
movb $0x0, -0x51(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jl 0xb7330
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jl 0xb7328
jmp 0xb7356
movq $0x0, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x10(%rbp), %rdx
imulq 0x48(%rdx), %rcx
imulq %rcx, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xb71b5
movl -0x58(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)