// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq (%rdi), %rax
movq 0x10(%rdi), %rdx
movq 0x8(%rax), %r14
movq 0x18(%r14), %r12
movl $0x1, %ecx
cmpq %r12, %rdx
jae 0x12d13
movq %rdi, %rbx
movq 0x10(%rax), %r15
leaq 0x10(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r14, %rdi
movq %r15, %rsi
callq 0x12480
movq %rax, 0x10(%rbx)
movq %rax, %rcx
shrq $0x6, %rcx
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
andq 0x38(%r14), %rdx
leaq 0x11(,%rdx,8), %rsi
imulq %rsi, %rcx
movq 0x9(%r15,%rcx), %rcx
btq %rax, %rcx
jae 0x12cc3
movabsq $-0x7f7f7f7f7f7f7f80, %r8 # imm = 0x8080808080808080
movabsq $0x5555555555555555, %r11 # imm = 0x5555555555555555
movabsq $0x3333333333333333, %r10 # imm = 0x3333333333333333
movabsq $0x101010101010100, %r13 # imm = 0x101010101010100
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movq %rdx, %r9
movl $0x2, %edi
shlq %cl, %rdi
imulq %rsi, %r9
movq 0x1(%r15,%r9), %rbp
decq %rdi
andq %rbp, %rdi
popcntq %rdi, %rdi
movq %rbp, %rcx
popcntq %rcx, %rcx
cmpl %edi, %ecx
jle 0x12bf0
movq %rbp, %rcx
shrq %rcx
andq %r11, %rcx
movq %rbp, %r9
subq %rcx, %r9
movq %r9, %rcx
andq %r10, %rcx
shrq $0x2, %r9
andq %r10, %r9
addq %rcx, %r9
movq %r9, %r11
shrq $0x4, %r11
addq %r9, %r11
movabsq $0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F
andq %rcx, %r11
movq %r11, %rcx
movabsq $-0x101010101010101, %r9 # imm = 0xFEFEFEFEFEFEFEFF
imulq %r9, %rcx
movslq %edi, %rdi
leaq 0x1(%r13), %r9
imulq %rdi, %r9
orq %r8, %r9
addq %rcx, %r9
andq %r8, %r9
popcntq %r9, %r9
shll $0x3, %r9d
movslq %r9d, %rcx
imulq %r13, %r11
shrq %cl, %r11
movl $0xff, %r9d
andq %r9, %r11
shrq %cl, %rbp
subq %r11, %rdi
movabsq $0x5555555555555555, %r11 # imm = 0x5555555555555555
andq %r9, %rbp
shlq $0x8, %rdi
orq %rbp, %rdi
leaq 0x1f72(%rip), %r9       # 0x14b50
movzbl (%r9,%rdi), %edi
addq %rcx, %rdi
cmpq $0x40, %rdi
jne 0x12ce0
movq %r12, (%rsp)
movq %r13, %r12
movabsq $0xf0f0f0f0f0f0f0f, %r13 # imm = 0xF0F0F0F0F0F0F0F
movq 0x50(%r14), %r14
leaq 0x1(%rdx), %rcx
imulq %rsi, %rcx
addq %rcx, %r15
incq %r15
leaq 0x1f36(%rip), %rbp      # 0x14b50
cmpq %r14, %rdx
jae 0x12cd5
movq (%r15), %rdi
movq %rdi, %rcx
popcntq %rcx, %rcx
testl %ecx, %ecx
jle 0x12cac
movq %rdi, %rcx
shrq %rcx
andq %r11, %rcx
movq %rdi, %r11
subq %rcx, %r11
movq %r11, %rcx
andq %r10, %rcx
shrq $0x2, %r11
andq %r10, %r11
addq %rcx, %r11
movq %r11, %r9
shrq $0x4, %r9
addq %r11, %r9
andq %r13, %r9
movq %r9, %rcx
movabsq $-0x101010101010101, %r11 # imm = 0xFEFEFEFEFEFEFEFF
imulq %r11, %rcx
movabsq $0x5555555555555555, %r11 # imm = 0x5555555555555555
addq %r8, %rcx
andq %r8, %rcx
popcntq %rcx, %rcx
shll $0x3, %ecx
movslq %ecx, %rcx
imulq %r12, %r9
shrq %cl, %r9
shrq %cl, %rdi
movzbl %dil, %edi
shll $0x8, %r9d
movzwl %r9w, %r9d
subq %r9, %rdi
movzbl (%rdi,%rbp), %edi
addq %rcx, %rdi
jmp 0x12cb1
movl $0x40, %edi
addq %rsi, %r15
incq %rdx
cmpq $0x40, %rdi
je 0x12c1a
jmp 0x12cda
incq %rax
movq %rax, 0x10(%rbx)
xorl %ecx, %ecx
cmpq 0x10(%r14), %rax
seta %cl
jmp 0x12d13
movl $0x40, %edi
movq (%rsp), %r12
jmp 0x12ce4
movq 0x50(%r14), %r14
cmpq %r14, %rdx
jne 0x12cf8
movq %r12, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movl $0x1, %ecx
jmp 0x12d13
shlq $0x6, %rdx
addq %rdi, %rdx
incq %rax
cmpq %rdx, %rax
cmovbeq %rdx, %rax
movq %rdx, 0x8(%rbx)
movq %rax, 0x10(%rbx)
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq