// File: /workspace/github_cpp_makefile_star2_O2/amadvance[P]tommyds/check.c
// Function: test_hashtable
void test_hashtable(void)
{
	tommy_hashtable hashtable;
	struct object_hash* HASH;
	unsigned i, j, n;
	unsigned limit;
	const unsigned size = TOMMY_SIZE;
	const unsigned module = TOMMY_SIZE / 4;

	HASH = malloc(size * sizeof(struct object_hash));

	for(i=0;i<size;++i)
		HASH[i].value = i % module;

	/* initialize a very small hashtable */
	tommy_hashtable_init(&hashtable, 1);

	/* check that we allocated space for more elements */
	if (hashtable.bucket_max == 1)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	/* destroy it as empty */
	tommy_hashtable_done(&hashtable);

	START("hashtable stack");
	limit = 5 * isqrt(size);
	for(n=0;n<=limit;++n) {
		/* last iteration is full size */
		if (n == limit)
			n = limit = size;

		tommy_hashtable_init(&hashtable, limit / 2);

		/* insert */
		for(i=0;i<n;++i)
			tommy_hashtable_insert(&hashtable, &HASH[i].node, &HASH[i], HASH[i].value);

		if (tommy_hashtable_memory_usage(&hashtable) < n * sizeof(void*))
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		if (tommy_hashtable_count(&hashtable) != n)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		the_count = 0;
		tommy_hashtable_foreach(&hashtable, count_callback);
		if (the_count != n)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		/* remove in backward order */
		for(i=0;i<n/2;++i)
			tommy_hashtable_remove_existing(&hashtable, &HASH[n-i-1].node);

		/* remove missing */
		for(i=0;i<n/2;++i)
			if (tommy_hashtable_remove(&hashtable, search_callback, &HASH[n-i-1], HASH[n-i-1].value) != 0)
				/* LCOV_EXCL_START */
				abort();
				/* LCOV_EXCL_STOP */

		/* remove search */
		for(i=0;i<n/2;++i)
			if (tommy_hashtable_remove(&hashtable, search_callback, &HASH[n/2-i-1], HASH[n/2-i-1].value) == 0)
				/* LCOV_EXCL_START */
				abort();
				/* LCOV_EXCL_STOP */

		tommy_hashtable_done(&hashtable);
	}
	STOP();

	START("hashtable queue");
	limit = isqrt(size) / 16;
	for(n=0;n<=limit;++n) {
		/* last iteration is full size */
		if (n == limit)
			n = limit = size;

		tommy_hashtable_init(&hashtable, limit / 2);

		/* insert first run */
		for(j=0,i=0;i<n;++i)
			tommy_hashtable_insert(&hashtable, &HASH[i].node, &HASH[i], HASH[i].value);

		the_count = 0;
		tommy_hashtable_foreach_arg(&hashtable, count_arg_callback, &the_count);
		if (the_count != n)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		/* insert all the others */
		for(;i<size;++i,++j) {
			/* insert one */
			tommy_hashtable_insert(&hashtable, &HASH[i].node, &HASH[i], HASH[i].value);

			/* remove one */
			tommy_hashtable_remove_existing(&hashtable, &HASH[j].node);
		}

		for(;j<size;++j)
			if (tommy_hashtable_remove(&hashtable, search_callback, &HASH[j], HASH[j].value) == 0)
				/* LCOV_EXCL_START */
				abort();
				/* LCOV_EXCL_STOP */

		tommy_hashtable_done(&hashtable);
	}
	STOP();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl $0x3567e00, %edi        # imm = 0x3567E00
callq 0x10b0
movq %rax, %r12
xorl %ecx, %ecx
movl $0x3d090, %esi          # imm = 0x3D090
xorl %edi, %edi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
cmpq $0x3567e00, %rdi        # imm = 0x3567E00
je 0x22de
movl %edx, (%r12,%rdi)
addq $0x38, %rdi
incl %ecx
jmp 0x22c3
leaq 0x28(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x44e3
cmpq $0x1, 0x8(%rbx)
je 0x25d2
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x4555
leaq 0x3f96(%rip), %rdi      # 0x62a3
callq 0x127d
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x122b
movq %rax, 0x18(%rsp)
leal (%rax,%rax,4), %ebp
xorl %r13d, %r13d
cmpl %ebp, %r13d
ja 0x2466
movl $0xf4240, %eax          # imm = 0xF4240
cmovel %eax, %r13d
cmovel %eax, %ebp
movl %ebp, %esi
shrl %esi
movq %r15, %rdi
callq 0x44e3
movq %r12, %r14
movq %r13, %rbx
subq $0x1, %rbx
jb 0x236c
leaq 0x8(%r14), %rsi
movslq (%r14), %rcx
movq %r15, %rdi
movq %r14, %rdx
callq 0x455d
addq $0x38, %r14
jmp 0x234e
movq %r15, %rdi
callq 0x4707
leaq (,%r13,8), %rcx
cmpq %rcx, %rax
jb 0x25d2
cmpq %r13, 0x40(%rsp)
jne 0x25d2
movl %ebp, 0x10(%rsp)
andl $0x0, 0x1008a75(%rip)   # 0x100ae10
movq %r15, %rdi
leaq -0x5bf(%rip), %rsi      # 0x1de6
callq 0x4677
cmpl %r13d, 0x1008a5f(%rip)  # 0x100ae10
jne 0x25d2
movq %r13, %rax
shrl %r13d
movq %rax, 0x8(%rsp)
leal -0x1(%rax), %ebx
movl %ebx, %r14d
movq %r13, %rbp
subq $0x1, %rbp
jb 0x23ed
movl %r14d, %eax
imulq $0x38, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x8, %rsi
movq %r15, %rdi
callq 0x45ba
decl %r14d
jmp 0x23cb
movq %r13, %r14
leaq 0x1e0(%rip), %rbp       # 0x25d7
subq $0x1, %r14
jb 0x2448
movl %ebx, %eax
imulq $0x38, %rax, %rax
leaq (%r12,%rax), %rdx
movslq (%r12,%rax), %rcx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x460b
decl %ebx
testq %rax, %rax
je 0x23f7
jmp 0x25d2
decq %r13
movl %r13d, %eax
imulq $0x38, %rax, %rax
leaq (%r12,%rax), %rdx
movslq (%r12,%rax), %rcx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x460b
testq %rax, %rax
je 0x25d2
testq %r13, %r13
jne 0x2422
movq %r15, %rdi
callq 0x4555
movq 0x8(%rsp), %r13
incl %r13d
movl 0x10(%rsp), %ebp
jmp 0x2327
callq 0x12cf
leaq 0x3e41(%rip), %rdi      # 0x62b3
callq 0x127d
movq 0x18(%rsp), %rsi
shrl $0x4, %esi
movq %r12, 0x8(%rsp)
leaq 0x8(%r12), %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
leaq 0x28(%rsp), %r12
cmpl %esi, %r15d
ja 0x25be
movl $0xf4240, %eax          # imm = 0xF4240
cmovel %eax, %r15d
cmovel %eax, %esi
movq %rsi, 0x18(%rsp)
shrl %esi
movq %r12, %rdi
callq 0x44e3
movq 0x8(%rsp), %rbx
movq %r15, %r14
subq $0x1, %r14
jb 0x24e0
leaq 0x8(%rbx), %rsi
movslq (%rbx), %rcx
movq %r12, %rdi
movq %rbx, %rdx
callq 0x455d
addq $0x38, %rbx
jmp 0x24c2
andl $0x0, 0x1008929(%rip)   # 0x100ae10
movq %r12, %rdi
leaq -0x704(%rip), %rsi      # 0x1ded
leaq 0x1008918(%rip), %rdx   # 0x100ae10
callq 0x46b8
cmpl %r15d, 0x100890c(%rip)  # 0x100ae10
jne 0x25d2
movq %r15, 0x10(%rsp)
imulq $0x38, %r15, %r13
movq 0x8(%rsp), %rbx
addq %rbx, %r13
pushq $-0x1
popq %rbp
movq 0x20(%rsp), %r14
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
addq %r15, %rax
cmpq $0xf4240, %rax          # imm = 0xF4240
jae 0x256d
leaq 0x8(%r13), %rsi
movslq (%r13), %rcx
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x455d
movq %r12, %rdi
movq %r14, %rsi
callq 0x45ba
incq %r15
addq $0x38, %r13
addq $0x38, %r14
addq $0x38, %rbx
incq %rbp
jmp 0x2526
leaq 0x28(%rsp), %r12
leaq 0x5e(%rip), %r15        # 0x25d7
incq %rbp
cmpq $0xf423f, %rbp          # imm = 0xF423F
ja 0x25a4
leaq 0x38(%rbx), %r14
movslq (%rbx), %rcx
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x460b
movq %r14, %rbx
testq %rax, %rax
jne 0x2579
jmp 0x25d2
movq %r12, %rdi
callq 0x4555
movq 0x10(%rsp), %r15
incl %r15d
movq 0x18(%rsp), %rsi
jmp 0x2496
callq 0x12cf
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040