// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/binhex.c
// Function: do_binhex
static void do_binhex(deark *c, lctx *d, i64 pos)
{
	int ret;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;

	init_binhex_decoder(c, d);
	de_dbg(c, "BinHex data starts at %d", (int)pos);

	d->decoded = dbuf_create_membuf(c, 65536, 0);
	dbuf_enable_wbuffer(d->decoded);
	d->decompressed = dbuf_create_membuf(c, 65536, 0);
	dbuf_enable_wbuffer(d->decompressed);

	ret = do_decode_main(c, d, pos);
	dbuf_flush(d->decoded);
	if(!ret) goto done;

	de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);
	dcmpri.f = d->decoded;
	dcmpri.pos = 0;
	dcmpri.len = d->decoded->len;
	dcmpro.f = d->decompressed;
	fmtutil_decompress_rle90_ex(c, &dcmpri, &dcmpro, &dres, 0);
	dbuf_flush(dcmpro.f);
	if(dres.errcode) {
		de_err(c, "%s", de_dfilter_get_errmsg(c, &dres));
		goto done;
	}
	de_dbg(c, "size after decompression: %d", (int)d->decompressed->len);

	d->advf = de_advfile_create(c);

	do_extract_forks(c, d);

done:
	de_advfile_destroy(d->advf);
	d->advf = NULL;
	dbuf_close(d->decompressed);
	d->decompressed = NULL;
	dbuf_close(d->decoded);
	d->decoded = NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3dd90
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x16507d(%rip), %rsi    # 0x1a2c42
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x3de00
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x167c30
cmpl $0x0, -0x1c(%rbp)
jne 0x3dc48
jmp 0x3dd33
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0xb8(%rbp), %rcx
callq 0x1773f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0xb8(%rbp), %rcx
xorl %r8d, %r8d
callq 0x177f90
movq -0x58(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0xb8(%rbp)
je 0x3dcf2
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x177360
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
leaq 0x162e46(%rip), %rsi    # 0x1a0b2f
movb $0x0, %al
callq 0x15bfb0
jmp 0x3dd33
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x164f50(%rip), %rsi    # 0x1a2c5b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x17aa20
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3e010
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x17aaa0
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1676a0
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1676a0
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)