// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/dms.c
// Function: dmslzh_codectype1
static void dmslzh_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
	struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
	void *codec_private_params)
{
	struct dmslzh_params *lzhp = (struct dmslzh_params*)codec_private_params;
	struct lzh_ctx *cctx = NULL;
	struct dmsheavy_cmpr_state *hvst = NULL;

	cctx = de_malloc(c, sizeof(struct lzh_ctx));
	cctx->modname = "undmslzh";
	cctx->c = c;
	cctx->dcmpri = dcmpri;
	cctx->dcmpro = dcmpro;
	cctx->dres = dres;
	cctx->bitrd.f = dcmpri->f;
	cctx->bitrd.curpos = dcmpri->pos;
	cctx->bitrd.endpos = dcmpri->pos + dcmpri->len;

	if(lzhp->heavy_state) {
		// If a previous decompression state exists, use it.
		hvst = lzhp->heavy_state;
		lzhp->heavy_state = NULL;
	}
	else {
		hvst = de_malloc(c, sizeof(struct dmsheavy_cmpr_state));
		hvst->cmpr_type = lzhp->cmpr_type;
	}

	decompress_dms_heavy(cctx, lzhp, hvst);

	hvst->ringbuf->userdata = NULL;
	hvst->ringbuf->writebyte_cb = NULL;
	lzhp->heavy_state = hvst;
	hvst = NULL;

	if(cctx->err_flag) {
		// A default error message
		de_dfilter_set_errorf(c, dres, cctx->modname, "LZH decoding error");
		goto done;
	}

	de_bitreader_skip_to_byte_boundary(&cctx->bitrd);
	cctx->dres->bytes_consumed = cctx->bitrd.curpos - cctx->dcmpri->pos;
	if(cctx->dres->bytes_consumed<0) {
		cctx->dres->bytes_consumed = 0;
	}
	cctx->dres->bytes_consumed_valid = 1;

done:
	if(hvst) destroy_heavy_state(c, hvst);
	de_free(c, cctx);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
leaq 0x142ba2(%rip), %rcx    # 0x1a9d33
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x67220
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x6723e
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0x15b780
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x67390
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x672ac
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x142a99(%rip), %rcx    # 0x1a9d3c
movb $0x0, %al
callq 0x177450
jmp 0x67304
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
callq 0x16a460
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
subq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x8(%rax)
jge 0x672f8
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movb $0x1, 0x4(%rax)
cmpq $0x0, -0x40(%rbp)
je 0x67318
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x67330
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)