// File: /workspace/github_cpp_makefile_star2_O3/splatlab[P]debgr/threadsafe-gqf/gqf.c
// Function: qf_iterator
bool qf_iterator(const QF *qf, QFi *qfi, uint64_t position)
{
  if (position == 0xffffffffffffffff) {
    qfi->current = 0xffffffffffffffff;
    qfi->qf = qf;
    return false;
  }
	assert(position < qf->metadata->nslots);
	if (!is_occupied(qf, position)) {
		uint64_t block_index = position;
		uint64_t idx = bitselect(get_block(qf, block_index)->occupieds[0], 0);
		if (idx == 64) {
			while(idx == 64 && block_index < qf->metadata->nblocks) {
				block_index++;
				idx = bitselect(get_block(qf, block_index)->occupieds[0], 0);
			}
		}
		position = block_index * SLOTS_PER_BLOCK + idx;
	}

	qfi->qf = qf;
	qfi->num_clusters = 0;
	qfi->run = position;
	qfi->current = position == 0 ? 0 : run_end(qfi->qf, position-1) + 1;
	if (qfi->current < position)
		qfi->current = position;

#ifdef LOG_CLUSTER_LENGTH
	qfi->c_info = (cluster_data* )calloc(qf->metadata->nslots/32, sizeof(cluster_data));
	qfi->cur_start_index = position;
	qfi->cur_length = 1;
#endif

	if (qfi->current >= qf->metadata->nslots)
		return false;
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
cmpq $-0x1, %rdx
je 0x1296a
movq %rdx, %r14
movq 0x8(%rdi), %r15
movq 0x10(%rdi), %rsi
movq 0x38(%r15), %rax
movq %rdx, %rcx
shrq $0x6, %rcx
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
andq %rax, %rdx
leaq 0x11(,%rdx,8), %rdx
imulq %rdx, %rcx
movq 0x1(%rsi,%rcx), %rcx
btq %r14, %rcx
jb 0x12990
movq %rax, 0x10(%rsp)
movabsq $-0x101010101010101, %r13 # imm = 0xFEFEFEFEFEFEFEFF
movabsq $-0x7f7f7f7f7f7f7f80, %r9 # imm = 0x8080808080808080
movabsq $0x5555555555555555, %rax # imm = 0x5555555555555555
movabsq $0x3333333333333333, %r11 # imm = 0x3333333333333333
movabsq $0xf0f0f0f0f0f0f0f, %rbp # imm = 0xF0F0F0F0F0F0F0F
movq %rdx, %rcx
imulq %r14, %rcx
movq 0x1(%rsi,%rcx), %r8
movq %r8, %rcx
popcntq %rcx, %rcx
testl %ecx, %ecx
movq %r15, 0x8(%rsp)
jle 0x12897
movq %r8, %rcx
shrq %rcx
andq %rax, %rcx
movq %r8, %r12
subq %rcx, %r12
movq %r12, %rcx
andq %r11, %rcx
shrq $0x2, %r12
andq %r11, %r12
addq %rcx, %r12
movq %r12, %r10
shrq $0x4, %r10
addq %r12, %r10
andq %rbp, %r10
movq %r10, %rcx
imulq %r13, %rcx
addq %r9, %rcx
andq %r9, %rcx
popcntq %rcx, %rcx
shll $0x3, %ecx
movslq %ecx, %rcx
movabsq $0x101010101010100, %r12 # imm = 0x101010101010100
imulq %r12, %r10
shrq %cl, %r10
shrq %cl, %r8
movzbl %r8b, %r8d
shll $0x8, %r10d
movzwl %r10w, %r10d
subq %r10, %r8
leaq 0x22cb(%rip), %r10      # 0x14b50
movzbl (%r8,%r10), %r12d
addq %rcx, %r12
cmpq $0x40, %r12
jne 0x1297f
movq 0x50(%r15), %rbp
leaq 0x1(%r14), %rcx
imulq %rdx, %rcx
leaq (%rcx,%rsi), %r8
incq %r8
cmpq %rbp, %r14
jae 0x12979
movq (%r8), %r12
movq %r12, %rcx
popcntq %rcx, %rcx
testl %ecx, %ecx
jle 0x12952
movq %r12, %rcx
shrq %rcx
andq %rax, %rcx
movq %r13, %r10
movq %r12, %r13
subq %rcx, %r13
movq %rax, %r15
movq %r13, %rax
andq %r11, %rax
shrq $0x2, %r13
andq %r11, %r13
addq %rax, %r13
movq %r13, %rax
shrq $0x4, %rax
addq %r13, %rax
movq %r10, %r13
movabsq $0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F
andq %rcx, %rax
movq %rax, %rcx
imulq %r10, %rcx
addq %r9, %rcx
andq %r9, %rcx
popcntq %rcx, %rcx
shll $0x3, %ecx
movslq %ecx, %rcx
movabsq $0x101010101010100, %r10 # imm = 0x101010101010100
imulq %r10, %rax
shrq %cl, %rax
shrq %cl, %r12
movzbl %r12b, %r12d
shll $0x8, %eax
movzwl %ax, %eax
subq %rax, %r12
movq %r15, %rax
leaq 0x2208(%rip), %r10      # 0x14b50
movzbl (%r12,%r10), %r12d
addq %rcx, %r12
jmp 0x12958
movl $0x40, %r12d
addq %rdx, %r8
incq %r14
cmpq $0x40, %r12
je 0x128aa
jmp 0x1297f
movq $-0x1, 0x10(%rbx)
movq %rdi, (%rbx)
xorl %eax, %eax
jmp 0x129c8
movl $0x40, %r12d
shlq $0x6, %r14
addq %r12, %r14
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %r15
movq %rdi, (%rbx)
movl $0x0, 0x24(%rbx)
movq %r14, 0x8(%rbx)
testq %r14, %r14
je 0x129b4
leaq -0x1(%r14), %rdx
movq %rax, %rdi
callq 0x121bd
incq %rax
jmp 0x129b6
xorl %eax, %eax
cmpq %r14, %rax
cmovaq %rax, %r14
movq %r14, 0x10(%rbx)
cmpq 0x10(%r15), %r14
setb %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq