// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-lzw.c
// Function: delzw_unixcompress_end_bitgroup
static void delzw_unixcompress_end_bitgroup(delzwctx *dc)
{
	i64 ncodes_alloc;
	i64 nbits_left_to_skip;

	// The Unix 'compress' format has a quirk.
	// The codes are written 8 at a time, with all 8 having the same codesize.
	// The codesize cannot change in the middle of a block of 8. If it needs to,
	// the remainder of the block is unused padding, which we must skip over.
	// This is relevant when we encounter a clear code. It is also potentially
	// relevant when the codesize is auto-incremented. But except possibly for
	// the first group of codes (the 9-bit codes), the natural number of codes of
	// a given size is always (?) a power of 2, and a multiple of 8. So, usually
	// no padding is present at the auto-increment position.
	// As it happens, when code 256 is used as the clear code, it reduces the
	// natural number of 9-bit codes from 257 to 256, and since 256 is a multiple
	// of 8, still no padding is present.
	// But "v2" format does not use a clear code, and AFAICT it does have padding
	// after the 9-bit codes.

	ncodes_alloc = ((dc->ncodes_in_this_bitgroup + 7)/8)*8;
	nbits_left_to_skip = (ncodes_alloc - dc->ncodes_in_this_bitgroup) * dc->curr_codesize;

	// My thinking:
	// Each "bitgroup" has a whole number of bytes.
	// When we get here, we've just read a code, so the bitreader's buffer can have no more than
	// 7 bits in it.
	// All of the bits in it will be part of the "bits to skip". After accounting for them, we'll
	// be left with a whole number of *bytes* left to skip, which always start on a byte boundary
	// in the input stream.
	// So, whenever the main input loop needs to skip anything, it will be a whole byte, and the
	// bitreader's buffer will be empty. That's good; it makes it easier to deal with this
	// padding.

	if(nbits_left_to_skip>0) {
		delzw_debugmsg(dc, 2, "padding bits: %d", (int)nbits_left_to_skip);
	}

	dc->ncodes_in_this_bitgroup = 0;
	if(dc->bbll.nbits_in_bitbuf>7 || dc->bbll.nbits_in_bitbuf>nbits_left_to_skip) {
		delzw_set_error(dc, DELZW_ERRCODE_INTERNAL_ERROR, NULL);
		return;
	}

	nbits_left_to_skip -= dc->bbll.nbits_in_bitbuf;
	if(nbits_left_to_skip%8 != 0) {
		delzw_set_error(dc, DELZW_ERRCODE_INTERNAL_ERROR, NULL);
		return;
	}

	de_bitbuf_lowlevel_empty(&dc->bbll);
	dc->nbytes_left_to_skip = nbits_left_to_skip/8;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
shlq $0x3, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq 0x78(%rcx), %rax
movq -0x8(%rbp), %rcx
movl 0x90(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jle 0x18634c
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %ecx
movl $0x2, %esi
leaq 0x514b0(%rip), %rdx     # 0x1d77f5
movb $0x0, %al
callq 0x1848d0
movq -0x8(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x8(%rbp), %rax
cmpl $0x7, 0xbc(%rax)
ja 0x186375
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %eax
cmpq -0x18(%rbp), %rax
jle 0x186389
movq -0x8(%rbp), %rdi
movl $0xa, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x185850
jmp 0x1863f4
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x8, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x1863c8
movq -0x8(%rbp), %rdi
movl $0xa, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x185850
jmp 0x1863f4
movq -0x8(%rbp), %rdi
addq $0xb8, %rdi
callq 0x16a360
movq -0x18(%rbp), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x80(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)