// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rsi, %r14
movq %rsi, %r10
shrq $0x6, %r10
movq 0x8(%rdi), %r9
movq 0x10(%rdi), %rsi
movq 0x38(%r9), %rcx
movabsq $0x3ffffffffffffff, %r11 # imm = 0x3FFFFFFFFFFFFFF
movq %rcx, %rax
andq %r11, %rax
leaq 0x11(,%rax,8), %r8
imulq %r10, %r8
addq %rsi, %r8
movl %r14d, %r15d
andl $0x3f, %r15d
movq %rcx, %rax
imulq %r15, %rax
movq %rax, %r12
shrq $0x3, %r12
movq 0x11(%r12,%r8), %r8
movq $-0x1, %r12
movq $-0x1, %r13
shlq %cl, %r13
cmpq $0x40, %rcx
notq %r13
cmoveq %r12, %r13
andb $0x7, %al
movl %eax, %ecx
shrq %cl, %r8
andq %r13, %r8
movq %r8, (%rdx)
movq 0x38(%r9), %rax
andq %rax, %r11
leaq 0x11(,%r11,8), %r9
imulq %r9, %r10
movq 0x9(%rsi,%r10), %rcx
btq %r15, %rcx
jae 0x1277d
movq $0x1, (%rbx)
jmp 0x127fa
movq %rbx, 0x8(%rsp)
leaq 0x1(%r14), %rbx
movq %rbx, %r13
shrq $0x6, %r13
imulq %r9, %r13
leaq (%rsi,%r13), %rcx
movl %ebx, %ebp
andl $0x3f, %ebp
movq %rax, %rdx
imulq %rbp, %rdx
movq %rdx, %r10
shrq $0x3, %r10
movq 0x11(%r10,%rcx), %r11
movq $-0x1, %r10
movl %eax, %ecx
shlq %cl, %r10
cmpq $0x40, %rax
notq %r10
cmoveq %r12, %r10
andb $0x7, %dl
movl %edx, %ecx
shrq %cl, %r11
andq %r10, %r11
movq 0x9(%rsi,%r13), %rcx
btq %rbp, %rcx
jb 0x127e3
leaq -0x1(%r8), %rcx
cmpq %r11, %rcx
jae 0x1280c
xorl %eax, %eax
cmpq %r8, %r11
sete %al
leaq 0x1(%rax), %rcx
movq 0x8(%rsp), %rdx
movq %rcx, (%rdx)
addq %rax, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r8, %r8
je 0x1285c
testq %r11, %r11
jne 0x1285c
leaq 0x2(%r14), %rdx
movq %rdx, %r12
shrq $0x6, %r12
imulq %r9, %r12
addq %rsi, %r12
movl %edx, %ecx
andl $0x3f, %ecx
imulq %rax, %rcx
movq %rcx, %r13
shrq $0x3, %r13
movq 0x11(%r13,%r12), %r12
andb $0x7, %cl
shrq %cl, %r12
andq %r10, %r12
cmpq %r8, %r12
jne 0x1285c
movq 0x8(%rsp), %rax
movq $0x3, (%rax)
movq %rdx, %r14
jmp 0x127fa
movq %r11, %rcx
orq %r8, %rcx
je 0x12922
movl $0x1, %r13d
movl %eax, %ecx
shlq %cl, %r13
xorl %r12d, %r12d
cmpq $0x1, %r8
movl $0x0, %edx
adcq $-0x2, %rdx
cmpq %r8, %r11
je 0x1290f
addq %r13, %rdx
leaq 0x11(%rsi), %rcx
movq %rcx, 0x10(%rsp)
xorl %r12d, %r12d
movq %rbx, %rcx
shrq $0x6, %rcx
imulq %r9, %rcx
movq 0x9(%rsi,%rcx), %rcx
btq %rbx, %rcx
jb 0x1290f
testq %r8, %r8
setne %r13b
cmpq %r11, %r8
sbbq $0x0, %r11
setne %bpl
imulq %rdx, %r12
addq %r11, %r12
incq %rbx
movq %rbx, %r11
shrq $0x6, %r11
imulq %r9, %r11
addq 0x10(%rsp), %r11
movl %ebx, %r15d
andl $0x3f, %r15d
imulq %rax, %r15
movq %r15, %rcx
shrq $0x3, %rcx
movq (%rcx,%r11), %r11
andb %r13b, %bpl
andb $0x7, %r15b
movl %r15d, %ecx
shrq %cl, %r11
movzbl %bpl, %ecx
subq %rcx, %r12
andq %r10, %r11
cmpq %r8, %r11
jne 0x1289b
testq %r8, %r8
je 0x12947
addq $0x3, %r12
movq 0x8(%rsp), %rax
movq %r12, (%rax)
jmp 0x1293f
addq $0x2, %r14
movq %r14, %rsi
callq 0x13532
testq %rax, %rax
je 0x1297e
movq 0x8(%rsp), %rax
movq $0x2, (%rax)
movq %rbx, %r14
jmp 0x127fa
movq %rbx, %rax
shrq $0x6, %rax
imulq %r9, %rax
movq 0x9(%rsi,%rax), %rax
btq %rbx, %rax
jb 0x1296d
incq %rbx
movq %rbx, %rsi
callq 0x13532
testq %rax, %rax
je 0x1298f
movq 0x8(%rsp), %rax
movq $0x1, (%rax)
jmp 0x127fa
movq 0x8(%rsp), %rax
movq $0x3, (%rax)
jmp 0x127fa
addq $0x4, %r12
jmp 0x12918