// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, (%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef34e
cmpl $0x5741434b, %eax       # imm = 0x5741434B
jne 0xa05fb
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xef1ed
movl %eax, 0x10(%r14)
leaq 0x91993(%rip), %rsi     # 0x131f49
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
movq %rax, %r12
movq (%r13), %r13
addq %r13, %r12
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jle 0xa0617
leaq 0x91a8f(%rip), %rsi     # 0x132078
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xa07f8
leaq 0x91a67(%rip), %rsi     # 0x132069
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
xorl %r15d, %r15d
jmp 0xa07f8
movq %r13, %rsi
callq 0xef1ca
movq %rax, %rbp
movq 0x18(%rbx), %rdi
addq $0x2, %r13
movq %r13, %rsi
callq 0xef1ca
movq %r14, %r13
addq $0x18, %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0xeae33
leaq 0x50(%rsp), %rbp
movl $0x40, %edx
movq %r13, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
leaq 0x78822(%rip), %rsi     # 0x118e87
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x4, 0x10(%rsp)
movq %rbx, %rdi
callq 0xf6870
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 0xf0203
movq 0x8(%r14), %rdi
callq 0xf7557
leaq 0x9b318(%rip), %rsi     # 0x13b9d4
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xea9e4
movb $0x1, 0x8(%r15)
movq %r12, 0x10(%rsp)
leaq 0x917bd(%rip), %rsi     # 0x131ea8
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, 0x18(%rsp)
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r12
movq %rax, %rdi
callq 0xf0e3f
movq 0x10(%rsp), %r13
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
movl $0x0, 0x10(%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 0xfa6e0
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 0xeba56
movq %rax, %r13
leaq 0x512cc(%rip), %rsi     # 0xf1a51
movq %r12, %rdi
movq %rax, %rdx
callq 0xf1a12
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x102cf0
movq %r12, %rdi
callq 0xf0ea4
movq %r13, %rdi
callq 0xebe2a
movzwl %ax, %edx
movl %edx, 0x14(%r14)
leaq 0x79b4f(%rip), %rsi     # 0x11a315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x14(%r14), %eax
cmpl 0x10(%r14), %eax
je 0xa07eb
leaq 0x91705(%rip), %rsi     # 0x131ee6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %r13, %rdi
callq 0xebe1d
movq 0x18(%rsp), %r15
movq %r12, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea9b3
movq 0x8(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq