// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
movl $0xd0, %esi
callq 0xe969b
movq %rax, %rbx
leaq 0x4275d(%rip), %rax     # 0x1435ad
movq %rax, 0x20(%rbx)
movq %r15, (%rbx)
movq %r13, 0x8(%rbx)
movq %r12, 0x10(%rbx)
movq %rbp, 0x20(%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 0x100e92
movb $0x1, 0xb0(%rbx)
testb $0x4, %al
je 0x100e9d
movb $0x1, 0xb1(%rbx)
cmpb $0x1, 0x4(%r14)
movq %rbx, %rax
adcq $0xb0, %rax
cmpb $0x1, (%rax)
movl $0x3, %eax
sbbl $0x0, %eax
movl %eax, 0xb4(%rbx)
xorl %esi, %esi
cmpb $0x0, 0xb0(%rbx)
leaq 0x38(%rbx), %r12
setne %sil
shll $0xc, %esi
addl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdi
callq 0xfb2c3
movq %rax, 0x70(%rbx)
movq %rbx, (%rax)
leaq 0xace(%rip), %rcx       # 0x1019ba
movq %rcx, 0x8(%rax)
cmpb $0x0, 0xb1(%rbx)
je 0x100f35
movq (%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x100, %edx            # imm = 0x100
callq 0x105165
leaq 0x98(%rbx), %rsi
movq %rax, 0x98(%rbx)
leaq 0x4a2db(%rip), %rcx     # 0x14b1fb
movq %rbx, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x102876
testl %eax, %eax
je 0x101117
movq (%rbx), %rdi
movl $0x40, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x105165
leaq 0xa8(%rbx), %rsi
movq %rax, 0xa8(%rbx)
leaq 0x4a2a8(%rip), %rcx     # 0x14b204
movq %rbx, %rdi
movq %rsi, 0x18(%rsp)
movl $0x40, %edx
callq 0x102876
testl %eax, %eax
je 0x101117
movq (%rbx), %rdi
movl $0x40, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x105165
leaq 0xa0(%rbx), %rsi
movq %rax, 0xa0(%rbx)
leaq 0x27c36(%rip), %rcx     # 0x128bd3
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
movl $0x40, %edx
callq 0x102876
testl %eax, %eax
je 0x101117
movq 0x40(%rbx), %rdx
leaq 0x4a21c(%rip), %rsi     # 0x14b1de
movq %r15, %rdi
xorl %eax, %eax
callq 0xe93cf
cmpb $0x1, 0xb0(%rbx)
movl $0x7, %eax
sbbl $0x0, %eax
movl %eax, 0x4(%rsp)
cmpb $0x0, 0x50(%rbx)
jne 0x10111e
movq %rbx, %r14
addq $0x98, %r14
movq %r14, 0x8(%rsp)
cmpl $0x0, 0x30(%rbx)
jne 0x10111e
movq 0x10(%rbx), %rax
cmpb $0x0, 0x8(%rax)
je 0x10101a
movq 0x28(%rbx), %rcx
cmpq 0x10(%rax), %rcx
jge 0x10111e
movq %r12, %rdi
movl $0x1, %esi
callq 0xf2271
testl %eax, %eax
je 0x10103e
cmpq $0x0, (%r14)
je 0x101091
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1026f6
jmp 0x10109e
movq %r12, %rdi
movl 0x4(%rsp), %ebp
movl %ebp, %esi
callq 0xf2271
movq %rax, %r14
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x1026f6
movl %eax, %r13d
movl %ebp, %ecx
shll %cl, %r13d
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x1026f6
cmpl $0x3f, %eax
jne 0x1010c9
movq %r12, %rdi
movl $0x8, %esi
callq 0xf2271
movl 0xb4(%rbx), %ecx
leal (%rcx,%rax), %ebp
addl $0x3f, %ebp
jmp 0x1010d1
movq %r12, %rdi
movl $0x8, %esi
callq 0xf2271
movq (%rbx), %rcx
cmpl $0x4, (%rcx)
movzbl %al, %ebp
jl 0x1010bc
movq %r15, %rdi
leaq 0x49499(%rip), %rsi     # 0x14a54c
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x70(%rbx), %rdi
movl %ebp, %esi
callq 0xfb382
jmp 0x10110b
movl %eax, %ebp
addl 0xb4(%rbx), %ebp
orl %r14d, %r13d
cmpl $0x4, (%r15)
jl 0x1010f1
leal 0x1(%r13), %edx
movq %r15, %rdi
leaq 0x4a2c5(%rip), %rsi     # 0x14b3ad
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe9226
movq 0x70(%rbx), %rdi
notl %r13d
addl 0x10(%rdi), %r13d
movl %r13d, %esi
movl %ebp, %edx
callq 0xfb3af
movq 0x8(%rsp), %r14
cmpb $0x0, 0x50(%rbx)
je 0x100ff8
jmp 0x10111e
movl $0x1, 0x30(%rbx)
cmpl $0x0, 0x30(%rbx)
je 0x101140
movq 0x20(%rbx), %rdx
leaq 0x49bbd(%rip), %rcx     # 0x14acec
movq %r15, %rdi
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0xfa71e
jmp 0x101169
movq %r12, %rdi
callq 0xf22f1
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 $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xffe9f