// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/src/fmtutil-cmpr.c
// Function: de_dfilter_decompress_two_layer
void de_dfilter_decompress_two_layer(deark *c, struct de_dcmpr_two_layer_params *tlp)
{
	dbuf *outf_codec1 = NULL;
	struct de_dfilter_out_params dcmpro_codec1;
	struct de_dfilter_results dres_codec2;
	struct my_2layer_userdata u;
	struct de_dfilter_ctx *dfctx_codec2 = NULL;

	de_dfilter_init_objects(c, NULL, &dcmpro_codec1, NULL);
	de_dfilter_init_objects(c, NULL, NULL, &dres_codec2);
	de_zeromem(&u, sizeof(struct my_2layer_userdata));

	// Make a custom dbuf. The output from the first decompressor will be written
	// to it, and it will relay that output to the second decompressor.
	outf_codec1 = dbuf_create_custom_dbuf(c, 0, 0);
	dbuf_enable_wbuffer(outf_codec1);
	outf_codec1->userdata_for_customwrite = (void*)&u;
	outf_codec1->customwrite_fn = my_2layer_write_cb;

	dcmpro_codec1.f = outf_codec1;
	if(tlp->intermed_len_known) {
		dcmpro_codec1.len_known = 1;
		dcmpro_codec1.expected_len = tlp->intermed_expected_len;
	}
	else {
		dcmpro_codec1.len_known = 0;
		dcmpro_codec1.expected_len = 0;
	}

	dfctx_codec2 = de_dfilter_create(c, tlp->codec2, tlp->codec2_private_params, tlp->dcmpro, &dres_codec2);
	u.dfctx_codec2 = dfctx_codec2;

	// The first codec in the chain does not need the advanced (de_dfilter_create) API.
	if(tlp->codec1_type1) {
		tlp->codec1_type1(c, tlp->dcmpri, &dcmpro_codec1, tlp->dres, tlp->codec1_private_params);
	}
	else {
		de_dfilter_decompress_oneshot(c, tlp->codec1_pushable, tlp->codec1_private_params,
			tlp->dcmpri, &dcmpro_codec1, tlp->dres);
	}
	dbuf_flush(outf_codec1);
	de_dfilter_finish(dfctx_codec2);

	if(tlp->dres->errcode) goto done;
	de_dbg2(c, "size after intermediate decompression: %"I64_FMT, u.intermediate_nbytes);

	if(dres_codec2.errcode) {
		// An error occurred in codec2, and not in codec1.
		// Copy the error info to the dres that will be returned to the caller.
		de_dfilter_transfer_error(c, &dres_codec2, tlp->dres);
		goto done;
	}

done:
	de_dfilter_destroy(dfctx_codec2);
	dbuf_close(outf_codec1);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rsi, %rbx
movq %rdi, %r15
andq $0x0, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
xorl %r12d, %r12d
movb %r12b, 0x34(%rsp)
andq $0x0, 0x38(%rsp)
movb %r12b, 0x40(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r13
movaps %xmm0, (%r13)
xorl %esi, %esi
xorl %edx, %edx
callq 0xe6277
movq %rax, %r14
movq %rax, %rdi
callq 0xe589c
movq %r13, 0xa8(%r14)
leaq 0xf2(%rip), %rax        # 0xef6cc
movq %rax, 0xb0(%r14)
movq %r14, 0x8(%rsp)
movl $0x0, %eax
cmpb %r12b, 0x40(%rbx)
je 0xef5f8
movq 0x48(%rbx), %rax
movb $0x1, %r12b
movb %r12b, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
movq 0x30(%rbx), %rcx
leaq 0x30(%rsp), %r8
movq %r15, %rdi
callq 0xee930
movq %rax, %r12
movq %rax, 0x20(%rsp)
movq (%rbx), %rax
testq %rax, %rax
je 0xef643
movq 0x10(%rbx), %r8
movq 0x28(%rbx), %rsi
movq 0x38(%rbx), %rcx
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq *%rax
jmp 0xef660
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq 0x28(%rbx), %rcx
movq 0x38(%rbx), %r9
leaq 0x8(%rsp), %r8
movq %r15, %rdi
callq 0xeea46
movq %r14, %rdi
callq 0xe58e8
movq 0x40(%r12), %rax
testq %rax, %rax
je 0xef677
movq %r12, %rdi
callq *%rax
movq 0x38(%rbx), %rax
cmpl $0x0, (%rax)
jne 0xef6ab
movq 0x28(%rsp), %rdx
leaq 0x4dfc8(%rip), %rsi     # 0x13d654
movq %r15, %rdi
xorl %eax, %eax
callq 0xde9f1
cmpl $0x0, 0x30(%rsp)
je 0xef6ab
movq 0x38(%rbx), %rdx
leaq 0x30(%rsp), %rsi
callq 0xef523
movq %r12, %rdi
callq 0xee9dd
movq %r14, %rdi
callq 0xe5591
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq