// File: /workspace/github_cpp_makefile_star2_O3/funny-falcon[P]fanom_hash/./check.inc.cpp
// Function: check_table(table*, int)
int check_table(table *tbl, int use_32) {
	uint32_t maxchain = 0;
	double expectedmaxchain = 2 * log(tbl->bins) / log(log(tbl->bins));
	std::map<uint64_t, uint32_t> counter;
	int ret = 0;
	int i;
	for (i = 0; i < tbl->bins; i++) {
		uint32_t chain = 0;
		entry* e = tbl->entries[i];
		while (e != NULL) {
			chain++;
			checksum_add(e->str, e->len);
			counter[e->hash]++;
			e = e->next;
		}
		if (chain > maxchain)
			maxchain = chain;
	}
	printf("checksum %08x %08x\n", checksum[0], checksum[1]);
	printf("maxchain: %u (expected %f)", maxchain, expectedmaxchain);
	if (maxchain > expectedmaxchain*2) {
		printf("(!!! maxchain overflow)");
		ret = 1;
	}
	printf("\n");
	if (counter.size() != tbl->size) {
		double ncoll = tbl->size - (uint32_t)counter.size();
		double expected = 0;
		uint32_t maxcnt = 0;
		if (use_32) {
			double d = pow(2,32);
			double n = tbl->size;
			/* https://en.wikipedia.org/wiki/Birthday_problem#Collision_counting */
			expected = n - d + d*pow((d-1)/d, n);
			if (expected > 0.01 && ncoll <= 2) {
				ret = 0;
			} else {
				ret = expected*4 < ncoll;
			}
		} else {
			ret = 1;
		}
		for (auto& pair: counter) {
			if (pair.second-1 > maxcnt) {
				maxcnt = pair.second-1;
			}
		}
		printf("Has full hash collision: %u same hashes for %u values (expected %f)\n",
				(uint32_t)ncoll, tbl->size, expected);
		if (maxcnt > 1) {
			printf("Max full collision: %u\n", maxcnt);
			ret = 1;
		}
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, 0x14(%rsp)
movq %rdi, %rbx
movl 0x4(%rdi), %eax
cvtsi2sd %rax, %xmm0
callq 0x2110
movsd %xmm0, (%rsp)
movl 0x4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x2110
callq 0x2110
movsd %xmm0, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movl 0x4(%rbx), %eax
movl $0x0, %r15d
testl %eax, %eax
je 0x26d4
xorl %ebp, %ebp
leaq 0x18(%rsp), %r12
xorl %r15d, %r15d
movq 0x8(%rbx), %rcx
movq (%rcx,%rbp,8), %r13
movl $0x0, %r14d
testq %r13, %r13
je 0x26c3
xorl %r14d, %r14d
leaq 0x20(%r13), %rdi
movq 0x18(%r13), %rsi
callq 0x2568
movq %r12, %rdi
movq %r13, %rsi
callq 0x32e8
incl (%rax)
incl %r14d
movq 0x8(%r13), %r13
testq %r13, %r13
jne 0x269a
movl 0x4(%rbx), %eax
cmpl %r15d, %r14d
cmoval %r14d, %r15d
incq %rbp
movl %eax, %ecx
cmpq %rcx, %rbp
jb 0x2684
movsd (%rsp), %xmm0
addsd %xmm0, %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movl 0x4a92(%rip), %esi      # 0x7180
movl 0x4a90(%rip), %edx      # 0x7184
leaq 0x19dc(%rip), %rdi      # 0x40d7
xorl %eax, %eax
callq 0x2030
leaq 0x19e2(%rip), %rdi      # 0x40eb
movl %r15d, %esi
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x2030
movl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd (%rsp), %xmm1
addsd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movl $0x0, %r12d
jbe 0x274c
leaq 0x19c7(%rip), %rdi      # 0x4106
xorl %eax, %eax
callq 0x2030
movl $0x1, %r12d
movl $0xa, %edi
callq 0x21e0
movq 0x40(%rsp), %rcx
movl (%rbx), %eax
cmpq %rax, %rcx
je 0x286f
movl %eax, %r15d
subl %ecx, %r15d
cmpl $0x0, 0x14(%rsp)
leaq 0x20(%rsp), %r14
je 0x27f3
movl %r15d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, (%rsp)
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x186e(%rip), %xmm0     # 0x4008
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x1864(%rip), %xmm0     # 0x4010
callq 0x2250
mulsd 0x185f(%rip), %xmm0     # 0x4018
addsd 0x8(%rsp), %xmm0
ucomisd 0x1859(%rip), %xmm0     # 0x4020
setbe %al
cmpl $0x3, %r15d
setae %cl
orb %al, %cl
movsd 0x184d(%rip), %xmm1     # 0x4028
mulsd %xmm0, %xmm1
movsd (%rsp), %xmm2
ucomisd %xmm1, %xmm2
seta %al
andb %cl, %al
movzbl %al, %r12d
jmp 0x27fd
movl $0x1, %r12d
xorpd %xmm0, %xmm0
movq 0x30(%rsp), %rax
cmpq %r14, %rax
je 0x285c
movsd %xmm0, (%rsp)
xorl %ebp, %ebp
movl %ebp, %ecx
movl 0x28(%rax), %ebp
decl %ebp
cmpl %ecx, %ebp
cmovbel %ecx, %ebp
movq %rax, %rdi
callq 0x20e0
cmpq %r14, %rax
jne 0x280e
movl (%rbx), %edx
leaq 0x18ee(%rip), %rdi      # 0x411e
movl %r15d, %esi
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x2030
cmpl $0x1, %ebp
jbe 0x286f
leaq 0x1918(%rip), %rdi      # 0x4163
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
movl $0x1, %r12d
jmp 0x286f
movl (%rbx), %edx
leaq 0x18b9(%rip), %rdi      # 0x411e
movl %r15d, %esi
movb $0x1, %al
callq 0x2030
leaq 0x18(%rsp), %rdi
callq 0x3358
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3358
movq %rbx, %rdi
callq 0x2260