// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r15
movq $0x0, (%rsi)
leaq 0xc(%rsp), %rbx
movl $0x0, (%rbx)
movq %rbx, %rsi
callq 0xb1d8
movl %eax, %r14d
movq %r15, 0x30(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xb1d8
movl (%rbx), %r15d
leal (,%r15,8), %ecx
movl %ecx, (%rbx)
movq %rax, 0x38(%rsp)
incl %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x3190
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xb2d6
movq %rbp, 0x20(%rsp)
movq %r13, 0x28(%rsp)
leal (%r14,%r15,8), %eax
movl 0xc(%rsp), %r15d
movl %eax, 0x1c(%rsp)
cmpl %eax, %r15d
jne 0xb2e0
movl %r15d, %r14d
jmp 0xb3c5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xb3e6
movq 0x10(%rsp), %rbx
leaq -0x1000(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
movq %rbx, %r13
movq 0x30(%rsp), %r12
movslq %r15d, %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0xdf00
incl %r14d
testl %eax, %eax
je 0xb36a
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %edx
movl $0x11, %ecx
movl $0x20, %r8d
callq 0xdf40
movl 0x8(%rsp), %edi
callq 0xdfa1
addl $0x12, %r15d
movl %eax, %r14d
andl $0x1f, %r14d
leaq 0x2(%r14), %rdx
sarl $0x5, %eax
movl %eax, 0x8(%rsp)
movslq %eax, %rsi
addq %rbx, %rsi
movq %r13, %rdi
callq 0x3290
addq %r14, %rbp
addq $0x2, %rbp
movl %r15d, %r14d
movq 0x10(%rsp), %r13
movq %r13, %rdi
addq %rbp, %rdi
movb $0x0, (%r13,%rbp)
leaq 0x1(%rbp), %r15
movq %r12, %rsi
movl %r14d, %edx
movl $0x8, %ecx
movl $0x8, %r8d
callq 0xdf40
addl $0x8, %r14d
cmpq $0x1000, %rbp           # imm = 0x1000
movq 0x40(%rsp), %rax
leaq 0x1(%rax,%rbp), %rax
cmovgeq %rax, %rbx
addq %rbp, %r13
incq %r13
movq %r15, %rbp
movl %r14d, %r15d
cmpl 0x1c(%rsp), %r14d
jne 0xb2fb
movl %r14d, 0xc(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movslq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)