// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/../foreign/lzhuf.h
// Function: lzhuf_Decode_continue
static void lzhuf_Decode_continue(struct lzahuf_ctx *cctx, const u8 *buf, i64 buf_len, int flush)
{
	UI i, j, c;
	i64 bufpos = 0;
	char pos_descr[32];

	pos_descr[0] = '\0';
	if(cctx->dfctx->finished_flag) goto done;

	while(1) {
		if(cctx->errflag) goto done;
		if(lzah_have_enough_output(cctx)) {
			goto done;
		}

		// We're relying on the assumption that a compression instruction can
		// never be more than 57 bits in size.
		// The Huffman-encoded "character" maxes out, I think, at around 15 or
		// 16 bits -- this follows indirectly from MAX_FREQ, which reduces the
		// tree depth perdiodically.
		// For a "match" instruction, an 8-bit code is then read.
		// Then, some additional bits are read -- the most possible for the
		// supported formats is 8, for DMS-Deep.
		// So, about 16+8+8 = 32 bits should be sufficient.

		// Top off the bitbuf, if possible.
		while(bufpos<buf_len && cctx->bbll.nbits_in_bitbuf<=(64-8)) {
			de_bitbuf_lowlevel_add_byte(&cctx->bbll, buf[bufpos++]);
			cctx->total_nbytes_processed++;
		}

		if(!flush && cctx->bbll.nbits_in_bitbuf<=(64-8)) {
			// Wait for more data before trying to continue
			goto done;
		}

		if(cctx->c->debug_level>=4) {
			de_bitbuf_describe_curpos(&cctx->bbll,
				cctx->dfctx->input_file_offset+cctx->total_nbytes_processed,
				pos_descr, sizeof(pos_descr));
		}

		c = lzhuf_DecodeChar(cctx);
		if(cctx->errflag) goto done;

		if(c==256 && cctx->num_special_codes>=1) {
			if(cctx->c->debug_level>=4) {
				de_dbg(cctx->c, "special @%s =%u", pos_descr, c);
			}
			cctx->dfctx->finished_flag = 1;
			goto done;
		}
		if (c < 256) {
			if(cctx->c->debug_level>=4) {
				de_dbg(cctx->c, "lit @%s =%u", pos_descr, c);
			}
			de_lz77buffer_add_literal_byte(cctx->ringbuf, (u8)c);
		}
		else {
			// i is the distance back
			i = lzhuf_DecodePosition(cctx);
			if(cctx->errflag) goto done;

			// j is the match length
			j = c - cctx->match_length_bias;

			if(cctx->c->debug_level>=4) {
				de_dbg(cctx->c, "match @%s dist=%u len=%u", pos_descr, i+1, j);
			}

			de_lz77buffer_copy_from_hist(cctx->ringbuf,
				(UI)(cctx->ringbuf->curpos - (UI)i - 1), j);
		}
	}

done:
	if(!cctx->dfctx->finished_flag && !cctx->errflag) {
		if(bufpos<buf_len) {
			// It shouldn't be possible to get here. If we do, it means some input
			// bytes will be lost.
			de_dfilter_set_generic_error(cctx->dfctx->c, cctx->dres, cctx->modname);
			cctx->errflag = 1;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x30(%rbp)
movb $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
cmpb $0x0, 0x20(%rax)
je 0x18b9c6
jmp 0x18bbba
jmp 0x18b9c8
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x18b9d7
jmp 0x18bbba
movq -0x8(%rbp), %rdi
callq 0x18bc10
cmpl $0x0, %eax
je 0x18b9ea
jmp 0x18bbba
jmp 0x18b9ec
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x51(%rbp)
jge 0x18ba09
movq -0x8(%rbp), %rax
cmpl $0x38, 0x74(%rax)
setbe %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x18ba12
jmp 0x18ba48
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %esi
callq 0x16a230
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x58(%rax)
jmp 0x18b9ec
cmpl $0x0, -0x1c(%rbp)
jne 0x18ba5d
movq -0x8(%rbp), %rax
cmpl $0x38, 0x74(%rax)
ja 0x18ba5d
jmp 0x18bbba
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x4, (%rax)
jl 0x18ba93
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
addq 0x58(%rax), %rsi
leaq -0x50(%rbp), %rdx
movl $0x20, %ecx
callq 0x16a4a0
movq -0x8(%rbp), %rdi
callq 0x18bc60
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x18baae
jmp 0x18bbba
cmpl $0x100, -0x28(%rbp)     # imm = 0x100
jne 0x18bafa
movq -0x8(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jb 0x18bafa
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x4, (%rax)
jl 0x18bae9
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x50(%rbp), %rdx
movl -0x28(%rbp), %ecx
leaq 0x4c11c(%rip), %rsi     # 0x1d7bfe
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movb $0x1, 0x20(%rax)
jmp 0x18bbba
cmpl $0x100, -0x28(%rbp)     # imm = 0x100
jae 0x18bb40
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x4, (%rax)
jl 0x18bb2b
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x50(%rbp), %rdx
movl -0x28(%rbp), %ecx
leaq 0x4c0ea(%rip), %rsi     # 0x1d7c0e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movl -0x28(%rbp), %eax
movzbl %al, %esi
callq 0x178880
jmp 0x18bbb5
movq -0x8(%rbp), %rdi
callq 0x18bd00
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x18bb58
jmp 0x18bbba
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
subl 0x34(%rcx), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x4, (%rax)
jl 0x18bb94
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x50(%rbp), %rdx
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movl -0x24(%rbp), %r8d
leaq 0x4c08d(%rip), %rsi     # 0x1d7c1a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movl 0x10(%rax), %esi
subl -0x20(%rbp), %esi
subl $0x1, %esi
movl -0x24(%rbp), %edx
callq 0x1788e0
jmp 0x18b9c8
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
cmpb $0x0, 0x20(%rax)
jne 0x18bc09
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x18bc09
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x18bc07
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x177560
movq -0x8(%rbp), %rax
movl $0x1, 0x54(%rax)
jmp 0x18bc09
addq $0x60, %rsp
popq %rbp
retq
nop