// File: /workspace/github_c_makefile_star2_O0/qpfiffer[P]38-Moths/src/simple_sparsehash.c
// Function: rehash_and_grow_table
static int _rehash_and_grow_table(struct sparse_dict *dict) {
	/* We've reached our chosen 'rehash the table' point, so
	 * we need to resize the table now.
	 */
	unsigned int i = 0, buckets_rehashed = 0;
	const size_t new_bucket_max = dict->bucket_max * 2;
	struct sparse_array *new_buckets = NULL;

	new_buckets = sparse_array_init(sizeof(struct sparse_bucket), new_bucket_max);
	if (new_buckets == NULL)
		goto error;

	/* Loop through each bucket and stick it into the new array. */
	for (i = 0; i < dict->bucket_max; i++) {
		size_t bucket_siz = 0;
		const struct sparse_bucket *bucket = sparse_array_get(dict->buckets, i, &bucket_siz);

		if (bucket_siz != 0 && bucket != NULL) {
			/* We found a bucket. */
			unsigned int probed_val = 0, num_probes = 0;
			uint64_t key_hash = bucket->hash;
			while (1) {
				/* Quadratically probe along the hash table for an empty slot. */
				probed_val = QUADRATIC_PROBE(new_bucket_max);
				size_t current_value_siz = 0;
				const void *current_value = sparse_array_get(new_buckets, probed_val, &current_value_siz);

				if (current_value_siz == 0 && current_value == NULL)
					break;

				/* If the following ever happens, there are deeply troubling
				 * things that no longer make sense in the universe.
				 */
				if (num_probes > dict->bucket_count)
					goto error;

				num_probes++;
			}
			if (!sparse_array_set(new_buckets, probed_val,
						bucket, sizeof(struct sparse_bucket)))
				goto error;
			buckets_rehashed++;
		}

		/* Short circuit to see if we can quit early: */
		if (buckets_rehashed == dict->bucket_count)
			break;
	}

	/* Finally, swap out the old array with the new one: */
	sparse_array_free(dict->buckets);
	dict->buckets = new_buckets;
	dict->bucket_max = new_bucket_max;

	return 1;

error:
	if (new_buckets)
		sparse_array_free(new_buckets);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shlq %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl %eax, %esi
movl $0x28, %edi
callq 0x35b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4170
jmp 0x42ac
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x427f
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x14(%rbp), %esi
leaq -0x30(%rbp), %rdx
callq 0x3460
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4260
cmpq $0x0, -0x38(%rbp)
je 0x4260
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x40(%rbp), %ecx
imull -0x40(%rbp), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
andq %rcx, %rax
movl %eax, -0x3c(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
leaq -0x50(%rbp), %rdx
callq 0x3460
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x4221
cmpq $0x0, -0x58(%rbp)
jne 0x4221
jmp 0x423b
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x4230
jmp 0x42ac
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x41d7
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq -0x38(%rbp), %rdx
movl $0x28, %ecx
callq 0x3070
cmpl $0x0, %eax
jne 0x4257
jmp 0x42ac
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x426f
jmp 0x427f
jmp 0x4271
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4177
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3250
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x42c3
cmpq $0x0, -0x28(%rbp)
je 0x42bc
movq -0x28(%rbp), %rdi
callq 0x3250
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)