// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/src/fmtutil-lzh.c
// Function: fmtutil_decompress_zip_implode
void fmtutil_decompress_zip_implode(deark *c, struct de_dfilter_in_params *dcmpri,
	struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
	struct de_zipimplode_params *params)
{
	struct lzh_ctx *cctx = NULL;

	cctx = de_malloc(c, sizeof(struct lzh_ctx));
	cctx->modname = "implode";
	cctx->c = c;
	cctx->dcmpri = dcmpri;
	cctx->dcmpro = dcmpro;
	cctx->dres = dres;

	cctx->bitrd.bbll.is_lsb = 1;
	cctx->bitrd.f = dcmpri->f;
	cctx->bitrd.curpos = dcmpri->pos;
	cctx->bitrd.endpos = dcmpri->pos + dcmpri->len;

	if(params->bit_flags & IMPLODE_FLAG_8KDICT) {
		cctx->implode_8k_buffer = 1;
	}
	if(params->bit_flags & IMPLODE_FLAG_3TREES) {
		cctx->implode_3_trees = 1;
	}
	if(params->mml_bug) {
		cctx->implode_min_match_len = cctx->implode_8k_buffer ? 3 : 2;
	}
	else {
		cctx->implode_min_match_len = cctx->implode_3_trees ? 3 : 2;
	}

	decompress_implode_internal(cctx);

