// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, (%r15)
pushq $0x28
popq %rsi
callq 0xdecaf
movq %rax, %r14
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, (%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe4071
cmpl $0x5741434b, %eax       # imm = 0x5741434B
jne 0x9a02a
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0xe3fc4
movl %eax, 0x10(%r14)
leaq 0x8affc(%rip), %rsi     # 0x124fe1
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %r12
movq (%r13), %r13
addq %r13, %r12
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jle 0x9a046
leaq 0x8b0f8(%rip), %rsi     # 0x125110
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x9a21b
leaq 0x8b0d0(%rip), %rsi     # 0x125101
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
xorl %r15d, %r15d
jmp 0x9a21b
movq %r13, %rsi
callq 0xe3fa3
movq %rax, %rbp
movq 0x18(%rbx), %rdi
addq $0x2, %r13
movq %r13, %rsi
callq 0xe3fa3
movq %r14, %r13
addq $0x18, %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0xe0110
leaq 0x50(%rsp), %rbp
pushq $0x40
popq %rdx
movq %r13, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xe0644
leaq 0x71e25(%rip), %rsi     # 0x10beb7
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x4, 0x10(%rsp)
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x8(%r14)
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
subq %rsi, %rdx
movl (%r14), %ecx
movl %ecx, (%rsp)
pushq $0x1
popq %r9
movl $0xff, %ecx
movq %rax, %r8
callq 0xe4ced
movq 0x8(%r14), %rdi
callq 0xeb877
leaq 0x94977(%rip), %rsi     # 0x12ea5e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xdfd55
movb $0x1, 0x8(%r15)
movq %r12, 0x10(%rsp)
leaq 0x8ae2a(%rip), %rsi     # 0x124f40
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, 0x18(%rsp)
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r12
movq %rax, %rdi
callq 0xe589c
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 0xee7ee
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)
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, %r13
leaq 0x4c119(%rip), %rsi     # 0xe62c1
movq %r12, %rdi
movq %rax, %rdx
callq 0xe629a
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x24(%rsp), %r8
callq 0xf644c
movq %r12, %rdi
callq 0xe58e8
movq %r13, %rdi
callq 0xe0e95
movzwl %ax, %edx
movl %edx, 0x14(%r14)
leaq 0x7315c(%rip), %rsi     # 0x10d345
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x14(%r14), %eax
cmpl 0x10(%r14), %eax
je 0x9a20e
leaq 0x8ad7a(%rip), %rsi     # 0x124f7e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %r13, %rdi
callq 0xe0e8d
movq 0x18(%rsp), %r15
movq %r12, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdfd24
movq 0x8(%r14), %rdi
callq 0xeaf3c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq