// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x50, %esi
callq 0x15b780
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xd, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x20(%rbp)
cmpq $0xff76, -0x20(%rbp)    # imm = 0xFF76
jne 0xea96e
movq -0x8(%rbp), %rdi
leaq 0xd3246(%rip), %rsi     # 0x1bdbad
callq 0x15e380
jmp 0xea9aa
cmpq $0xfffa, -0x20(%rbp)    # imm = 0xFFFA
jne 0xea991
movq -0x8(%rbp), %rdi
leaq 0xd3233(%rip), %rsi     # 0x1bdbb6
callq 0x15e380
movq -0x28(%rbp), %rax
movb $0x1, (%rax)
jmp 0xea9a8
movq -0x8(%rbp), %rdi
leaq 0xd322b(%rip), %rsi     # 0x1bdbc7
movb $0x0, %al
callq 0x15b0d0
jmp 0xeac83
jmp 0xea9aa
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0xea9d0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xec370
cmpl $0x0, %eax
jne 0xea9ce
jmp 0xeac83
jmp 0xea9ed
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xec550
cmpl $0x0, %eax
jne 0xea9eb
jmp 0xeac83
jmp 0xea9ed
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x30(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xd31a7(%rip), %rsi     # 0x1bdbdb
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x88(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0x1773f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movl $0x30, %esi
callq 0x15eac0
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x7e7fc(%rip), %rsi     # 0x1692d0
callq 0x169280
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x19140
leaq 0x8e46d(%rip), %rax     # 0x178f60
movq %rax, -0x138(%rbp)
leaq 0x8d4df(%rip), %rax     # 0x177fe0
movq %rax, -0x120(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x88(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x178cf0
movq -0x88(%rbp), %rdi
callq 0x167c30
cmpb $0x0, -0xe4(%rbp)
je 0xeabb4
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
movq -0x68(%rbp), %rcx
addq -0xe0(%rbp), %rcx
leaq 0xd3089(%rip), %rsi     # 0x1bdbfa
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq -0xe0(%rbp), %rdx
callq 0xec5f0
movq -0x28(%rbp), %rax
cmpb $0x0, 0x40(%rax)
je 0xeabb2
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x40(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x48(%rcx), %rcx
movq %rcx, 0x20(%rax)
jmp 0xeabb4
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x48(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
cmpl $0x0, -0xe8(%rbp)
je 0xeac22
movq -0x8(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x177360
movq -0x140(%rbp), %rdi
movq %rax, %rdx
leaq 0xb53e4(%rip), %rsi     # 0x19fffd
movb $0x0, %al
callq 0x15bfb0
jmp 0xeac83
movq -0x38(%rbp), %rdi
callq 0x15f340
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x28(%rbp), %rax
movl 0x34(%rax), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x34(%rax), %edx
leaq 0xbb43f(%rip), %rsi     # 0x1a6095
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movl 0x34(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x30(%rcx), %eax
je 0xeac81
movq -0x8(%rbp), %rdi
leaq 0xd2fa9(%rip), %rsi     # 0x1bdc21
movb $0x0, %al
callq 0x15bfb0
jmp 0xeac83
jmp 0xeac83
cmpq $0x0, -0x28(%rbp)
je 0xeacca
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0xec780
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15b820
movq -0x48(%rbp), %rdi
callq 0x1676a0
movq -0x40(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15d260
movq -0x38(%rbp), %rdi
callq 0x15f2e0
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x15b5a0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw (%rax,%rax)