// File: /workspace/github_c_makefile_star2_O3/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 $0x168, %rsp            # imm = 0x168
movq %rdi, %rbx
leaq 0x8(%rsp), %r15
movq $0x0, (%r15)
leaq 0x1c(%rsp), %rsi
callq 0xe8a1c
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
cmpq $0xff76, %rax           # imm = 0xFF76
je 0x9eed0
cmpq $0xfffa, %rax           # imm = 0xFFFA
jne 0x9f010
leaq 0x9333d(%rip), %rsi     # 0x1321ff
movq %rbx, %rdi
callq 0xeb125
movb $0x1, (%r14)
jmp 0x9eee9
leaq 0x9331f(%rip), %rsi     # 0x1321f6
movq %rbx, %rdi
callq 0xeb125
cmpb $0x0, (%r14)
je 0x9f029
movq 0x8(%rsp), %r15
movq %r15, 0x70(%rsp)
leaq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa08e3
testl %eax, %eax
je 0x9f375
addq 0x18(%r14), %r15
movq %r15, 0x70(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %r9d
movl $0x12c, %edx            # imm = 0x12C
movl $0x12c, %ecx            # imm = 0x12C
movq %r15, %rsi
movl $0x1, %r8d
callq 0xef87c
movq %rax, 0x20(%r14)
cmpl $0x0, 0x34(%rax)
je 0x9f375
movq 0x18(%rax), %rdi
callq 0xf70f6
leaq 0x93348(%rip), %rsi     # 0x132299
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x20(%r14), %rax
addq (%rax), %r15
movq %r15, 0x70(%rsp)
movq 0x18(%rbx), %rdi
movl 0x4(%r14), %r9d
movl $0x12c, %edx            # imm = 0x12C
movl $0x12c, %ecx            # imm = 0x12C
movq %r15, %rsi
movl $0x1, %r8d
callq 0xef87c
movq %rax, 0x28(%r14)
cmpl $0x0, 0x34(%rax)
je 0x9f375
movq 0x18(%rax), %rdi
callq 0xf70f6
leaq 0x758d8(%rip), %rsi     # 0x114880
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x28(%r14), %rax
addq (%rax), %r15
leaq 0x70(%rsp), %rsi
movq %r15, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeeb4b
cmpb $0x1a, %al
jne 0x9f375
movq 0x70(%rsp), %rax
leaq 0xc0(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeebeb
movl %eax, 0x30(%r14)
leaq 0x932d4(%rip), %rsi     # 0x1322cd
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x70(%rsp), %r15
addq $0x6, %r15
jmp 0x9f078
leaq 0x931f9(%rip), %rsi     # 0x132210
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0x9f389
movq 0x8(%rsp), %r15
leaq 0xc0(%rsp), %rsi
movq %r15, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeebeb
movl %eax, 0x30(%r14)
leaq 0x93280(%rip), %rsi     # 0x1322cd
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq $0x2, %r15
leaq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa08e3
testl %eax, %eax
je 0x9f375
addq 0x18(%r14), %r15
movq %r15, 0x38(%r14)
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
callq 0xea504
movq %rax, %r15
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xea53f
movb $0x1, 0x8(%r15)
movq 0x8(%rsp), %rdx
leaq 0x93176(%rip), %rsi     # 0x132224
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %rax, %r12
movq %rax, %rdi
callq 0xf0855
leaq 0x50(%rsp), %rbp
leaq 0x38(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %rdx, %r13
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq 0x18(%rax), %rax
subq %rcx, %rax
movq %rax, 0x10(%rbp)
movq %r12, (%r13)
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeb499
movq %rax, %r13
leaq 0x5231e(%rip), %rsi     # 0xf1451
movq %r12, %rdi
movq %rax, %rdx
callq 0xf1412
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rsi
movups %xmm0, 0x18(%rsi)
movups %xmm0, 0x28(%rsi)
movups %xmm0, 0x38(%rsi)
movups %xmm0, 0x8(%rsi)
movq $0x0, 0x48(%rsi)
leaq 0x5c1af(%rip), %rax     # 0xfb314
movq %rax, (%rsi)
leaq 0x5b78a(%rip), %rax     # 0xfa8f9
movq %rax, 0x18(%rsi)
movq %rbp, 0x28(%rsi)
leaq 0x38(%rsp), %rax
movq %rax, 0x30(%rsi)
leaq 0xc0(%rsp), %rbp
movq %rbp, 0x38(%rsi)
movq %rbx, %rdi
callq 0xfb10b
leaq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0xf08ba
cmpb $0x0, 0x4(%rbp)
je 0x9f31d
movq 0xc8(%rsp), %rdx
movq 0x58(%rsp), %rcx
addq %rdx, %rcx
leaq 0x93081(%rip), %rsi     # 0x132243
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0xc8(%rsp), %rbp
addq 0x58(%rsp), %rbp
movq %rbp, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
subq %rbp, %rax
cmpq $0x8, %rax
jl 0x9f307
leaq 0x10(%rsp), %rsi
callq 0xeebeb
cmpq $0xff77, %rax           # imm = 0xFF77
jne 0x9f307
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xeebeb
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xeebeb
movq %rax, 0x28(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xeebeb
movq %rax, 0x20(%rsp)
movq 0x18(%rbx), %rdi
movl $0x6, %edx
movq %rbp, %rsi
movl $0x31, %ecx
callq 0xeb97d
movzwl %ax, %eax
cmpl 0x20(%rsp), %eax
jne 0x9f307
leaq 0x93079(%rip), %rsi     # 0x1322e5
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x40(%r14), %rbp
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0xea92a
movb $0x2, 0x41(%r14)
leaq 0x120(%rsp), %rsi
movl $0x40, %edx
movq %rbp, %rdi
movq %rsi, %rbp
xorl %ecx, %ecx
callq 0xeaf46
leaq 0x79ce5(%rip), %rsi     # 0x118fa7
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
leaq 0x93020(%rip), %rsi     # 0x1322f6
movq %rbx, %rdi
movq 0x20(%rsp), %rbp
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0x93030(%rip), %rsi     # 0x13231e
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpb $0x0, 0x40(%r14)
je 0x9f31d
movq %r14, %rax
addq $0x40, %rax
movups (%rax), %xmm0
movups %xmm0, 0x18(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %rbp
movq 0x18(%r12), %rdx
movq %r12, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0xef481
cmpl $0x0, 0xc0(%rsp)
je 0x9f407
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0x74ebb(%rip), %rsi     # 0x114221
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x9f391
leaq 0x92f34(%rip), %rsi     # 0x1322b0
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x8(%r14), %rdi
callq 0xf6753
movq 0x10(%r14), %rdi
callq 0xf6753
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xefaca
movq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0xefaca
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movq %rbp, %rdi
callq 0xf052b
movq %r12, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea50e
movq %r13, %rdi
callq 0xeb858
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0xeb865
movzwl %ax, %edx
movl %edx, 0x34(%r14)
leaq 0x7b018(%rip), %rsi     # 0x11a435
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x34(%r14), %eax
cmpl 0x30(%r14), %eax
je 0x9f391
leaq 0x92e2e(%rip), %rsi     # 0x13226a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x9f391