// File: /workspace/github_c_makefile_star2_O2/open-mesh-mirror[P]batmand/hash.c
// Function: hash_iterate
struct hash_it_t *hash_iterate(struct hashtable_t *hash,
			       struct hash_it_t *iter_in)
{
	struct hash_it_t *iter;

	if (iter_in == NULL) {
		iter = debugMalloc(sizeof(struct hash_it_t), 301);
		iter->index =  -1;
		iter->bucket = NULL;
		iter->prev_bucket = NULL;
	} else {
		iter = iter_in;
	}

	/* sanity checks first (if our bucket got deleted in the last
	 * iteration): */
	if (iter->bucket != NULL) {
		if (iter->first_bucket != NULL) {

			/* we're on the first element and it got removed after
			 * the last iteration. */
			if ((*iter->first_bucket) != iter->bucket) {

				/* there are still other elements in the list */
				if ((*iter->first_bucket) != NULL) {
					iter->prev_bucket = NULL;
					iter->bucket = (*iter->first_bucket);
					iter->first_bucket = &hash->table[iter->index];
					return iter;
				} else {
					iter->bucket = NULL;
				}

			}

		} else if (iter->prev_bucket != NULL) {

			/* we're not on the first element, and the bucket got
			 * removed after the last iteration. The last bucket's
			 * next pointer is not pointing to our actual bucket
			 * anymore. Select the next. */
			if (iter->prev_bucket->next != iter->bucket)
				iter->bucket = iter->prev_bucket;

		}

	}

	/* now as we are sane, select the next one if there is some */
	if (iter->bucket != NULL) {
		if (iter->bucket->next != NULL) {
			iter->prev_bucket = iter->bucket;
			iter->bucket = iter->bucket->next;
			iter->first_bucket = NULL;
			return iter;
		}
	}
	/* if not returned yet, we've reached the last one on the index and
	 * have to search forward */

	iter->index++;
	/* go through the entries of the hash table */
	while (iter->index < hash->size) {

		if ((hash->table[iter->index]) == NULL) {
			iter->index++;
			continue;
		}

		iter->prev_bucket = NULL;
		iter->bucket = hash->table[iter->index];
		iter->first_bucket = &hash->table[iter->index];
		return iter;	/* if this table entry is not null, return it */
	}

	/* nothing to iterate over anymore */
	hash_iterate_free(iter);
	return NULL;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
testq %rsi, %rsi
je 0x5fe6
movq %rsi, %rax
leaq 0x8(%rsi), %rcx
movq 0x8(%rsi), %rdx
testq %rdx, %rdx
je 0x6004
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x605a
movq (%rsi), %rdi
cmpq %rdx, %rdi
je 0x6074
testq %rdi, %rdi
je 0x608c
andq $0x0, 0x10(%rax)
movq (%rsi), %rcx
movq %rcx, 0x8(%rax)
movslq (%rax), %rcx
shlq $0x3, %rcx
addq (%rbx), %rcx
movq %rcx, 0x18(%rax)
jmp 0x608a
pushq $0x20
popq %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x58c9
orl $-0x1, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq %rax, %rcx
addq $0x8, %rcx
movslq (%rax), %rdx
movslq 0xc(%rbx), %rdi
leaq 0x1(%rdx), %r8
movq %rdx, %rsi
shlq $0x3, %rsi
cmpq %rdi, %r8
jge 0x604a
movq (%rbx), %r9
incl %edx
leaq 0x1(%r8), %r10
addq $0x8, %rsi
cmpq $0x0, (%r9,%r8,8)
movq %r10, %r8
je 0x6016
movl %edx, (%rax)
andq $0x0, 0x10(%rax)
addq %r9, %rsi
movq -0x8(%r9,%r10,8), %rdx
movq %rdx, (%rcx)
movq %rsi, 0x18(%rax)
jmp 0x608a
incl %edx
movl %edx, (%rax)
movq %rax, %rdi
callq 0x5f82
xorl %eax, %eax
jmp 0x608a
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x6074
movq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x6074
movq %rdi, (%rcx)
movq %rdi, %rdx
jmp 0x6078
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0x6004
movq %rdx, 0x10(%rax)
movq %rsi, 0x8(%rax)
andq $0x0, 0x18(%rax)
popq %rbx
retq
andq $0x0, (%rcx)
jmp 0x6004