// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/dms.c
// Function: do_decompress_track_q_m_d
static void do_decompress_track_q_m_d(deark *c, struct dmsctx *d, struct dms_track_info *tri,
	struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
	struct de_dfilter_results *dres)
{
	struct dms_std_cmpr_state *cst = NULL;
	struct std_saved_state_wrapper *ssw;

	if(tri->cmpr_type==DMSCMPR_QUICK) {
		ssw = &d->saved_quick_state;
	}
	else if(tri->cmpr_type==DMSCMPR_DEEP) {
		ssw = &d->saved_deep_cmpr_state;
	}
	else {
		ssw = &d->saved_medium_state;
	}

	if(ssw->saved_state) {
		if(tri->is_real) {
			// Reclaim saved decompression state, if any
			cst = ssw->saved_state;
			ssw->saved_state = NULL;

			cst->dcmpro1.len_known = 1;
			cst->dcmpro1.expected_len = tri->intermediate_len;

			de_dfilter_command(cst->dfctx_codec1, DE_DFILTER_COMMAND_RESET_COUNTERS, 0);
		}
		else {
			destroy_std_cmpr_state(c, ssw->saved_state);
			ssw->saved_state = NULL;
		}
	}

	if(!cst) {
		cst = de_malloc(c, sizeof(struct dms_std_cmpr_state));
		cst->cmpr_meth = tri->cmpr_type;
		if(cst->cmpr_meth==DMSCMPR_QUICK) {
			cst->cmpr_meth_name = "quickcmpr";
		}
		else if(cst->cmpr_meth==DMSCMPR_DEEP) {
			cst->cmpr_meth_name = "deepcmpr";
		}
		else {
			cst->cmpr_meth_name = "mediumcmpr";
		}

		cst->outf_codec1 = dbuf_create_custom_dbuf(c, 0, 0);
		cst->outf_codec1->userdata_for_customwrite = (void*)cst;
		cst->outf_codec1->customwrite_fn = my_std1_write_cb;

		cst->dcmpro1.f = cst->outf_codec1;
		cst->dcmpro1.len_known = 1;
		cst->dcmpro1.expected_len = tri->intermediate_len;
	}

	// Reset the "length" of this virtual dbuf.
	dbuf_truncate(cst->outf_codec1, 0);

	if(cst->dfctx_rle) {
		de_dfilter_destroy(cst->dfctx_rle);
		cst->dfctx_rle = NULL;
	}
	cst->dfctx_rle = de_dfilter_create(c, dmsrle_codec, NULL, dcmpro, dres);

	if(!cst->dfctx_codec1) {
		if(cst->cmpr_meth==DMSCMPR_DEEP) {
			struct de_lh1_params lh1p;

			de_zeromem(&lh1p, sizeof(struct de_lh1_params));
			lh1p.is_dms_deep = 1;
			cst->dfctx_codec1 = de_dfilter_create(c, dfilter_lh1_codec,
				(void*)&lh1p, &cst->dcmpro1, &cst->dres1);
		}
		else if(cst->cmpr_meth==DMSCMPR_QUICK) {
			cst->dfctx_codec1 = de_dfilter_create(c, dmsquicklz77_codec,
				NULL, &cst->dcmpro1, &cst->dres1);
		}
		else {
			cst->dfctx_codec1 = de_dfilter_create(c, dmsmediumlz77_codec,
				NULL, &cst->dcmpro1, &cst->dres1);
		}
	}

	cst->dfctx_codec1->input_file_offset = dcmpri->pos;
	cst->intermediate_nbytes = 0;

	de_dfilter_addslice(cst->dfctx_codec1, dcmpri->f, dcmpri->pos, dcmpri->len);
	de_dfilter_command(cst->dfctx_codec1, DE_DFILTER_COMMAND_FINISH_BLOCK, 0);
	de_dfilter_finish(cst->dfctx_rle);

	// If cst->dfctx_lzah->dres has the error message we need, copy it to the
	// real dres.
	de_dfilter_transfer_error(c, cst->dfctx_codec1->dres, dres);

	if(tri->is_real) {
		// Note that this saved state may be deleted soon, in dms_decompress_track().
		ssw->saved_state = cst;
	}
	else {
		destroy_std_cmpr_state(c, cst);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %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 -0x18(%rbp), %rax
cmpl $0x2, 0x2c(%rax)
jne 0x66042
movq -0x10(%rbp), %rax
addq $0x12f0, %rax           # imm = 0x12F0
movq %rax, -0x40(%rbp)
jmp 0x6606c
movq -0x18(%rbp), %rax
cmpl $0x4, 0x2c(%rax)
jne 0x6605c
movq -0x10(%rbp), %rax
addq $0x1300, %rax           # imm = 0x1300
movq %rax, -0x40(%rbp)
jmp 0x6606a
movq -0x10(%rbp), %rax
addq $0x12f8, %rax           # imm = 0x12F8
movq %rax, -0x40(%rbp)
jmp 0x6606c
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
je 0x660e1
movq -0x18(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x660c4
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rax
movb $0x1, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x177690
jmp 0x660df
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
callq 0x66690
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
jmp 0x660e1
cmpq $0x0, -0x38(%rbp)
jne 0x661bb
movq -0x8(%rbp), %rdi
movl $0xa8, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x66125
movq -0x38(%rbp), %rax
leaq 0x143bd9(%rip), %rcx    # 0x1a9cf8
movq %rcx, 0x8(%rax)
jmp 0x66150
movq -0x38(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x6613f
movq -0x38(%rbp), %rax
leaq 0x143bc9(%rip), %rcx    # 0x1a9d02
movq %rcx, 0x8(%rax)
jmp 0x6614e
movq -0x38(%rbp), %rax
leaq 0x143bc1(%rip), %rcx    # 0x1a9d0b
movq %rcx, 0x8(%rax)
jmp 0x66150
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x169220
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rcx
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0xa8(%rax)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
leaq 0x574(%rip), %rcx       # 0x66700
movq %rcx, 0xb0(%rax)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
movb $0x1, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168900
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x661f0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x177720
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
leaq -0x283(%rip), %rsi      # 0x65f80
xorl %eax, %eax
movl %eax, %edx
callq 0x1775a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x662e1
movq -0x38(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x66274
leaq -0x45(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x19140
movb $0x1, -0x42(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rcx
addq $0x30, %rcx
movq -0x38(%rbp), %r8
addq $0x48, %r8
leaq 0x125162(%rip), %rsi    # 0x18b3c0
leaq -0x45(%rbp), %rdx
callq 0x1775a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x662df
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x662ae
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rcx
addq $0x30, %rcx
movq -0x38(%rbp), %r8
addq $0x48, %r8
leaq 0x4e8(%rip), %rsi       # 0x66780
xorl %eax, %eax
movl %eax, %edx
callq 0x1775a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x662dd
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rcx
addq $0x30, %rcx
movq -0x38(%rbp), %r8
addq $0x48, %r8
leaq 0x5b7(%rip), %rsi       # 0x66880
xorl %eax, %eax
movl %eax, %edx
callq 0x1775a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x662df
jmp 0x662e1
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
callq 0x177770
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x177690
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1776f0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rdx
callq 0x178c20
movq -0x18(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x66376
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
jmp 0x66383
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x66690
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)