// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/lbr.c
// Function: de_run_squeeze
static void de_run_squeeze(deark *c, de_module_params *mparams)
{
	i64 pos = 0;
	i64 n;
	struct squeeze_ctx *sqctx = NULL;
	de_finfo *fi = NULL;
	struct de_crcobj *crco = NULL;
	dbuf *outf_tmp = NULL;
	dbuf *outf_final = NULL;
	int saved_indent_level;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;
	struct de_dcmpr_two_layer_params tlp;

	de_dbg_indent_save(c, &saved_indent_level);
	sqctx = de_malloc(c, sizeof(struct squeeze_ctx));
	sqctx->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);

	n = de_getu16le_p(&pos);
	if(n==0xff76) {
		de_declare_fmt(c, "Squeezed");
	}
	else if(n==0xfffa) {
		de_declare_fmt(c, "Squeeze v2 (SQ2)");
		sqctx->is_sq2 = 1;
	}
	else {
		de_dbg(c, "Not a Squeezed file");
		goto done;
	}

	if(sqctx->is_sq2) {
		if(!read_sq2_headers(c, sqctx, pos)) goto done;
	}
	else {
		if(!read_squeeze_headers(c, sqctx, pos)) goto done;
	}

	pos = sqctx->cmpr_data_pos;

	fi = de_finfo_create(c);
	de_finfo_set_name_from_ucstring(c, fi, sqctx->fnd.fn, 0);
	fi->original_filename_flag = 1;

	de_dbg(c, "squeeze-compressed data at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	// We have to decompress the file before we can find the timestamp. That's
	// why we decompress to a membuf.
	outf_tmp = dbuf_create_membuf(c, 0, 0);
	dbuf_enable_wbuffer(outf_tmp);

	de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);
	dcmpri.f = c->infile;
	dcmpri.pos = pos;
	dcmpri.len = c->infile->len - pos;
	dcmpro.f = outf_tmp;

	crco = de_crcobj_create(c, DE_CRCOBJ_SUM_BYTES);
	dbuf_set_writelistener(outf_tmp, de_writelistener_for_crc, (void*)crco);

	de_zeromem(&tlp, sizeof(struct de_dcmpr_two_layer_params));
	tlp.codec1_type1 = fmtutil_huff_squeeze_codectype1;
	tlp.codec2 = dfilter_rle90_codec;
	tlp.dcmpri = &dcmpri;
	tlp.dcmpro = &dcmpro;
	tlp.dres = &dres;
	de_dfilter_decompress_two_layer(c, &tlp);
	dbuf_flush(dcmpro.f);

	if(dres.bytes_consumed_valid) {
		de_dbg(c, "compressed data size: %"I64_FMT", ends at %"I64_FMT, dres.bytes_consumed,
			dcmpri.pos+dres.bytes_consumed);

		do_sqeeze_timestamp(c, sqctx, dcmpri.pos+dres.bytes_consumed);
		if(sqctx->timestamp.is_valid) {
			fi->timestamp[DE_TIMESTAMPIDX_MODIFY] = sqctx->timestamp;
		}
	}

	outf_final = dbuf_create_output_file(c, NULL, fi, 0);
	dbuf_copy(outf_tmp, 0, outf_tmp->len, outf_final);

	if(dres.errcode) {
		de_err(c, "Decompression failed: %s", de_dfilter_get_errmsg(c, &dres));
		goto done;
	}

	sqctx->checksum_calc = de_crcobj_getval(crco);
	sqctx->checksum_calc &= 0xffff;
	de_dbg(c, "checksum (calculated): %u", (UI)sqctx->checksum_calc);
	if(sqctx->checksum_calc != sqctx->checksum_reported) {
		de_err(c, "Checksum error. Decompression probably failed.");
		goto done;
	}

done:
	if(sqctx) {
		crcr_filename_data_freecontents(c, &sqctx->fnd);
		de_destroy_stringreaderdata(c, sqctx->sq2_timestamp_string);
		de_destroy_stringreaderdata(c, sqctx->sq2_comment);
		de_free(c, sqctx);
	}
	dbuf_close(outf_final);
	dbuf_close(outf_tmp);
	de_finfo_destroy(c, fi);
	de_crcobj_destroy(crco);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %rbx
