// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rsi, %rbx
cmpq $-0x1, %rdx
je 0x12aa8
movq %rdx, %r14
movq %rdx, %rcx
shrq $0x6, %rcx
movq 0x8(%rdi), %r15
movq 0x10(%rdi), %r12
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq 0x38(%r15), %rax
leaq 0x11(,%rax,8), %rax
imulq %rax, %rcx
movq 0x1(%r12,%rcx), %rcx
btq %rdx, %rcx
jb 0x12ba2
movabsq $-0x101010101010101, %r9 # imm = 0xFEFEFEFEFEFEFEFF
movabsq $-0x7f7f7f7f7f7f7f80, %rsi # imm = 0x8080808080808080
movabsq $0x5555555555555555, %r10 # imm = 0x5555555555555555
movabsq $0x3333333333333333, %rdx # imm = 0x3333333333333333
movabsq $0xf0f0f0f0f0f0f0f, %rbp # imm = 0xF0F0F0F0F0F0F0F
movabsq $0x101010101010100, %r11 # imm = 0x101010101010100
movq %rax, %rcx
imulq %r14, %rcx
movq 0x1(%r12,%rcx), %r13
movq %r13, %rcx
popcntq %rcx, %rcx
testl %ecx, %ecx
jle 0x12aba
movq %r13, %rcx
shrq %rcx
andq %r10, %rcx
movq %r13, %r8
subq %rcx, %r8
movq %r8, %rcx
andq %rdx, %rcx
shrq $0x2, %r8
andq %rdx, %r8
addq %rcx, %r8
movq %r8, %rdx
shrq $0x4, %rdx
addq %r8, %rdx
andq %rbp, %rdx
movq %rdx, %rcx
imulq %r9, %rcx
addq %rsi, %rcx
andq %rsi, %rcx
popcntq %rcx, %rcx
shll $0x3, %ecx
movslq %ecx, %rcx
imulq %r11, %rdx
shrq %cl, %rdx
shrq %cl, %r13
movzbl %r13b, %r8d
shll $0x8, %edx
movzwl %dx, %edx
subq %rdx, %r8
leaq 0x20a2(%rip), %rdx      # 0x14b40
movzbl (%r8,%rdx), %edx
addq %rcx, %rdx
jmp 0x12abf
movq $-0x1, 0x10(%rbx)
movq %rdi, (%rbx)
xorl %eax, %eax
jmp 0x12bd7
movl $0x40, %edx
cmpq $0x40, %rdx
jne 0x12b9b
movq 0x50(%r15), %r13
leaq 0x1(%r14), %rcx
imulq %rax, %rcx
addq %rcx, %r12
incq %r12
cmpq %r13, %r14
jae 0x12b96
movq (%r12), %rdx
movq %rdx, %rcx
popcntq %rcx, %rcx
testl %ecx, %ecx
jle 0x12b7f
movq %rdx, %rcx
shrq %rcx
andq %r10, %rcx
movq %rdx, %r8
subq %rcx, %r8
movq %r8, %rcx
movabsq $0x3333333333333333, %r9 # imm = 0x3333333333333333
andq %r9, %rcx
shrq $0x2, %r8
andq %r9, %r8
addq %rcx, %r8
movq %r10, %r9
movq %r8, %r10
shrq $0x4, %r10
addq %r8, %r10
andq %rbp, %r10
movq %r10, %rcx
movabsq $-0x101010101010101, %r8 # imm = 0xFEFEFEFEFEFEFEFF
imulq %r8, %rcx
addq %rsi, %rcx
andq %rsi, %rcx
popcntq %rcx, %rcx
shll $0x3, %ecx
movslq %ecx, %rcx
imulq %r11, %r10
shrq %cl, %r10
shrq %cl, %rdx
movzbl %dl, %edx
shll $0x8, %r10d
movzwl %r10w, %r8d
movq %r9, %r10
subq %r8, %rdx
leaq 0x1fcb(%rip), %r8       # 0x14b40
movzbl (%rdx,%r8), %edx
addq %rcx, %rdx
jmp 0x12b84
movl $0x40, %edx
addq %rax, %r12
incq %r14
cmpq $0x40, %rdx
je 0x12adb
jmp 0x12b9b
movl $0x40, %edx
shlq $0x6, %r14
addq %rdx, %r14
movq %rdi, (%rbx)
movl $0x0, 0x24(%rbx)
movq %r14, 0x8(%rbx)
testq %r14, %r14
je 0x12bc3
leaq -0x1(%r14), %rsi
callq 0x12418
incq %rax
jmp 0x12bc5
xorl %eax, %eax
cmpq %r14, %rax
cmovaq %rax, %r14
movq %r14, 0x10(%rbx)
cmpq 0x10(%r15), %r14
setb %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq