// File: /workspace/github_cpp_makefile_star2_O2/splatlab[P]debgr/threadsafe-gqf/gqf.c
// Function: decode_counter(quotient_filter const*, unsigned long, unsigned long*, unsigned long*)
static inline uint64_t decode_counter(const QF *qf, uint64_t index, uint64_t
																			*remainder, uint64_t *count)
{
	uint64_t base;
	uint64_t rem;
	uint64_t cnt;
	uint64_t digit;
	uint64_t end;

	*remainder = rem = get_slot(qf, index);

	if (is_runend(qf, index)) { /* Entire run is "0" */
		*count = 1; 
		return index;
	}

	digit = get_slot(qf, index + 1);

	if (is_runend(qf, index + 1)) {
		*count = digit == rem ? 2 : 1;
		return index + (digit == rem ? 1 : 0);
	}

	if (rem > 0 && digit >= rem) {
		*count = digit == rem ? 2 : 1;
		return index + (digit == rem ? 1 : 0);
	}

	if (rem > 0 && digit == 0 && get_slot(qf, index + 2) == rem) {
		*count = 3;
		return index + 2;
	}

	if (rem == 0 && digit == 0) {
		if (get_slot(qf, index + 2) == 0) {
			*count = 3;
			return index + 2;
		} else {
			*count = 2;
			return index + 1;
		}
	}

	cnt = 0;
	base = (1ULL << qf->metadata->bits_per_slot) - (rem ? 2 : 1);

	end = index + 1;
	while (digit != rem && !is_runend(qf, end)) {
		if (digit > rem)
			digit--;
		if (digit && rem)
			digit--;
		cnt = cnt * base + digit;

		end++;
		digit = get_slot(qf, end);
	}

	if (rem) {
		*count = cnt + 3;
		return end;
	}

	if (is_runend(qf, end) || get_slot(qf, end + 1) != 0) {
		*count = 1;
		return index;
	}

	*count = cnt + 4;
	return end + 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r15
callq 0xf891
movq %rax, %r12
movq %rax, (%rbx)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xef61
testl %eax, %eax
je 0xedc2
movq $0x1, (%r14)
jmp 0xedff
leaq 0x1(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xf891
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0xef61
testl %eax, %eax
jne 0xeded
leaq -0x1(%r12), %rax
cmpq %r13, %rax
jae 0xee11
xorl %eax, %eax
cmpq %r12, %r13
sete %al
leaq 0x1(%rax), %rcx
movq %rcx, (%r14)
addq %rax, %rbp
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, (%rsp)
testq %r12, %r12
sete %al
testq %r13, %r13
setne %cl
orb %al, %cl
jne 0xee49
leaq 0x2(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0xf891
cmpq %r12, %rax
jne 0xee49
movq (%rsp), %rax
movq $0x3, (%rax)
movq %r14, %rbp
jmp 0xedff
movq %r13, %rax
orq %r12, %rax
je 0xeee6
movq 0x8(%r15), %rax
movb 0x38(%rax), %cl
pushq $0x1
popq %rax
shlq %cl, %rax
xorl %r14d, %r14d
cmpq $0x1, %r12
movl $0x0, %ecx
adcq $-0x2, %rcx
addq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq %rbp, 0x8(%rsp)
leaq 0x2(%rbp), %rbx
movq %rbx, %rbp
decq %rbx
cmpq %r12, %r13
je 0xeed4
movq %r15, %rdi
movq %rbx, %rsi
callq 0xef61
testl %eax, %eax
jne 0xeed4
testq %r12, %r12
setne %al
cmpq %r13, %r12
sbbq $0x0, %r13
setne %cl
andb %al, %cl
imulq 0x10(%rsp), %r14
addq %r13, %r14
movzbl %cl, %eax
subq %rax, %r14
movq %r15, %rdi
movq %rbp, %rbx
movq %rbp, %rsi
callq 0xf891
movq %rax, %r13
incq %rbx
jmp 0xee83
testq %r12, %r12
je 0xef0d
addq $0x3, %r14
movq (%rsp), %rax
movq %r14, (%rax)
jmp 0xef05
addq $0x2, %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0xf891
testq %rax, %rax
je 0xef41
movq (%rsp), %rax
movq $0x2, (%rax)
movq %rbx, %rbp
jmp 0xedff
movq %r15, %rdi
movq %rbx, %rsi
callq 0xef61
testl %eax, %eax
jne 0xef2c
movq %r15, %rdi
movq %rbp, %rsi
callq 0xf891
testq %rax, %rax
je 0xef51
movq (%rsp), %rax
movq $0x1, (%rax)
movq 0x8(%rsp), %rbp
jmp 0xedff
movq (%rsp), %rax
movq $0x3, (%rax)
jmp 0xedff
addq $0x4, %r14
movq (%rsp), %rax
movq %r14, (%rax)
jmp 0xedff