// File: /workspace/github_cpp_makefile_star2_O2/splatlab[P]debgr/threadsafe-gqf/gqf.c
// Function: qfi_next
int qfi_next(QFi *qfi)
{
	if (qfi_end(qfi))
		return 1;
	else {
		/* move to the end of the current counter*/
		uint64_t current_remainder, current_count;
		qfi->current = decode_counter(qfi->qf, qfi->current, &current_remainder,
																	&current_count);
		
		if (!is_runend(qfi->qf, qfi->current)) {
			qfi->current++;
#ifdef LOG_CLUSTER_LENGTH
			qfi->cur_length++;
#endif
			if (qfi->current > qfi->qf->metadata->nslots)
				return 1;
			return 0;
		}
		else {
#ifdef LOG_CLUSTER_LENGTH
			/* save to check if the new current is the new cluster. */
			uint64_t old_current = qfi->current;
#endif
			uint64_t block_index = qfi->run / SLOTS_PER_BLOCK;
			uint64_t rank = bitrank(get_block(qfi->qf, block_index)->occupieds[0],
															qfi->run % SLOTS_PER_BLOCK);
			uint64_t next_run = bitselect(get_block(qfi->qf,
																							block_index)->occupieds[0],
																		rank);
			if (next_run == 64) {
				rank = 0;
				while (next_run == 64 && block_index < qfi->qf->metadata->nblocks) {
					block_index++;
					next_run = bitselect(get_block(qfi->qf, block_index)->occupieds[0],
															 rank);
				}
			}
			if (block_index == qfi->qf->metadata->nblocks) {
				/* set the index values to max. */
				qfi->run = qfi->current = qfi->qf->metadata->xnslots;
				return 1;
			}
			qfi->run = block_index * SLOTS_PER_BLOCK + next_run;
			qfi->current++;
			if (qfi->current < qfi->run)
				qfi->current = qfi->run;
#ifdef LOG_CLUSTER_LENGTH
			if (qfi->current > old_current + 1) { /* new cluster. */
				if (qfi->cur_length > 10) {
					qfi->c_info[qfi->num_clusters].start_index = qfi->cur_start_index;
					qfi->c_info[qfi->num_clusters].length = qfi->cur_length;
					qfi->num_clusters++;
				}
				qfi->cur_start_index = qfi->run;
				qfi->cur_length = 1;
			} else {
				qfi->cur_length++;
			}
#endif
			return 0;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq (%rdi), %r15
movq 0x10(%rdi), %rsi
movq 0x8(%r15), %r12
movq 0x18(%r12), %r13
cmpq %r13, %rsi
jae 0xf2ed
movq %rdi, %rbx
leaq 0x20(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %r15, %rdi
callq 0xed85
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq %r15, %rdi
movq %rax, %rsi
callq 0xef61
testl %eax, %eax
je 0xf2c3
movq 0x8(%rbx), %rcx
movq %rcx, %rbp
shrq $0x6, %rbp
movq 0x10(%r15), %rdx
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq 0x38(%r12), %rax
leaq 0x11(,%rax,8), %r15
movq %r15, %rax
imulq %rbp, %rax
pushq $0x2
popq %rsi
shlq %cl, %rsi
movq %rdx, 0x10(%rsp)
movq 0x1(%rdx,%rax), %rdi
decq %rsi
andq %rdi, %rsi
popcntq %rsi, %rsi
callq 0xf088
cmpq $0x40, %rax
jne 0xf2de
movq %r13, 0x8(%rsp)
leaq 0x1(%rbp), %rax
imulq %r15, %rax
movq 0x10(%rsp), %rcx
leaq (%rax,%rcx), %r13
incq %r13
pushq $0x40
popq %rax
cmpq $0x40, %rax
jne 0xf2d9
cmpq 0x50(%r12), %rbp
jae 0xf2d6
incq %rbp
movq (%r13), %rdi
xorl %esi, %esi
callq 0xf088
addq %r15, %r13
jmp 0xf2a3
incq %r14
movq %r14, 0x10(%rbx)
xorl %eax, %eax
cmpq 0x10(%r12), %r14
seta %al
jmp 0xf2f0
pushq $0x40
popq %rax
movq 0x8(%rsp), %r13
cmpq 0x50(%r12), %rbp
jne 0xf2ff
movq %r13, 0x10(%rbx)
movq %r13, 0x8(%rbx)
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shlq $0x6, %rbp
addq %rax, %rbp
incq %r14
cmpq %rbp, %r14
cmovbeq %rbp, %r14
movq %rbp, 0x8(%rbx)
movq %r14, 0x10(%rbx)
xorl %eax, %eax
jmp 0xf2f0