// File: /workspace/github_cpp_makefile_star2_O3/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 0x10c0
movq %rax, %rbx
xorl %eax, %eax
xorl %ecx, %ecx
movl %eax, %edx
imulq $0x431bde83, %rdx, %rdx # imm = 0x431BDE83
shrq $0x30, %rdx
imull $0x3d090, %edx, %edx    # imm = 0x3D090
movl %eax, %esi
subl %edx, %esi
movl %esi, (%rbx,%rcx)
addq $0x38, %rcx
incl %eax
cmpq $0x3567e00, %rcx        # imm = 0x3567E00
jne 0x2c5f
leaq 0x28(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdi
callq 0x55bf
cmpq $0x1, 0x8(%r14)
je 0x2ffe
leaq 0x28(%rsp), %rdi
callq 0x5639
movq $-0x20, %rax
leaq 0x9153(%rip), %rcx      # 0xbe10
incb 0x20(%rax,%rcx)
addq $0x20, %rax
cmpq $0xffffe0, %rax         # imm = 0xFFFFE0
jb 0x2cbd
movl $0x0, 0x9129(%rip)      # 0xbe00
leaq 0x45c5(%rip), %rax      # 0x72a3
movq %rax, 0x100912b(%rip)   # 0x100be10
callq 0x12e3
movq %rax, 0x1009127(%rip)   # 0x100be18
xorl %ebp, %ebp
movl $0x1388, %eax           # imm = 0x1388
leaq 0x28(%rsp), %r14
cmpl %eax, %ebp
movl $0xf4240, %ecx          # imm = 0xF4240
cmovel %ecx, %ebp
cmovel %ecx, %eax
movl %eax, 0x10(%rsp)
movl %eax, %esi
shrl %esi
movq %r14, %rdi
callq 0x55bf
testl %ebp, %ebp
je 0x2d47
movq %rbp, %r12
movl %ebp, %ebp
movq %rbp, %r15
movq %rbx, %r13
leaq 0x8(%r13), %rsi
movslq (%r13), %rcx
movq %r14, %rdi
movq %r13, %rdx
callq 0x5641
addq $0x38, %r13
decq %r15
jne 0x2d29
jmp 0x2d4c
movq %rbp, %r12
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x57e7
leaq (,%rbp,8), %rcx
cmpq %rcx, %rax
jb 0x2ffe
cmpq %rbp, 0x40(%rsp)
jne 0x2ffe
movl $0x0, 0x10090a6(%rip)   # 0x100be20
movq %r14, %rdi
leaq -0xa8c(%rip), %rsi      # 0x22f8
callq 0x574b
movq %r12, %rbp
cmpl %ebp, 0x100908e(%rip)   # 0x100be20
jne 0x2ffe
cmpl $0x2, %ebp
jb 0x2e43
movl %ebp, %eax
shrl %eax
movl %eax, %r12d
movq %rbp, 0x8(%rsp)
leal -0x1(%rbp), %r15d
movq %r12, %r13
movl %r15d, %ebp
movl %ebp, %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x5685
decl %ebp
decq %r13
jne 0x2db7
movq %r12, %r13
movq 0x8(%rsp), %rbp
cmpl $0x2, %ebp
jb 0x2e43
movl %r15d, %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rdx
movslq (%rbx,%rax), %rcx
movq %r14, %rdi
leaq 0x209(%rip), %rsi       # 0x3003
callq 0x56bf
testq %rax, %rax
jne 0x2ffe
decl %r15d
decq %r13
jne 0x2de1
cmpl $0x2, %ebp
jb 0x2e43
leal -0x1(%r12), %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rdx
movslq (%rbx,%rax), %rcx
movq %r14, %rdi
leaq 0x1d3(%rip), %rsi       # 0x3003
callq 0x56bf
testq %rax, %rax
je 0x2ffe
decq %r12
jne 0x2e15
movq %r14, %rdi
callq 0x5639
incl %ebp
movl 0x10(%rsp), %eax
cmpl %eax, %ebp
jbe 0x2cfd
callq 0x1312
movq $-0x20, %rax
leaq 0x8fa4(%rip), %rcx      # 0xbe10
incb 0x20(%rax,%rcx)
addq $0x20, %rax
cmpq $0xffffe0, %rax         # imm = 0xFFFFE0
jb 0x2e6c
movl $0x0, 0x8f7a(%rip)      # 0xbe00
leaq 0x4426(%rip), %rax      # 0x72b3
movq %rax, 0x1008f7c(%rip)   # 0x100be10
callq 0x12e3
movq %rax, 0x1008f78(%rip)   # 0x100be18
leaq 0x8(%rbx), %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
movl $0x3e, %r12d
leaq 0x28(%rsp), %r14
leaq 0x145(%rip), %r13       # 0x3003
cmpl %r12d, %r15d
movl $0xf4240, %eax          # imm = 0xF4240
cmovel %eax, %r15d
cmovel %eax, %r12d
movl %r12d, %esi
shrl %esi
movq %r14, %rdi
callq 0x55bf
movl %r15d, %eax
movq %rax, 0x8(%rsp)
movq %r15, 0x10(%rsp)
testl %r15d, %r15d
je 0x2f11
movq 0x8(%rsp), %r15
movq %rbx, %rbp
leaq 0x8(%rbp), %rsi
movslq (%rbp), %rcx
movq %r14, %rdi
movq %rbp, %rdx
callq 0x5641
addq $0x38, %rbp
decq %r15
jne 0x2ef5
movl $0x0, 0x1008f05(%rip)   # 0x100be20
movq %r14, %rdi
leaq -0xc26(%rip), %rsi      # 0x22ff
leaq 0x1008ef4(%rip), %rdx   # 0x100be20
callq 0x5792
movq 0x10(%rsp), %rbp
cmpl %ebp, 0x1008ee4(%rip)   # 0x100be20
jne 0x2ffe
xorl %eax, %eax
cmpl $0xf423f, %ebp          # imm = 0xF423F
ja 0x2fa8
movl %r12d, 0x1c(%rsp)
movl $0xf4240, %r12d         # imm = 0xF4240
subl %ebp, %r12d
imulq $0x38, 0x8(%rsp), %r15
movq %r12, 0x8(%rsp)
movq 0x20(%rsp), %rbp
leaq (%r15,%rbp), %rsi
leaq (%r15,%rbp), %rdx
addq $-0x8, %rdx
movslq (%rdx), %rcx
movq %r14, %rdi
callq 0x5641
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5685
addq $0x38, %rbp
decq %r12
jne 0x2f6a
movq 0x10(%rsp), %rbp
testl %ebp, %ebp
movl 0x1c(%rsp), %r12d
movq 0x8(%rsp), %rax
je 0x2fd3
movl %eax, %eax
imulq $0x38, %rax, %r15
leaq (%rbx,%r15), %rdx
movslq (%rbx,%r15), %rcx
movq %r14, %rdi
movq %r13, %rsi
callq 0x56bf
testq %rax, %rax
je 0x2ffe
addq $0x38, %r15
cmpq $0x3567e00, %r15        # imm = 0x3567E00
jne 0x2fae
movq %r14, %rdi
callq 0x5639
leal 0x1(%rbp), %eax
cmpl %r12d, %ebp
movl %eax, %r15d
jb 0x2ebe
callq 0x1312
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040