	if(cctx->err_flag) {
		// A default error message
		de_dfilter_set_errorf(c, dres, cctx->modname, "Implode 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:
	destroy_lzh_ctx(cctx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbp
movl $0xd0, %esi
callq 0xdecaf
movq %rax, %rbx
leaq 0x41ed2(%rip), %rax     # 0x13663d
movq %rax, 0x20(%rbx)
movq %rbp, 0x8(%rsp)
movq %rbp, (%rbx)
movq %r12, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %r13, 0x18(%rbx)
movb $0x1, 0x58(%rbx)
movq (%r12), %rax
movq %rax, 0x38(%rbx)
movq 0x8(%r12), %rax
movq %rax, 0x40(%rbx)
addq 0x10(%r12), %rax
movq %rax, 0x48(%rbx)
movl (%r14), %eax
testb $0x2, %al
je 0xf47af
movb $0x1, 0xb0(%rbx)
testb $0x4, %al
je 0xf47ba
movb $0x1, 0xb1(%rbx)
cmpb $0x0, 0x4(%r14)
movq %r13, 0x28(%rsp)
je 0xf47d0
movb 0xb0(%rbx), %al
cmpb $0x1, %al
jmp 0xf47dd
cmpb $0x1, 0xb1(%rbx)
movb 0xb0(%rbx), %al
pushq $0x3
popq %rcx
sbbl $0x0, %ecx
movl %ecx, 0xb4(%rbx)
xorl %esi, %esi
testb %al, %al
setne %sil
shll $0xc, %esi
addl $0x1000, %esi           # imm = 0x1000
movq 0x8(%rsp), %rdi
callq 0xef27c
movq %rax, 0x70(%rbx)
movq %rbx, (%rax)
leaq 0xa81(%rip), %rcx       # 0xf5293
movq %rcx, 0x8(%rax)
cmpb $0x0, 0xb1(%rbx)
je 0xf485b
movq (%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x100, %edx            # imm = 0x100
callq 0xf8601
leaq 0x98(%rbx), %rsi
movq %rax, 0x98(%rbx)
leaq 0x49adc(%rip), %rcx     # 0x13e322
movq %rbx, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0xf5fab
testl %eax, %eax
je 0xf4a42
movq (%rbx), %rdi
pushq $0x40
popq %rsi
movl $0x100, %edx            # imm = 0x100
callq 0xf8601
leaq 0xa8(%rbx), %rsi
movq %rax, 0xa8(%rbx)
leaq 0x49aab(%rip), %rcx     # 0x13e32b
pushq $0x40
popq %rdx
movq %rbx, %rdi
movq %rsi, 0x30(%rsp)
callq 0xf5fab
testl %eax, %eax
je 0xf4a42
movq (%rbx), %rdi
pushq $0x40
popq %rsi
movl $0x100, %edx            # imm = 0x100
callq 0xf8601
leaq 0xa0(%rbx), %rsi
movq %rax, 0xa0(%rbx)
leaq 0x27306(%rip), %rcx     # 0x11bbc3
pushq $0x40
popq %rdx
movq %rbx, %rdi
movq %rsi, 0x20(%rsp)
callq 0xf5fab
testl %eax, %eax
je 0xf4a42
leaq 0x38(%rbx), %rbp
movq 0x40(%rbx), %rdx
leaq 0x49a21(%rip), %rsi     # 0x13e305
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0xde9f1
cmpb $0x1, 0xb0(%rbx)
pushq $0x7
popq %rax
sbbl $0x0, %eax
movl %eax, 0x14(%rsp)
movq %rbx, %r12
addq $0x98, %r12
pushq $0x1
popq %r13
movq %r12, 0x18(%rsp)
cmpb $0x0, 0x50(%rbx)
movl 0x30(%rbx), %eax
jne 0xf4a7b
testl %eax, %eax
jne 0xf4a49
movq %rbx, %rdi
callq 0xf5ddd
testl %eax, %eax
jne 0xf4a7f
movq %rbp, %rdi
movl %r13d, %esi
callq 0xe6a4a
testl %eax, %eax
je 0xf495c
cmpq $0x0, (%r12)
je 0xf49b2
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf5df8
jmp 0xf49bd
movq %rbp, %rdi
movl 0x14(%rsp), %r15d
movl %r15d, %esi
callq 0xe6a4a
movq %rax, %r14
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0xf5df8
movl %eax, %r12d
movl %r15d, %ecx
shll %cl, %r12d
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0xf5df8
cmpl $0x3f, %eax
jne 0xf49f0
movq %rbp, %rdi
pushq $0x8
popq %rsi
callq 0xe6a4a
movl 0xb4(%rbx), %ecx
leal (%rcx,%rax), %r15d
addl $0x3f, %r15d
jmp 0xf49fa
movq %rbp, %rdi
pushq $0x8
popq %rsi
callq 0xe6a4a
movq (%rbx), %rcx
cmpl $0x4, (%rcx)
movzbl %al, %r14d
jl 0xf49df
movq 0x8(%rsp), %rdi
leaq 0x48c57(%rip), %rsi     # 0x13d62c
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x70(%rbx), %rdi
movl %r14d, %esi
callq 0xef336
jmp 0xf4914
movl %eax, %r15d
addl 0xb4(%rbx), %r15d
orl %r14d, %r12d
movq 0x8(%rsp), %rax
cmpl $0x4, (%rax)
jl 0xf4a22
leal 0x1(%r12), %edx
movq 0x8(%rsp), %rdi
leaq 0x49abc(%rip), %rsi     # 0x13e4d4
movl %r15d, %ecx
xorl %eax, %eax
callq 0xde896
movq 0x70(%rbx), %rdi
notl %r12d
addl 0x10(%rdi), %r12d
movl %r12d, %esi
movl %r15d, %edx
callq 0xef363
movq 0x18(%rsp), %r12
jmp 0xf4914
movl $0x1, 0x30(%rbx)
movq 0x20(%rbx), %rdx
leaq 0x493bf(%rip), %rcx     # 0x13de13
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0xee823
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf3885
testl %eax, %eax
jne 0xf4a49
movq %rbp, %rdi
callq 0xe6abe
movq 0x40(%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x18(%rbx), %rdx
subq 0x8(%rcx), %rax
xorl %ecx, %ecx
testq %rax, %rax
cmovgq %rax, %rcx
movq %rcx, 0x8(%rdx)
movb $0x1, 0x4(%rdx)
jmp 0xf4a65