// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/lbr.c
// Function: de_run_zsq
static void de_run_zsq(deark *c, de_module_params *mparams)
{
	struct zsq_ctx *zsqctx = NULL;
	i64 pos = 0;
	i64 hdr_len;
	i64 hdr_endpos;
	u32 id;
	dbuf *outf = NULL;
	de_finfo *fi = NULL;

	zsqctx = de_malloc(c, sizeof(struct zsq_ctx));
	zsqctx->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);

	id = (u32)de_getu32be_p(&pos);
	if(id != CODE_WACK) {
		de_err(c, "Not a ZSQ file");
		goto done;
	}

	fi = de_finfo_create(c);

	zsqctx->checksum_reported = (u32)de_getu16le_p(&pos);
	de_dbg(c, "checksum (reported): %u", (UI)zsqctx->checksum_reported);

	hdr_len = de_getu16le_p(&pos);
	hdr_endpos = pos + hdr_len;
	if(hdr_endpos > c->infile->len) {
		de_err(c, "Bad header length");
		goto done;
	}

	zsq_read_timestamp(c, zsqctx, pos);
	pos += 4;

	zsqctx->fn = ucstring_create(c);
	dbuf_read_to_ucstring_n(c->infile, pos, hdr_endpos-pos, 255, zsqctx->fn,
		DE_CONVFLAG_STOP_AT_NUL, zsqctx->input_encoding);
	de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(zsqctx->fn));

	de_finfo_set_name_from_ucstring(c, fi, zsqctx->fn, 0);
	fi->original_filename_flag = 1;

	pos = hdr_endpos;
	de_dbg(c, "compressed data at %"I64_FMT, pos);

	outf = dbuf_create_output_file(c, NULL, fi, 0);
	dbuf_enable_wbuffer(outf);

	do_zsq_decompress(c, zsqctx, pos, outf);

done:
	dbuf_close(outf);
	de_finfo_destroy(c, fi);
	if(zsqctx) {
		ucstring_destroy(zsqctx->fn);
		de_free(c, zsqctx);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x10(%rsp), %r15
movq $0x0, (%r15)
movl $0x28, %esi
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, (%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeed31
cmpl $0x5741434b, %eax       # imm = 0x5741434B
jne 0x9fd53
movq %rbx, %rdi
callq 0xea504
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xeebeb
movl %eax, 0x10(%r14)
leaq 0x925bf(%rip), %rsi     # 0x1322cd
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
movq %rax, %r12
movq (%r13), %r13
addq %r13, %r12
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jle 0x9fd6f
leaq 0x926bb(%rip), %rsi     # 0x1323fc
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x9ff4a
leaq 0x92693(%rip), %rsi     # 0x1323ed
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
xorl %r15d, %r15d
jmp 0x9ff4a
movq %r13, %rsi
callq 0xeebc8
movq %rax, %rbp
movq 0x18(%rbx), %rdi
addq $0x2, %r13
movq %r13, %rsi
callq 0xeebc8
movq %r14, %r13
addq $0x18, %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0xea92a
leaq 0x50(%rsp), %rbp
movl $0x40, %edx
movq %r13, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xeaf46
leaq 0x791ea(%rip), %rsi     # 0x118fa7
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x4, 0x10(%rsp)
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x8(%r14)
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
subq %rsi, %rdx
movl (%r14), %ecx
movl %ecx, (%rsp)
movl $0xff, %ecx
movq %rax, %r8
movl $0x1, %r9d
callq 0xefc2a
movq 0x8(%r14), %rdi
callq 0xf70f6
leaq 0x9bf3a(%rip), %rsi     # 0x13bd4e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xea53f
movb $0x1, 0x8(%r15)
movq %r12, 0x10(%rsp)
leaq 0x923e9(%rip), %rsi     # 0x13222c
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, 0x18(%rsp)
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r12
movq %rax, %rdi
callq 0xf0855
movq 0x10(%rsp), %r13
xorps %xmm0, %xmm0
leaq 0x24(%rsp), %rax
movups %xmm0, 0x4(%rax)
movl $0x7, (%rax)
leaq 0xb8(%rsp), %rbp
leaq 0x38(%rsp), %r15
leaq 0x50(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq %r13, 0x8(%rbp)
movq 0x18(%rax), %rax
subq %r13, %rax
movq %rax, 0x10(%rbp)
movq %r12, (%r15)
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeb499
movq %rax, %r13
leaq 0x5157a(%rip), %rsi     # 0xf1451
movq %r12, %rdi
movq %rax, %rdx
callq 0xf1412
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x24(%rsp), %r8
callq 0x102400
movq %r12, %rdi
callq 0xf08ba
movq %r13, %rdi
callq 0xeb865
movzwl %ax, %edx
movl %edx, 0x14(%r14)
leaq 0x7a51d(%rip), %rsi     # 0x11a435
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x14(%r14), %eax
cmpl 0x10(%r14), %eax
je 0x9ff3d
leaq 0x92337(%rip), %rsi     # 0x13226a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %r13, %rdi
callq 0xeb858
movq 0x18(%rsp), %r15
movq %r12, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea50e
movq 0x8(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq