// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/hlp.c
// Function: do_hall_decompression
static void do_hall_decompression(deark *c, lctx *d, dbuf *inf, i64 pos1, i64 len,
	dbuf *outf, i64 unc_len_expected)
{
	static const u8 action[16] = {0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4};
	i64 pos = pos1;
	i64 endpos = pos1+len;
	UI n;
	i64 outf_expected_endpos;

	outf_expected_endpos = outf->len + unc_len_expected;

	while(1) {
		u8 b;

		if(outf->len >= outf_expected_endpos) goto unc_done;
		if(pos >= endpos) goto unc_done;
		b = dbuf_getbyte_p(inf, &pos);
		switch(action[b&0x0f]) {
		case 0:
			emit_phrase(c, d, outf, b>>1);
			break;
		case 1:
			if(pos >= endpos) goto unc_done;
			n = (((UI)b & 0xfc) << 6) | 0x80;
			n += dbuf_getbyte_p(inf, &pos);
			emit_phrase(c, d, outf, n);
			break;
		case 2:
			n = (b >> 3) +1;
			if(pos + (i64)n > endpos) goto unc_done;
			dbuf_copy(inf, pos, (i64)n, outf);
			pos += (i64)n;
			break;
		case 3:
			dbuf_write_run(outf, ' ', (i64)(b>>4)+1);
			break;
		default: // 4
			dbuf_write_zeroes(outf, (i64)(b>>4)+1);
			break;
		}
	}
unc_done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
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 %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
addq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x50(%rbp), %rax
jl 0x7e0ab
jmp 0x7e1e5
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x7e0ba
jmp 0x7e1e5
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165170
movb %al, -0x51(%rbp)
movzbl -0x51(%rbp), %eax
andl $0xf, %eax
leaq 0x12eb78(%rip), %rcx    # 0x1acc50
movzbl (%rax,%rcx), %eax
movq %rax, -0x60(%rbp)
subq $0x3, %rax
ja 0x7e1c9
movq -0x60(%rbp), %rax
leaq 0x12eb43(%rip), %rcx    # 0x1acc38
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movzbl -0x51(%rbp), %ecx
sarl %ecx
callq 0x7e410
jmp 0x7e1e0
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x7e129
jmp 0x7e1e5
movzbl -0x51(%rbp), %eax
andl $0xfc, %eax
shll $0x6, %eax
orl $0x80, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x7e410
jmp 0x7e1e0
movzbl -0x51(%rbp), %eax
sarl $0x3, %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
addq %rcx, %rax
cmpq -0x40(%rbp), %rax
jle 0x7e188
jmp 0x7e1e5
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x44(%rbp), %eax
movl %eax, %edx
movq -0x30(%rbp), %rcx
callq 0x166070
movl -0x44(%rbp), %eax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x7e1e0
movq -0x30(%rbp), %rdi
movzbl -0x51(%rbp), %eax
sarl $0x4, %eax
movslq %eax, %rdx
addq $0x1, %rdx
movl $0x20, %esi
callq 0x168800
jmp 0x7e1e0
movq -0x30(%rbp), %rdi
movzbl -0x51(%rbp), %eax
sarl $0x4, %eax
movslq %eax, %rsi
addq $0x1, %rsi
callq 0x1685f0
jmp 0x7e098
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)