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

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

	new_bucket_max = 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_count_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_count_t pos = j->key & 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_count_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
movl %esi, %ebp
movq %rdi, %rbx
movl $0x1, %r15d
movl %ebp, %ecx
shll %cl, %r15d
movl 0x8(%rdi), %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rdi), %r13d
leal -0x1(%r15), %r12d
leaq (,%r15,8), %rdi
callq 0x1090
movq %rax, %r14
cmpl %ebp, 0x4(%rsp)
jae 0x3a19
movq (%rbx), %rdi
testq %r13, %r13
je 0x3a5f
xorl %eax, %eax
xorl %ecx, %ecx
movq %rax, (%r14,%rcx,8)
leal (%rcx,%r13), %edx
movq %rax, (%r14,%rdx,8)
movq (%rdi,%rcx,8), %rdx
testq %rdx, %rdx
je 0x3a0f
movq (%rdx), %rsi
movl 0x18(%rdx), %r8d
andl %r12d, %r8d
movq (%r14,%r8,8), %r9
testq %r9, %r9
je 0x39f5
movq 0x8(%r9), %r8
movq %r8, 0x8(%rdx)
movq %rdx, 0x8(%r9)
movq $0x0, (%rdx)
movq 0x8(%rdx), %r8
jmp 0x3a04
leaq (%r14,%r8,8), %r8
movq %rdx, 0x8(%rdx)
movq $0x0, (%rdx)
movq %rdx, (%r8)
movq %rsi, %rdx
testq %rsi, %rsi
jne 0x39c9
incq %rcx
cmpq %r13, %rcx
jne 0x39b4
jmp 0x3a5f
xorl %eax, %eax
movq %r14, %rcx
movq (%rbx), %rsi
movq (%rsi,%rax,8), %rdx
movq %rdx, (%rcx)
leal (%r15,%rax), %edi
movq (%rsi,%rdi,8), %rsi
testq %rsi, %rsi
je 0x3a50
movq %rcx, %rdi
testq %rdx, %rdx
je 0x3a4d
movq 0x8(%rdx), %rdi
movq 0x8(%rsi), %r8
movq %r8, 0x8(%rdx)
movq %rdi, 0x8(%rsi)
movq %rsi, (%rdi)
incq %rax
addq $0x8, %rcx
cmpq %rax, %r15
jne 0x3a1e
movq (%rbx), %rdi
callq 0x1030
movl %ebp, 0x8(%rbx)
movl %r15d, 0xc(%rbx)
movl %r12d, 0x10(%rbx)
movq %r14, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq