// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xf690
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xf690
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
shll $0x3, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x3170
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xf7b2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf8eb
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x40(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
je 0xf8ce
movq -0x10(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0x143b0
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0xf876
movl $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rsi
movl -0x48(%rbp), %edx
leaq -0x58(%rbp), %rdi
movl $0x11, %ecx
movl $0x20, %r8d
callq 0x14470
movl -0x58(%rbp), %edi
callq 0x14520
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
addl $0x11, %eax
movl %eax, -0x48(%rbp)
movl -0x58(%rbp), %eax
andl $0x1f, %eax
addl $0x2, %eax
movl %eax, -0x50(%rbp)
movl -0x58(%rbp), %eax
sarl $0x5, %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x58(%rbp), %rax
addq %rax, %rsi
movslq -0x50(%rbp), %rdx
callq 0x3270
movl -0x50(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xf87d
movl $0x1, -0x50(%rbp)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x30(%rbp), %rdi
movq %rdi, %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rsi
movl -0x48(%rbp), %edx
movl $0x8, %r8d
movl %r8d, %ecx
callq 0x14470
movl -0x48(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0xf8c9
movq -0x30(%rbp), %rax
addq $-0x1000, %rax          # imm = 0xF000
movq %rax, -0x28(%rbp)
jmp 0xf7cc
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movslq -0x4c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop