// File: /workspace/github_cpp_makefile_star2_O1/amadvance[P]tommyds/tommyds/tommyhashdyn.c
// Function: tommy_hashdyn_resize
static void tommy_hashdyn_resize(tommy_hashdyn* hashdyn, tommy_size_t new_bucket_bit)
{
	tommy_size_t bucket_bit;
	tommy_size_t bucket_max;
	tommy_size_t new_bucket_max;
	tommy_size_t new_bucket_mask;
	tommy_hashdyn_node** new_bucket;

	bucket_bit = hashdyn->bucket_bit;
	bucket_max = hashdyn->bucket_max;

	new_bucket_max = (tommy_size_t)1 << new_bucket_bit;
	new_bucket_mask = new_bucket_max - 1;

	/* allocate the new vector using malloc() and not calloc() */
	/* because data is fully initialized in the update process */
	new_bucket = tommy_cast(tommy_hashdyn_node**, tommy_malloc(new_bucket_max * sizeof(tommy_hashdyn_node*)));

	/* reinsert all the elements */
	if (new_bucket_bit > bucket_bit) {
		tommy_size_t i;

		/* grow */
		for (i = 0; i < bucket_max; ++i) {
			tommy_hashdyn_node* j;

			/* setup the new two buckets */
			new_bucket[i] = 0;
			new_bucket[i + bucket_max] = 0;

			/* reinsert the bucket */
			j = hashdyn->bucket[i];
			while (j) {
				tommy_hashdyn_node* j_next = j->next;
				tommy_size_t pos = j->index & new_bucket_mask;
				if (new_bucket[pos])
					tommy_list_insert_tail_not_empty(new_bucket[pos], j);
				else
					tommy_list_insert_first(&new_bucket[pos], j);
				j = j_next;
			}
		}
	} else {
		tommy_size_t i;

		/* shrink */
		for (i = 0; i < new_bucket_max; ++i) {
			/* setup the new bucket with the lower bucket*/
			new_bucket[i] = hashdyn->bucket[i];

			/* concat the upper bucket */
			tommy_list_concat(&new_bucket[i], &hashdyn->bucket[i + new_bucket_max]);
		}
	}

	tommy_free(hashdyn->bucket);

	/* setup */
	hashdyn->bucket_bit = new_bucket_bit;
	hashdyn->bucket_max = new_bucket_max;
	hashdyn->bucket_mask = new_bucket_mask;
	hashdyn->bucket = new_bucket;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0x1, %r12d
movl %r14d, %ecx
shlq %cl, %r12
movl 0x20(%rdi), %eax
movq %rax, (%rsp)
movq 0x8(%rdi), %rbp
leaq -0x1(%r12), %r13
movl $0x8, %edi
shlq %cl, %rdi
callq 0x10c0
movq %rax, %r15
cmpq %r14, (%rsp)
jae 0x6151
testq %rbp, %rbp
je 0x6194
movq (%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
leaq (%r15,%rdx,8), %rsi
movq %rcx, (%r15,%rdx,8)
movq %rcx, (%rsi,%rbp,8)
movq (%rax,%rdx,8), %rsi
testq %rsi, %rsi
je 0x6147
movq (%rsi), %rdi
movq 0x18(%rsi), %r8
andq %r13, %r8
movq (%r15,%r8,8), %r9
testq %r9, %r9
je 0x612d
movq 0x8(%r9), %r8
movq %r8, 0x8(%rsi)
movq %rsi, 0x8(%r9)
movq $0x0, (%rsi)
movq 0x8(%rsi), %r8
jmp 0x613c
leaq (%r15,%r8,8), %r8
movq %rsi, 0x8(%rsi)
movq $0x0, (%rsi)
movq %rsi, (%r8)
movq %rdi, %rsi
testq %rdi, %rdi
jne 0x6101
incq %rdx
cmpq %rbp, %rdx
jne 0x60ec
jmp 0x6194
movq (%rbx), %rax
leaq (%rax,%r12,8), %rcx
xorl %edx, %edx
movq %r15, %rsi
movq (%rax,%rdx,8), %r8
movq %r8, (%rsi)
movq (%rcx,%rdx,8), %rdi
testq %rdi, %rdi
je 0x6188
movq %rsi, %r9
testq %r8, %r8
je 0x6185
movq 0x8(%r8), %r9
movq 0x8(%rdi), %r10
movq %r10, 0x8(%r8)
movq %r9, 0x8(%rdi)
movq %rdi, (%r9)
incq %rdx
addq $0x8, %rsi
cmpq %rdx, %r12
jne 0x615d
movq (%rbx), %rdi
callq 0x1030
movl %r14d, 0x20(%rbx)
movq %r12, 0x8(%rbx)
movq %r13, 0x10(%rbx)
movq %r15, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq