// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rcx, %r9
movq %rdx, %rax
movq 0x38(%rdi), %rcx
movq %rdx, %r10
shrq $0x6, %r10
movabsq $0x3ffffffffffffff, %rbx # imm = 0x3FFFFFFFFFFFFFF
movq %rcx, %rdx
andq %rbx, %rdx
leaq 0x11(,%rdx,8), %r11
imulq %r10, %r11
addq %rsi, %r11
movl %eax, %r14d
andl $0x3f, %r14d
movq %rcx, %rdx
imulq %r14, %rdx
movq %rdx, %r15
shrq $0x3, %r15
movq 0x11(%r15,%r11), %r11
movq $-0x1, %r15
movq $-0x1, %r12
shlq %cl, %r12
cmpq $0x40, %rcx
notq %r12
cmoveq %r15, %r12
andb $0x7, %dl
movl %edx, %ecx
shrq %cl, %r11
andq %r12, %r11
movq %r11, (%r9)
movq 0x38(%rdi), %rdx
andq %rdx, %rbx
leaq 0x11(,%rbx,8), %r9
imulq %r9, %r10
movq 0x9(%rsi,%r10), %rcx
btq %r14, %rcx
jae 0x12525
movq $0x1, (%r8)
jmp 0x1259b
leaq 0x1(%rax), %rbx
movq %rbx, %r12
shrq $0x6, %r12
imulq %r9, %r12
leaq (%rsi,%r12), %rcx
movl %ebx, %r13d
andl $0x3f, %r13d
movq %rdx, %rdi
imulq %r13, %rdi
movq %rdi, %r10
shrq $0x3, %r10
movq 0x11(%r10,%rcx), %r14
movq $-0x1, %r10
movl %edx, %ecx
shlq %cl, %r10
cmpq $0x40, %rdx
notq %r10
cmoveq %r15, %r10
andb $0x7, %dil
movl %edi, %ecx
shrq %cl, %r14
andq %r10, %r14
movq 0x9(%rsi,%r12), %rcx
btq %r13, %rcx
jb 0x12589
leaq -0x1(%r11), %rcx
cmpq %r14, %rcx
jae 0x125a6
xorl %ecx, %ecx
cmpq %r11, %r14
sete %cl
leaq 0x1(%rcx), %rdx
movq %rdx, (%r8)
addq %rcx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r11, %r11
je 0x125f1
testq %r14, %r14
jne 0x125f1
leaq 0x2(%rax), %rdi
movq %rdi, %r15
shrq $0x6, %r15
imulq %r9, %r15
addq %rsi, %r15
movl %edi, %ecx
andl $0x3f, %ecx
imulq %rdx, %rcx
movq %rcx, %r12
shrq $0x3, %r12
movq 0x11(%r12,%r15), %r15
andb $0x7, %cl
shrq %cl, %r15
andq %r10, %r15
cmpq %r11, %r15
jne 0x125f1
movq $0x3, (%r8)
movq %rdi, %rax
jmp 0x1259b
movq %r14, %rcx
orq %r11, %rcx
je 0x126ba
movq %r8, -0x8(%rsp)
movl $0x1, %r12d
movl %edx, %ecx
shlq %cl, %r12
xorl %edi, %edi
cmpq $0x1, %r11
movl $0x0, %r15d
adcq $-0x2, %r15
cmpq %r11, %r14
je 0x126a7
addq %r12, %r15
leaq 0x11(%rsi), %r8
xorl %edi, %edi
movq %rbx, %rcx
shrq $0x6, %rcx
imulq %r9, %rcx
movq 0x9(%rsi,%rcx), %rcx
btq %rbx, %rcx
jb 0x126a7
testq %r11, %r11
setne %r13b
cmpq %r14, %r11
sbbq $0x0, %r14
setne %bpl
imulq %r15, %rdi
addq %r14, %rdi
incq %rbx
movq %rbx, %r14
shrq $0x6, %r14
imulq %r9, %r14
addq %r8, %r14
movq %r9, %r12
movl %ebx, %r9d
andl $0x3f, %r9d
imulq %rdx, %r9
movq %r9, %rcx
shrq $0x3, %rcx
movq (%rcx,%r14), %r14
andb %r13b, %bpl
andb $0x7, %r9b
movl %r9d, %ecx
movq %r12, %r9
shrq %cl, %r14
movzbl %bpl, %ecx
subq %rcx, %rdi
andq %r10, %r14
cmpq %r11, %r14
jne 0x1262f
testq %r11, %r11
je 0x126fd
addq $0x3, %rdi
movq -0x8(%rsp), %rax
movq %rdi, (%rax)
jmp 0x126f5
addq $0x2, %rax
movq %rax, %rcx
shrq $0x6, %rcx
imulq %rcx, %r9
addq %r9, %rsi
movl %eax, %ecx
andl $0x3f, %ecx
imulq %rcx, %rdx
movq %rdx, %rcx
shrq $0x3, %rcx
movq 0x11(%rcx,%rsi), %rsi
andb $0x7, %dl
movl %edx, %ecx
shrq %cl, %rsi
testq %r10, %rsi
je 0x1275a
movq $0x2, (%r8)
movq %rbx, %rax
jmp 0x1259b
movq %rbx, %rcx
shrq $0x6, %rcx
imulq %r9, %rcx
movq 0x9(%rsi,%rcx), %rcx
btq %rbx, %rcx
movq -0x8(%rsp), %r8
jb 0x1251c
incq %rbx
movq %rbx, %rcx
shrq $0x6, %rcx
imulq %r9, %rcx
addq %rcx, %rsi
movl %ebx, %ecx
andl $0x3f, %ecx
imulq %rdx, %rcx
movq %rcx, %rdx
shrq $0x3, %rdx
movq 0x11(%rdx,%rsi), %rdx
andb $0x7, %cl
shrq %cl, %rdx
testq %r10, %rdx
jne 0x1251c
addq $0x4, %rdi
movq %rdi, (%r8)
jmp 0x126f5
movq $0x3, (%r8)
jmp 0x1259b