// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rsi, %r13
pushq $0x1
popq %rbx
movl %r13d, %ecx
shlq %cl, %rbx
movl 0x20(%rdi), %r14d
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r12
leaq -0x1(%rbx), %rbp
pushq $0x8
popq %rdi
shlq %cl, %rdi
callq 0x10b0
movq %rax, %r15
movq %r13, 0x10(%rsp)
cmpq %r13, %r14
jae 0x5155
xorl %eax, %eax
cmpq %r12, %rax
je 0x5190
andq $0x0, (%r15,%rax,8)
leaq (%r15,%rax,8), %rcx
andq $0x0, (%rcx,%r12,8)
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rcx
testq %rcx, %rcx
je 0x5150
movq (%rcx), %rdx
movq 0x18(%rcx), %rsi
andq %rbp, %rsi
movq (%r15,%rsi,8), %rdi
testq %rdi, %rdi
je 0x513c
movq 0x8(%rdi), %rsi
movq %rsi, 0x8(%rcx)
movq %rcx, 0x8(%rdi)
andq $0x0, (%rcx)
movq 0x8(%rcx), %rsi
jmp 0x5148
leaq (%r15,%rsi,8), %rsi
movq %rcx, 0x8(%rcx)
andq $0x0, (%rcx)
movq %rcx, (%rsi)
movq %rdx, %rcx
jmp 0x510e
incq %rax
jmp 0x50eb
leaq (,%rbx,8), %r14
xorl %r13d, %r13d
movq %r15, %r12
cmpq %r13, %rbx
je 0x5190
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq (%rsi,%r13,8), %rax
movq %rax, (%r12)
addq %r14, %rsi
movq %r12, %rdi
callq 0x51c0
incq %r13
addq $0x8, %r14
addq $0x8, %r12
jmp 0x5163
movq 0x8(%rsp), %r14
movq (%r14), %rdi
callq 0x1030
movq 0x10(%rsp), %rax
movl %eax, 0x20(%r14)
movq %rbx, 0x8(%r14)
movq %rbp, 0x10(%r14)
movq %r15, (%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq