// File: /workspace/github_cpp_makefile_star2_O3/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 0x646f
movq (%rbx), %rdi
testq %rbp, %rbp
je 0x64bd
xorl %eax, %eax
xorl %ecx, %ecx
leaq (%r15,%rcx,8), %rdx
movq %rax, (%r15,%rcx,8)
movq %rax, (%rdx,%rbp,8)
movq (%rdi,%rcx,8), %rdx
testq %rdx, %rdx
je 0x6465
movq (%rdx), %rsi
movq 0x18(%rdx), %r8
andq %r13, %r8
movq (%r15,%r8,8), %r9
testq %r9, %r9
je 0x644b
movq 0x8(%r9), %r8
movq %r8, 0x8(%rdx)
movq %rdx, 0x8(%r9)
movq $0x0, (%rdx)
movq 0x8(%rdx), %r8
jmp 0x645a
leaq (%r15,%r8,8), %r8
movq %rdx, 0x8(%rdx)
movq $0x0, (%rdx)
movq %rdx, (%r8)
movq %rsi, %rdx
testq %rsi, %rsi
jne 0x641f
incq %rcx
cmpq %rbp, %rcx
jne 0x640a
jmp 0x64bd
leaq (,%r12,8), %rax
xorl %ecx, %ecx
movq %r15, %rdx
movq (%rbx), %rsi
leaq (%rsi,%rcx,8), %r8
movq (%rsi,%rcx,8), %rdi
movq %rdi, (%rdx)
movq (%rax,%r8), %rsi
testq %rsi, %rsi
je 0x64ae
movq %rdx, %r8
testq %rdi, %rdi
je 0x64ab
movq 0x8(%rdi), %r8
movq 0x8(%rsi), %r9
movq %r9, 0x8(%rdi)
movq %r8, 0x8(%rsi)
movq %rsi, (%r8)
incq %rcx
addq $0x8, %rdx
cmpq %rcx, %r12
jne 0x647c
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