movq %rsp, %r15
movq $0x0, (%r15)
leaq 0xc(%rsp), %rsi
callq 0xe958c
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
cmpq $0xfffa, %rax           # imm = 0xFFFA
je 0x9f74e
cmpq $0xff76, %rax           # imm = 0xFF76
jne 0x9f89e
leaq 0x9272e(%rip), %rsi     # 0x131e72
movq %rbx, %rdi
callq 0xeb6d6
jmp 0x9f761
leaq 0x92726(%rip), %rsi     # 0x131e7b
movq %rbx, %rdi
callq 0xeb6d6
movb $0x1, (%r14)
cmpb $0x0, (%r14)
movq (%rsp), %r15
je 0x9f8b7
movq %r15, 0x40(%rsp)
leaq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa1192
testl %eax, %eax
je 0x9fc1d
movq 0x40(%rsp), %rsi
addq 0x18(%r14), %rsi
movq %rsi, 0x40(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %r9d
movl $0x12c, %edx            # imm = 0x12C
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xefe67
movq %rax, 0x20(%r14)
cmpl $0x0, 0x34(%rax)
je 0x9fc1d
movq 0x18(%rax), %rdi
callq 0xf7557
leaq 0x92741(%rip), %rsi     # 0x131f15
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x20(%r14), %rax
movq 0x40(%rsp), %rsi
addq (%rax), %rsi
movq %rsi, 0x40(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %r9d
movl $0x12c, %edx            # imm = 0x12C
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xefe67
movq %rax, 0x28(%r14)
cmpl $0x0, 0x34(%rax)
je 0x9fc1d
movq 0x18(%rax), %rdi
callq 0xf7557
leaq 0x74f78(%rip), %rsi     # 0x1147a5
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x28(%r14), %rax
movq (%rax), %rax
leaq 0x40(%rsp), %rsi
addq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef14d
cmpb $0x1a, %al
jne 0x9fc1d
movq 0x40(%rsp), %rax
leaq 0x98(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef1ed
movl %eax, 0x30(%r14)
leaq 0x926cb(%rip), %rsi     # 0x131f49
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x40(%rsp), %rax
addq $0x6, %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x38(%r14)
jmp 0x9f905
leaq 0x925e7(%rip), %rsi     # 0x131e8c
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0x9fc31
leaq 0x98(%rsp), %rsi
movq %r15, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef1ed
movl %eax, 0x30(%r14)
leaq 0x92673(%rip), %rsi     # 0x131f49
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
addq $0x2, %r15
leaq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa1192
testl %eax, %eax
je 0x9fc1d
addq 0x18(%r14), %r15
movq %r15, 0x38(%r14)
movq 0x38(%r14), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r13
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xea9e4
movb $0x1, 0x8(%r13)
movq (%rsp), %rdx
leaq 0x92567(%rip), %rsi     # 0x131ea0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %r12
movq %rax, %rdi
callq 0xf0e3f
leaq 0xf8(%rsp), %r15
leaq 0x118(%rsp), %rbp
leaq 0x98(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, (%r15)
movq (%rsp), %rcx
movq %rcx, 0x8(%r15)
movq 0x18(%rax), %rax
subq %rcx, %rax
movq %rax, 0x10(%r15)
movq %r12, (%rbp)
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeba56
leaq 0x52092(%rip), %rsi     # 0xf1a51
movq %r12, %rdi
movq %rax, 0x18(%rsp)
movq %rax, %rdx
callq 0xf1a12
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x40(%rsi)
leaq 0x5be80(%rip), %rax     # 0xfb871
movq %rax, (%rsi)
leaq 0x5b402(%rip), %rax     # 0xfadfd
movq %rax, 0x18(%rsi)
movq %r15, 0x28(%rsi)
movq %r13, %r15
movq %rbp, 0x30(%rsi)
leaq 0x98(%rsp), %rax
movq %rax, 0x38(%rsi)
movq %rbx, %rdi
callq 0xfb662
movq (%rbp), %rdi
callq 0xf0ea4
leaq 0x98(%rsp), %rax
cmpb $0x0, 0x4(%rax)
je 0x9fbc0
movq 0xa0(%rsp), %rdx
movq 0x100(%rsp), %rcx
addq %rdx, %rcx
leaq 0x9246c(%rip), %rsi     # 0x131ebf
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0xa0(%rsp), %rbp
addq 0x100(%rsp), %rbp
movq %rbp, 0x20(%rsp)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
subq %rbp, %rax
cmpq $0x8, %rax
jl 0x9fbad
leaq 0x20(%rsp), %rsi
callq 0xef1ed
cmpq $0xff77, %rax           # imm = 0xFF77
jne 0x9fbad
movq 0x18(%rbx), %rdi
movq %r15, 0x10(%rsp)
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0xef1ed
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, 0x28(%rsp)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %r15
callq 0xef1ed
movq %rax, %r13
movq 0x18(%rbx), %rdi
movl $0x6, %edx
movq %rbp, %rsi
movl $0x31, %ecx
callq 0xebf42
movzwl %ax, %eax
movq %r13, 0x38(%rsp)
cmpl %r13d, %eax
jne 0x9fbad
leaq 0x92456(%rip), %rsi     # 0x131f61
movq %rbx, %rdi
movl %eax, %r13d
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x40(%r14), %r15
movq %r15, %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0xeae33
movb $0x2, 0x41(%r14)
leaq 0x130(%rsp), %rbp
movl $0x40, %edx
movq %r15, %rdi
movq 0x10(%rsp), %r15
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
leaq 0x7931e(%rip), %rsi     # 0x118e87
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
leaq 0x923f5(%rip), %rsi     # 0x131f72
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
leaq 0x92409(%rip), %rsi     # 0x131f9a
movq %rbx, %rdi
movq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0x40(%r14)
je 0x9fbc0
leaq 0x40(%r14), %rax
movups (%rax), %xmm0
movups %xmm0, 0x18(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %rbp
movq 0x18(%r12), %rdx
movq %r12, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0xefabc
cmpl $0x0, 0x98(%rsp)
je 0x9fcb4
leaq 0x98(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0x74568(%rip), %rsi     # 0x114171
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
movq 0x18(%rsp), %r13
jmp 0x9fc39
leaq 0x92308(%rip), %rsi     # 0x131f2c
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
testq %r14, %r14
je 0x9fc73
movq 0x8(%r14), %rdi
callq 0xf6bb0
movq 0x10(%r14), %rdi
callq 0xf6bb0
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xf00aa
movq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0xf00aa
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movq %rbp, %rdi
callq 0xf0b13
movq %r12, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea9b3
movq %r13, %rdi
callq 0xebe1d
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0xebe2a
movzwl %ax, %edx
movl %edx, 0x34(%r14)
leaq 0x7a646(%rip), %rsi     # 0x11a315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x34(%r14), %eax
cmpl 0x30(%r14), %eax
je 0x9fc39
leaq 0x921f8(%rip), %rsi     # 0x131ee6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x9fc39