// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
movq %rdi, %rbx
movl $0x1, %ebp
movl %r15d, %ecx
shll %cl, %ebp
movl 0x8(%rdi), %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rdi), %r13d
leal -0x1(%rbp), %r12d
leaq (,%rbp,8), %rdi
callq 0x1090
movq %rax, %r14
cmpl %r15d, 0x4(%rsp)
jae 0x39d1
testq %r13, %r13
je 0x3a16
movq (%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq %rcx, (%r14,%rdx,8)
leal (%rdx,%r13), %esi
movq %rcx, (%r14,%rsi,8)
movq (%rax,%rdx,8), %rsi
testq %rsi, %rsi
je 0x39c7
movq (%rsi), %rdi
movl 0x18(%rsi), %r8d
andl %r12d, %r8d
movq (%r14,%r8,8), %r9
testq %r9, %r9
je 0x39ad
movq 0x8(%r9), %r8
movq %r8, 0x8(%rsi)
movq %rsi, 0x8(%r9)
movq $0x0, (%rsi)
movq 0x8(%rsi), %r8
jmp 0x39bc
leaq (%r14,%r8,8), %r8
movq %rsi, 0x8(%rsi)
movq $0x0, (%rsi)
movq %rsi, (%r8)
movq %rdi, %rsi
testq %rdi, %rdi
jne 0x3981
incq %rdx
cmpq %r13, %rdx
jne 0x396c
jmp 0x3a16
movq (%rbx), %rax
movl %ebp, %ecx
xorl %edx, %edx
movq %r14, %rsi
movq (%rax,%rdx,8), %rdi
movq %rdi, (%rsi)
leal (%rcx,%rdx), %r8d
movq (%rax,%r8,8), %r8
testq %r8, %r8
je 0x3a0a
movq %rsi, %r9
testq %rdi, %rdi
je 0x3a07
movq 0x8(%rdi), %r9
movq 0x8(%r8), %r10
movq %r10, 0x8(%rdi)
movq %r9, 0x8(%r8)
movq %r8, (%r9)
incq %rdx
addq $0x8, %rsi
cmpq %rdx, %rcx
jne 0x39db
movq (%rbx), %rdi
callq 0x1030
movl %r15d, 0x8(%rbx)
movl %ebp, 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