// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/dms.c
// Function: quicklz77_codec_addbuf
static void quicklz77_codec_addbuf(struct de_dfilter_ctx *dfctx,
	const u8 *buf, i64 buf_len)
{
	struct medium_ctx *mctx = (struct medium_ctx *)dfctx->codec_private;
	struct medium_state_machine *mdst = &mctx->mdst;
	i64 bufpos = 0;
	UI n;
	UI length;
	UI ocode, lcode;

	if(dfctx->finished_flag || mctx->errflag) {
		goto done;
	}

	while(1) {
		if(medium_have_enough_output(mctx)) {
			dfctx->finished_flag = 1;
			goto done;
		}

		// Top off the bitbuf, if possible. 32 is an arbitrary number that's
		// large enough for this format.
		while(bufpos<buf_len && mctx->bbll.nbits_in_bitbuf<32) {
			de_bitbuf_lowlevel_add_byte(&mctx->bbll, buf[bufpos++]);
		}

		if(mdst->state==MEDLZST_WAITING_FOR_OCODE1) goto read_ocode1;

		// Minimum useful number of bits is 9.
		if(mctx->bbll.nbits_in_bitbuf < 9) goto done;

		n = (UI)de_bitbuf_lowlevel_get_bits(&mctx->bbll, 1);
		if(n) { // literal byte
			u8 b;

			b = (u8)de_bitbuf_lowlevel_get_bits(&mctx->bbll, 8);
			de_lz77buffer_add_literal_byte(mctx->ringbuf, (u8)b);
			continue;
		}

	read_ocode1:
		if(mctx->bbll.nbits_in_bitbuf < 10) {
			mdst->state = MEDLZST_WAITING_FOR_OCODE1;
			goto done;
		}

		lcode = (UI)de_bitbuf_lowlevel_get_bits(&mctx->bbll, 2);
		ocode = (UI)de_bitbuf_lowlevel_get_bits(&mctx->bbll, 8);
		length = lcode + 2;
		de_lz77buffer_copy_from_hist(mctx->ringbuf, mctx->ringbuf->curpos - 1 - ocode, length);
		mdst->state = MEDLZST_NEUTRAL;
	}

done:
	if(!dfctx->finished_flag && !mctx->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(dfctx->c, mctx->dres, mctx->modname);
			mctx->errflag = 1;
		}
	}
}

// Assembly:
cmpb $0x0, 0x20(%rdi)
je 0x49914
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq 0x28(%rdi), %rbp
cmpl $0x0, 0x20(%rbp)
je 0x49934
xorl %r14d, %r14d
jmp 0x49a0c
movq %rsi, %r15
movq %rdi, (%rsp)
leaq 0x38(%rbp), %r12
xorl %r14d, %r14d
movq 0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x4995a
movq 0x28(%rbp), %rcx
cmpq 0x10(%rax), %rcx
jge 0x49a36
cmpq %rbx, %r14
jge 0x4997f
movl 0x3c(%rbp), %eax
cmpl $0x1f, %eax
ja 0x49982
movzbl (%r15,%r14), %esi
incq %r14
movq %r12, %rdi
callq 0xf1b5e
cmpq %r14, %rbx
jne 0x4995f
movq %rbx, %r14
movl 0x3c(%rbp), %eax
cmpl $0x1, 0x48(%rbp)
je 0x499bc
cmpl $0x9, %eax
jb 0x49a08
movq %r12, %rdi
movl $0x1, %esi
callq 0xf1b93
testl %eax, %eax
je 0x499b9
movq %r12, %rdi
movl $0x8, %esi
callq 0xf1b93
movq 0x30(%rbp), %rdi
movzbl %al, %esi
callq 0xfae4e
jmp 0x49942
movl 0x3c(%rbp), %eax
cmpl $0x9, %eax
jbe 0x49a01
movq %r12, %rdi
movl $0x2, %esi
callq 0xf1b93
movq %rax, %r13
movq %r12, %rdi
movl $0x8, %esi
callq 0xf1b93
addl $0x2, %r13d
movq 0x30(%rbp), %rdi
notl %eax
addl 0x10(%rdi), %eax
movl %eax, %esi
movl %r13d, %edx
callq 0xfae7b
movl $0x0, 0x48(%rbp)
jmp 0x49942
movl $0x1, 0x48(%rbp)
movq (%rsp), %rdi
cmpb $0x0, 0x20(%rdi)
jne 0x49a3e
cmpq %rbx, %r14
jge 0x49a3e
cmpl $0x0, 0x20(%rbp)
jne 0x49a3e
movq (%rdi), %rdi
movq 0x8(%rbp), %rdx
movq 0x18(%rbp), %rsi
callq 0xfa311
movl $0x1, 0x20(%rbp)
jmp 0x49a3e
movq (%rsp), %rax
movb $0x1, 0x20(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq