// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mscompress.c
// Function: mslzh_decompress_main
static void mslzh_decompress_main(struct mslzh_context *lzhctx)
{
	MSLZH_VALUE_TYPE v;
	struct mslzh_tree *curr_matchlen_table;
	char tmps[32];

	de_dbg(lzhctx->c, "LZ data at %s",
		de_bitreader_describe_curpos(&lzhctx->bitrd, tmps, sizeof(tmps)));

	curr_matchlen_table = &lzhctx->htree[MSLZH_TREE_IDX_MATCHLEN];

	while(1) {
		if(mslzh_have_enough_output(lzhctx)) goto unc_done;
		if(lzhctx->bitrd.eof_flag) goto unc_done;

		v = mslzh_getnextcode(lzhctx, curr_matchlen_table);
		if(lzhctx->bitrd.eof_flag) goto unc_done;

		if(v!=0) { // match
			UI matchlen;
			UI matchpos;
			UI x, y;

			matchlen = v + 2;

			x = mslzh_getnextcode(lzhctx, &lzhctx->htree[MSLZH_TREE_IDX_OFFSET]);
			y = mslzh_getbits(lzhctx, 6);
			if(lzhctx->bitrd.eof_flag) goto unc_done;

			// This may underflow -- that's ok.
			matchpos = lzhctx->ringbuf->curpos - (x<<6 | y);

			curr_matchlen_table = &lzhctx->htree[MSLZH_TREE_IDX_MATCHLEN];

			de_lz77buffer_copy_from_hist(lzhctx->ringbuf, matchpos, matchlen);
		}
		else { // run of literals
			UI x;
			UI count;
			UI i;

			x = mslzh_getnextcode(lzhctx, &lzhctx->htree[MSLZH_TREE_IDX_LITLEN]);
			if(lzhctx->bitrd.eof_flag) goto unc_done;
			if(x != 31) {
				curr_matchlen_table = &lzhctx->htree[MSLZH_TREE_IDX_MATCHLEN2];
			}
			// read & emit x+1 literals using LITERAL table
			count = x+1;
			for(i=0; i<count; i++) {
				v = mslzh_getnextcode(lzhctx, &lzhctx->htree[MSLZH_TREE_IDX_LITERAL]);
				if(lzhctx->bitrd.eof_flag) goto unc_done;
				de_lz77buffer_add_literal_byte(lzhctx->ringbuf, (u8)v);
			}
		}
	}

unc_done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
leaq -0x40(%rbp), %rsi
movl $0x20, %edx
callq 0x16a540
movq -0x68(%rbp), %rdi
movq %rax, %rdx
leaq 0xd9c75(%rip), %rsi     # 0x1bcdd0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xe3580
cmpl $0x0, %eax
je 0xe3181
jmp 0xe32da
movq -0x8(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xe3190
jmp 0xe32da
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xe35d0
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xe31af
jmp 0xe32da
movzbl -0x9(%rbp), %eax
cmpl $0x0, %eax
je 0xe323e
movzbl -0x9(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x68, %rsi
addq $0x48, %rsi
callq 0xe35d0
movzbl %al, %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movl $0x6, %esi
callq 0xe2e30
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xe3201
jmp 0xe32da
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movl 0x10(%rax), %eax
movl -0x4c(%rbp), %ecx
shll $0x6, %ecx
orl -0x50(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movl -0x48(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x1788e0
jmp 0xe32d5
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x68, %rsi
addq $0x30, %rsi
callq 0xe35d0
movzbl %al, %eax
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xe3265
jmp 0xe32da
cmpl $0x1f, -0x54(%rbp)
je 0xe327b
movq -0x8(%rbp), %rax
addq $0x68, %rax
addq $0x18, %rax
movq %rax, -0x18(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x58(%rbp), %eax
jae 0xe32d3
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x68, %rsi
addq $0x60, %rsi
callq 0xe35d0
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xe32b7
jmp 0xe32da
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movzbl -0x9(%rbp), %esi
callq 0x178880
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe328b
jmp 0xe32d5
jmp 0xe316e
addq $0x70, %rsp
popq %rbp
retq