// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %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 0x2c95
leaq 0x18(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdi
callq 0x5410
cmpq $0x1, 0x8(%r14)
je 0x303b
leaq 0x18(%rsp), %rdi
callq 0x549c
movq $-0x20, %rax
leaq 0x811d(%rip), %rcx      # 0xae10
incb 0x20(%rax,%rcx)
addq $0x20, %rax
cmpq $0xffffe0, %rax         # imm = 0xFFFFE0
jb 0x2cf3
movl $0x0, 0x80f3(%rip)      # 0xae00
leaq 0x458f(%rip), %rax      # 0x72a3
movq %rax, 0x10080f5(%rip)   # 0x100ae10
callq 0x12e3
movq %rax, 0x10080f1(%rip)   # 0x100ae18
xorl %r15d, %r15d
movl $0x1388, %eax           # imm = 0x1388
leaq 0x18(%rsp), %r14
leaq 0x305(%rip), %r12       # 0x3040
cmpl %eax, %r15d
movl $0xf4240, %ecx          # imm = 0xF4240
cmovel %ecx, %r15d
cmovel %ecx, %eax
movl %eax, 0x8(%rsp)
movl %eax, %esi
shrl %esi
movq %r14, %rdi
callq 0x5410
movl %r15d, %eax
movq %rax, (%rsp)
testl %r15d, %r15d
je 0x2d89
movq (%rsp), %rbp
movq %rbx, %r13
leaq 0x8(%r13), %rsi
movslq (%r13), %rcx
movq %r14, %rdi
movq %r13, %rdx
callq 0x54a4
addq $0x38, %r13
decq %rbp
jne 0x2d6d
movq %r14, %rdi
callq 0x565b
movq (%rsp), %rdx
leaq (,%rdx,8), %rcx
cmpq %rcx, %rax
jb 0x303b
cmpq %rdx, 0x30(%rsp)
jne 0x303b
movl $0x0, 0x1008065(%rip)   # 0x100ae20
movq %r14, %rdi
leaq -0xa97(%rip), %rsi      # 0x232e
callq 0x55bf
cmpl %r15d, 0x100804f(%rip)  # 0x100ae20
jne 0x303b
movl %r15d, %eax
shrl %eax
movl %eax, (%rsp)
cmpl $0x2, %r15d
jb 0x2e0a
movl (%rsp), %r13d
leal -0x1(%r15), %ebp
movl %ebp, %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x54ef
decl %ebp
decq %r13
jne 0x2ded
cmpl $0x2, %r15d
jb 0x2e42
movl (%rsp), %ebp
leal -0x1(%r15), %r13d
movl %r13d, %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rdx
movslq (%rbx,%rax), %rcx
movq %r14, %rdi
movq %r12, %rsi
callq 0x552e
testq %rax, %rax
jne 0x303b
decl %r13d
decq %rbp
jne 0x2e17
cmpl $0x2, %r15d
jb 0x2e75
movl (%rsp), %r13d
leal -0x1(%r13), %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rdx
movslq (%rbx,%rax), %rcx
movq %r14, %rdi
movq %r12, %rsi
callq 0x552e
testq %rax, %rax
je 0x303b
decq %r13
jne 0x2e4c
movq %r14, %rdi
callq 0x549c
incl %r15d
movl 0x8(%rsp), %eax
cmpl %eax, %r15d
jbe 0x2d3b
callq 0x1312
movq $-0x20, %rax
leaq 0x7f70(%rip), %rcx      # 0xae10
incb 0x20(%rax,%rcx)
addq $0x20, %rax
cmpq $0xffffe0, %rax         # imm = 0xFFFFE0
jb 0x2ea0
movl $0x0, 0x7f46(%rip)      # 0xae00
leaq 0x43f2(%rip), %rax      # 0x72b3
movq %rax, 0x1007f48(%rip)   # 0x100ae10
callq 0x12e3
movq %rax, 0x1007f44(%rip)   # 0x100ae18
leaq 0x8(%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movl $0x3e, %ecx
leaq 0x18(%rsp), %r14
leaq 0x14f(%rip), %r12       # 0x3040
cmpl %ecx, %r13d
movl $0xf4240, %eax          # imm = 0xF4240
cmovel %eax, %r13d
cmovel %eax, %ecx
movl %ecx, (%rsp)
movl %ecx, %esi
shrl %esi
movq %r14, %rdi
callq 0x5410
movl $0x0, %r15d
testl %r13d, %r13d
je 0x2f49
movl %r13d, %r12d
movq %rbx, %rbp
xorl %r15d, %r15d
leaq 0x8(%rbp), %rsi
movslq (%rbp), %rcx
movq %r14, %rdi
movq %rbp, %rdx
callq 0x54a4
incq %r15
addq $0x38, %rbp
cmpq %r15, %r12
jne 0x2f23
leaq 0xf7(%rip), %r12        # 0x3040
movl $0x0, 0x1007ecd(%rip)   # 0x100ae20
movq %r14, %rdi
leaq -0xc28(%rip), %rsi      # 0x2335
leaq 0x1007ebc(%rip), %rdx   # 0x100ae20
callq 0x5606
movq %r13, 0x8(%rsp)
cmpl %r13d, 0x1007eab(%rip)  # 0x100ae20
jne 0x303b
xorl %r13d, %r13d
cmpl $0xf423f, %r15d         # imm = 0xF423F
ja 0x2fd4
movl %r15d, %eax
movl $0xf4240, %r12d         # imm = 0xF4240
subl %r15d, %r12d
imulq $0x38, %rax, %r15
movq 0x10(%rsp), %rbp
xorl %r13d, %r13d
leaq (%r15,%rbp), %rsi
leaq (%r15,%rbp), %rdx
addq $-0x8, %rdx
movslq (%rdx), %rcx
movq %r14, %rdi
callq 0x54a4
movq %r14, %rdi
movq %rbp, %rsi
callq 0x54ef
incq %r13
addq $0x38, %rbp
cmpq %r13, %r12
jne 0x2f9f
leaq 0x6c(%rip), %r12        # 0x3040
cmpl $0xf423f, %r13d         # imm = 0xF423F
ja 0x3009
movl %r13d, %eax
imulq $0x38, %rax, %r15
leaq (%rbx,%r15), %rdx
movslq (%rbx,%r15), %rcx
movq %r14, %rdi
movq %r12, %rsi
callq 0x552e
testq %rax, %rax
je 0x303b
addq $0x38, %r15
cmpq $0x3567e00, %r15        # imm = 0x3567E00
jne 0x2fe4
movq %r14, %rdi
callq 0x549c
movq 0x8(%rsp), %rdx
leal 0x1(%rdx), %eax
movl (%rsp), %ecx
cmpl %ecx, %edx
movl %eax, %r13d
jb 0x2ef1
callq 0x1312
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040