// File: /workspace/github_c_makefile_star2_O2/hoobaa[P]ficl/lzuncompress.c
// Function: ficlLzUncompress
int ficlLzUncompress(const unsigned char *compressed, unsigned char **uncompressed_p, size_t *uncompressedSize_p)
	{
	unsigned char *window;
	unsigned char *buffer;
	unsigned char *uncompressed;
	unsigned char *initialWindow;

	int bitstreamLength;
	int inputPosition;
	int uncompressedSize;

	*uncompressed_p = NULL;

	inputPosition = 0;
	bitstreamLength = ficlLzDecodeHeaderField(compressed, &inputPosition);
	uncompressedSize = ficlLzDecodeHeaderField(compressed, &inputPosition);

	inputPosition <<= 3; /* same as * 8 */

	bitstreamLength += inputPosition;

	uncompressed = (unsigned char *)calloc(uncompressedSize + 1, 1);
	if (uncompressed == NULL)
		return -1;
	window = buffer = uncompressed;
	initialWindow = buffer + FICL_LZ_WINDOW_SIZE;

	while (inputPosition != bitstreamLength)
		{
		int length;
		int token = ficlBitGet(compressed, inputPosition);
		inputPosition++;

		if (token)
			{
			/* phrase token */
			int offset = 0;
			ficlBitGetString((unsigned char *)&offset, compressed, inputPosition, FICL_LZ_PHRASE_BITS - (1 + FICL_LZ_NEXT_BITS), sizeof(offset) * 8);
			offset = ficlNetworkUnsigned32(offset);
			inputPosition += FICL_LZ_PHRASE_BITS - (1 + FICL_LZ_NEXT_BITS);

			length = (offset & ((1 << FICL_LZ_LENGTH_BITS) - 1)) + FICL_LZ_MINIMUM_USEFUL_MATCH;
			offset >>= FICL_LZ_LENGTH_BITS;

			memmove(buffer, window + offset, length);
			buffer += length;
			length++;
			}
		else
			length = 1;

		/* symbol token */
		*buffer = 0;
		ficlBitGetString(buffer++, compressed, inputPosition, FICL_LZ_NEXT_BITS, sizeof(*buffer) * 8);
		inputPosition += FICL_LZ_NEXT_BITS;
		if (buffer > initialWindow)
			window = buffer - FICL_LZ_WINDOW_SIZE;
		}

	*uncompressed_p = uncompressed;
	*uncompressedSize_p = uncompressedSize;

	return 0;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
andq $0x0, (%rsi)
leaq 0x54(%rsp), %r14
andl $0x0, (%r14)
movq %r14, %rsi
callq 0xaa84
movl %eax, %ebx
movq %r13, %rdi
movq %r14, %rsi
callq 0xaa84
movl (%r14), %r14d
movq %rax, 0x30(%rsp)
incl %eax
movslq %eax, %rdi
pushq $0x1
popq %rsi
callq 0x3190
testq %rax, %rax
je 0xac5b
movq %r13, 0x40(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movl %r14d, %r15d
shll $0x3, %r15d
leal (%rbx,%r14,8), %ecx
movl %ecx, 0x1c(%rsp)
leaq -0x1000(%rax), %rcx
movq %rcx, 0x38(%rsp)
xorl %r12d, %r12d
movq %rax, 0x10(%rsp)
movq %rax, %r13
movq 0x40(%rsp), %rbp
cmpl 0x1c(%rsp), %r15d
je 0xac3d
movslq %r15d, %rsi
movq %rbp, %rdi
callq 0xd47c
leal 0x1(%r15), %ebx
testl %eax, %eax
je 0xabf7
movq 0x10(%rsp), %r14
leaq (%r14,%r12), %rax
movq %rax, 0x48(%rsp)
andl $0x0, 0xc(%rsp)
leaq 0xc(%rsp), %rdi
movq %rbp, %rsi
movl %ebx, %edx
pushq $0x11
popq %rcx
pushq $0x20
popq %r8
callq 0xd4bc
movl 0xc(%rsp), %edi
callq 0xd514
addl $0x12, %r15d
movl %eax, %ebx
andl $0x1f, %ebx
leaq 0x2(%rbx), %rdx
sarl $0x5, %eax
movslq %eax, %rsi
addq %r13, %rsi
movq 0x48(%rsp), %rdi
callq 0x3290
addq %rbx, %r12
addq $0x2, %r12
movl %r15d, %ebx
jmp 0xabfc
movq 0x10(%rsp), %r14
leaq (%r14,%r12), %rdi
movb $0x0, (%r14,%r12)
leaq 0x1(%r12), %r14
movq %rbp, %rsi
movl %ebx, %edx
pushq $0x8
popq %rcx
movl %ecx, %r8d
callq 0xd4bc
addl $0x8, %ebx
cmpq $0x1000, %r12           # imm = 0x1000
movq 0x38(%rsp), %rax
leaq 0x1(%rax,%r12), %rax
cmovgeq %rax, %r13
movl %ebx, %r15d
movq %r14, %r12
jmp 0xab7b
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movslq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0xac5e
pushq $-0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)