// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %rdx
movq %rcx, %rsi
callq 0x1773f0
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rcx
movq %rdx, %rsi
callq 0x1773f0
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x19140
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x169220
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x167b90
movq -0x18(%rbp), %rax
leaq -0xa0(%rbp), %rcx
movq %rcx, 0xa8(%rax)
movq -0x18(%rbp), %rax
leaq 0x163(%rip), %rcx       # 0x178ef0
movq %rcx, 0xb0(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x40(%rax)
je 0x178db8
movb $0x1, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x178dc4
movb $0x0, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
leaq -0x90(%rbp), %r8
callq 0x1775a0
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x178e36
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rsi
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq 0x10(%rdx), %r8
leaq -0x30(%rbp), %rdx
callq *%rax
jmp 0x178e63
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %r9
leaq -0x30(%rbp), %r8
callq 0x177820
movq -0x18(%rbp), %rdi
callq 0x167c30
movq -0xa8(%rbp), %rdi
callq 0x1776f0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpl $0x0, (%rax)
je 0x178e87
jmp 0x178ec5
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rdx
leaq 0x5d707(%rip), %rsi     # 0x1d65a0
movb $0x0, %al
callq 0x15b350
cmpl $0x0, -0x90(%rbp)
je 0x178ec3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
leaq -0x90(%rbp), %rsi
callq 0x178c20
jmp 0x178ec5
jmp 0x178ec5
movq -0xa8(%rbp), %rdi
callq 0x177720
movq -0x18(%rbp), %rdi
callq 0x1676a0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)