// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc3.c
// Function: tc_decompress_rle
static void tc_decompress_rle(struct de_arch_member_data *md)
{
	u8 escchar;
	i64 pos = md->dcmpri->pos;
	i64 endpos = md->dcmpri->pos + md->dcmpri->len;
	i64 nbytes_written = 0;
	static const char *modname = "TC_RLE";

	escchar = dbuf_getbyte_p(md->dcmpri->f, &pos);
	while(1) {
		u8 b0, b1, b2;
		i64 ctmp;
		i64 count = 0;
		u8 val = 0;

		if(pos >= endpos) goto done;

		b0 = dbuf_getbyte_p(md->dcmpri->f, &pos);
		if(b0 != escchar) {
			dbuf_writebyte(md->dcmpro->f, b0);
			nbytes_written++;
			continue;
		}

		b1 = dbuf_getbyte_p(md->dcmpri->f, &pos);
		if(b1==0) {
			count = 1;
			val = escchar;
		}
		else if(b1==1) { // run length 256 to 511
			b2 = dbuf_getbyte_p(md->dcmpri->f, &pos);
			count = 256 + (i64)b2;
			val = dbuf_getbyte_p(md->dcmpri->f, &pos);
		}
		else if(b1==2) { // large  run length
			ctmp = dbuf_getu16be_p(md->dcmpri->f, &pos);
			count = 512 + ctmp;
			val = dbuf_getbyte_p(md->dcmpri->f, &pos);
		}
		else if(b1>3) { // small  run length
			count = (i64)b1;
			val = dbuf_getbyte_p(md->dcmpri->f, &pos);
		}
		else {
			de_dfilter_set_generic_error(md->c, md->dres, modname);
			goto done;
		}
		dbuf_write_run(md->dcmpro->f, val, count);
		nbytes_written += count;
	}
done:
	if(md->dres->errcode==0) {
		de_dbg(md->c, "decompressed %"I64_FMT" to %"I64_FMT" bytes",
			pos-md->dcmpri->pos, nbytes_written);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xb0(%rcx), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x9(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x41(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0xa4e0e
jmp 0xa4fae
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
movzbl -0x9(%rbp), %ecx
cmpl %ecx, %eax
je 0xa4e59
movq -0x8(%rbp), %rax
movq 0xb8(%rax), %rax
movq (%rax), %rdi
movzbl -0x29(%rbp), %esi
callq 0x168380
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xa4df3
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x2a(%rbp)
movzbl -0x2a(%rbp), %eax
cmpl $0x0, %eax
jne 0xa4e8f
movq $0x1, -0x40(%rbp)
movb -0x9(%rbp), %al
movb %al, -0x41(%rbp)
jmp 0xa4f80
movzbl -0x2a(%rbp), %eax
cmpl $0x1, %eax
jne 0xa4edf
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x2b(%rbp)
movzbl -0x2b(%rbp), %eax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x41(%rbp)
jmp 0xa4f7e
movzbl -0x2a(%rbp), %eax
cmpl $0x2, %eax
jne 0xa4f2d
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165210
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x41(%rbp)
jmp 0xa4f7c
movzbl -0x2a(%rbp), %eax
cmpl $0x3, %eax
jle 0xa4f5a
movzbl -0x2a(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, -0x41(%rbp)
jmp 0xa4f7a
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xc0(%rax), %rsi
movq 0x180815(%rip), %rdx    # 0x225788
callq 0x177560
jmp 0xa4fae
jmp 0xa4f7c
jmp 0xa4f7e
jmp 0xa4f80
movq -0x8(%rbp), %rax
movq 0xb8(%rax), %rax
movq (%rax), %rdi
movb -0x41(%rbp), %al
movq -0x40(%rbp), %rdx
movzbl %al, %esi
callq 0x168800
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0xa4df3
movq -0x8(%rbp), %rax
movq 0xc0(%rax), %rax
cmpl $0x0, (%rax)
jne 0xa4fea
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
subq 0x8(%rax), %rdx
movq -0x28(%rbp), %rcx
leaq 0x108115(%rip), %rsi    # 0x1ad0f8
movb $0x0, %al
callq 0x15b0d0
addq $0x50, %rsp
popq %rbp
retq