// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
movl $0xd0, %esi
callq 0xe8b2b
movq %rax, %rbx
leaq 0x433c1(%rip), %rax     # 0x143a8d
movq %rax, 0x20(%rbx)
movq %r15, (%rbx)
movq %r13, 0x8(%rbx)
movq %r12, 0x10(%rbx)
movq %rbp, 0x10(%rsp)
movq %rbp, 0x18(%rbx)
movb $0x1, 0x58(%rbx)
movq (%r13), %rax
movq %rax, 0x38(%rbx)
movq 0x8(%r13), %rax
movq %rax, 0x40(%rbx)
addq 0x10(%r13), %rax
movq %rax, 0x48(%rbx)
movl (%r14), %eax
testb $0x2, %al
je 0x10070e
movb $0x1, 0xb0(%rbx)
testb $0x4, %al
je 0x100719
movb $0x1, 0xb1(%rbx)
cmpb $0x0, 0x4(%r14)
je 0x10072a
movb 0xb0(%rbx), %al
cmpb $0x1, %al
jmp 0x100737
cmpb $0x1, 0xb1(%rbx)
movb 0xb0(%rbx), %al
movl $0x3, %ecx
sbbl $0x0, %ecx
leaq 0x38(%rbx), %r12
movl %ecx, 0xb4(%rbx)
xorl %esi, %esi
testb %al, %al
setne %sil
shll $0xc, %esi
addl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdi
callq 0xfad8f
movq %rax, 0x70(%rbx)
movq %rbx, (%rax)
leaq 0xabd(%rip), %rcx       # 0x10122d
movq %rcx, 0x8(%rax)
cmpb $0x0, 0xb1(%rbx)
je 0x1007b9
movq (%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x100, %edx            # imm = 0x100
callq 0x104d0e
leaq 0x98(%rbx), %rsi
movq %rax, 0x98(%rbx)
leaq 0x4b04e(%rip), %rcx     # 0x14b7f2
movq %rbx, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x101fa9
testl %eax, %eax
je 0x100983
movq (%rbx), %rdi
movl $0x40, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x104d0e
leaq 0xa8(%rbx), %rsi
movq %rax, 0xa8(%rbx)
leaq 0x4b01b(%rip), %rcx     # 0x14b7fb
movq %rbx, %rdi
movl $0x40, %edx
callq 0x101fa9
testl %eax, %eax
je 0x100983
movq (%rbx), %rdi
movl $0x40, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x104d0e
movq %rbx, %rsi
addq $0xa0, %rsi
movq %rax, 0xa0(%rbx)
leaq 0x285e4(%rip), %rcx     # 0x128e03
movq %rbx, %rdi
movl $0x40, %edx
callq 0x101fa9
testl %eax, %eax
je 0x100983
movq 0x40(%rbx), %rdx
leaq 0x4af96(%rip), %rsi     # 0x14b7d5
movq %r15, %rdi
xorl %eax, %eax
callq 0xe87e4
cmpb $0x1, 0xb0(%rbx)
movl $0x7, %eax
sbbl $0x0, %eax
movl %eax, 0xc(%rsp)
cmpb $0x0, 0x50(%rbx)
jne 0x10098a
cmpl $0x0, 0x30(%rbx)
jne 0x10098a
movq 0x10(%rbx), %rax
cmpb $0x0, 0x8(%rax)
je 0x100888
movq 0x28(%rbx), %rcx
cmpq 0x10(%rax), %rcx
jge 0x10098a
movq %r12, %rdi
movl $0x1, %esi
callq 0xf1bed
testl %eax, %eax
je 0x1008af
movq 0x98(%rbx), %rsi
testq %rsi, %rsi
je 0x100906
movq %rbx, %rdi
callq 0x101e47
jmp 0x100913
movq %r12, %rdi
movl 0xc(%rsp), %ebp
movl %ebp, %esi
callq 0xf1bed
movq %rax, %r14
movq 0xa0(%rbx), %rsi
movq %rbx, %rdi
callq 0x101e47
movl %eax, %r13d
movl %ebp, %ecx
shll %cl, %r13d
movq 0xa8(%rbx), %rsi
movq %rbx, %rdi
callq 0x101e47
cmpl $0x3f, %eax
jne 0x100941
movq %r12, %rdi
movl $0x8, %esi
callq 0xf1bed
movl 0xb4(%rbx), %ecx
leal (%rcx,%rax), %ebp
addl $0x3f, %ebp
jmp 0x100949
movq %r12, %rdi
movl $0x8, %esi
callq 0xf1bed
movq (%rbx), %rcx
cmpl $0x4, (%rcx)
movzbl %al, %ebp
jl 0x100931
movq %r15, %rdi
leaq 0x4a1d4(%rip), %rsi     # 0x14aafc
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x70(%rbx), %rdi
movl %ebp, %esi
callq 0xfae4e
jmp 0x10085c
movl %eax, %ebp
addl 0xb4(%rbx), %ebp
orl %r14d, %r13d
cmpl $0x4, (%r15)
jl 0x100969
leal 0x1(%r13), %edx
movq %r15, %rdi
leaq 0x4b044(%rip), %rsi     # 0x14b9a4
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8617
movq 0x70(%rbx), %rdi
notl %r13d
addl 0x10(%rdi), %r13d
movl %r13d, %esi
movl %ebp, %edx
callq 0xfae7b
jmp 0x10085c
movl $0x1, 0x30(%rbx)
cmpl $0x0, 0x30(%rbx)
je 0x1009ac
movq 0x20(%rbx), %rdx
leaq 0x4a948(%rip), %rcx     # 0x14b2e3
movq %r15, %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0xfa21a
jmp 0x1009d5
movq %r12, %rdi
callq 0xf1c84
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)
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xff6fb