// File: /workspace/github_cpp_makefile_star2_O1/attractivechaos[P]udb2/tommyds/./tommyhashlin.c
// Function: hashlin_shrink_step
tommy_inline void hashlin_shrink_step(tommy_hashlin* hashlin)
{
	/* shrink if less than 12.5% full */
	if (hashlin->state != TOMMY_HASHLIN_STATE_SHRINK
		&& hashlin->count < hashlin->bucket_max / 8
	) {
		/* avoid to shrink the first bucket */
		if (hashlin->bucket_bit > TOMMY_HASHLIN_BIT) {
			/* if we are stable, setup a new shrink state */
			/* otherwise continue with the already setup grow one */
			/* but in backward direction */
			if (hashlin->state == TOMMY_HASHLIN_STATE_STABLE) {
				/* set the lower size */
				hashlin->low_max = hashlin->bucket_max / 2;
				hashlin->low_mask = hashlin->bucket_mask / 2;

				/* start from the half going backward */
				hashlin->split = hashlin->low_max;
			}

			/* start reallocation */
			hashlin->state = TOMMY_HASHLIN_STATE_SHRINK;
		}
	}

	/* if we are shrinking */
	if (hashlin->state == TOMMY_HASHLIN_STATE_SHRINK) {
		/* compute the split target required to finish the reallocation before the next resize */
		tommy_count_t split_target = 8 * hashlin->count;

		/* reallocate buckets until the split target */
		while (hashlin->split + hashlin->low_max > split_target) {
			tommy_hashlin_node** split[2];

			/* go backward position */
			--hashlin->split;

			/* get the low bucket */
			split[0] = tommy_hashlin_pos(hashlin, hashlin->split);

			/* get the high bucket */
			split[1] = tommy_hashlin_pos(hashlin, hashlin->split + hashlin->low_max);

			/* concat the high bucket into the low one */
			tommy_list_concat(split[0], split[1]);

			/* if we have finished, clean up and change the state */
			if (hashlin->split == 0) {
				tommy_hashlin_node** segment;

				/* shrink the hash size */
				--hashlin->bucket_bit;
				hashlin->bucket_max = 1 << hashlin->bucket_bit;
				hashlin->bucket_mask = hashlin->bucket_max - 1;

				/* free the last segment */
				segment = hashlin->bucket[hashlin->bucket_bit];
				tommy_free(&segment[((tommy_ptrdiff_t)1) << hashlin->bucket_bit]);

				/* go in stable mode */
				tommy_hashlin_stable(hashlin);
				break;
			}
		}
	}
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl 0x11c(%rdi), %ecx
cmpl $0x2, %ecx
je 0x3561
movl 0x104(%rbx), %eax
movl %eax, %edx
shrl $0x3, %edx
cmpl %edx, 0x118(%rbx)
jae 0x3561
cmpl $0x7, 0x100(%rbx)
jb 0x3561
testl %ecx, %ecx
jne 0x3557
shrl %eax
movl %eax, 0x10c(%rbx)
movl 0x108(%rbx), %ecx
shrl %ecx
movl %ecx, 0x110(%rbx)
movl %eax, 0x114(%rbx)
movl $0x2, 0x11c(%rbx)
cmpl $0x2, 0x11c(%rbx)
jne 0x3641
movl 0x114(%rbx), %eax
movl 0x118(%rbx), %ecx
shll $0x3, %ecx
movl 0x10c(%rbx), %edx
addl %eax, %edx
decl %eax
leaq (,%rax,8), %rsi
cmpl %ecx, %edx
jbe 0x3641
movl %eax, 0x114(%rbx)
decl %edx
movl %edx, %edi
orl $0x1, %edi
bsrl %edi, %edi
movq (%rbx,%rdi,8), %rdi
movq (%rdi,%rdx,8), %rdi
testq %rdi, %rdi
je 0x35e4
movl %eax, %r8d
orl $0x1, %r8d
bsrl %r8d, %r8d
movq (%rbx,%r8,8), %r8
movq (%r8,%rsi), %r9
testq %r9, %r9
je 0x35de
movq 0x8(%r9), %r8
movq 0x8(%rdi), %r10
movq %r10, 0x8(%r9)
movq %r8, 0x8(%rdi)
jmp 0x35e1
addq %rsi, %r8
movq %rdi, (%r8)
addq $-0x8, %rsi
addl $-0x1, %eax
jb 0x358f
movl 0x100(%rbx), %ecx
decl %ecx
movl $0x1, %eax
shll %cl, %eax
movl %ecx, 0x100(%rbx)
movl %eax, 0x104(%rbx)
decl %eax
movl $0x1, %edi
shlq %cl, %rdi
movl %eax, 0x108(%rbx)
shlq $0x3, %rdi
addq (%rbx,%rcx,8), %rdi
callq 0x1030
xorl %eax, %eax
movl %eax, 0x11c(%rbx)
movq 0x104(%rbx), %rcx
movq %rcx, 0x10c(%rbx)
movl %eax, 0x114(%rbx)
popq %rbx
retq