// File: /workspace/github_cpp_makefile_star2_O1/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)
cmpl $0x0, 0x4(%rbx)
movl $0x0, %r15d
je 0x26c2
xorl %ebp, %ebp
leaq 0x18(%rsp), %r12
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movq (%rax,%rbp,8), %r13
movl $0x0, %r14d
testq %r13, %r13
je 0x26b0
xorl %r14d, %r14d
leaq 0x20(%r13), %rdi
movq 0x18(%r13), %rsi
callq 0x2559
movq %r12, %rdi
movq %r13, %rsi
callq 0x327c
incl (%rax)
incl %r14d
movq 0x8(%r13), %r13
testq %r13, %r13
jne 0x268a
cmpl %r15d, %r14d
cmoval %r14d, %r15d
incq %rbp
movl 0x4(%rbx), %eax
cmpq %rax, %rbp
jb 0x2674
movsd (%rsp), %xmm0
addsd %xmm0, %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movl 0x4aa4(%rip), %esi      # 0x7180
movl 0x4aa2(%rip), %edx      # 0x7184
leaq 0x19ee(%rip), %rdi      # 0x40d7
xorl %eax, %eax
callq 0x2030
leaq 0x19f4(%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 0x273a
leaq 0x19d9(%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 0x2855
movl %eax, %r15d
subl %ecx, %r15d
cmpl $0x0, 0x14(%rsp)
leaq 0x20(%rsp), %r14
je 0x27ea
movl %r15d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x8(%rsp)
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x187b(%rip), %xmm0     # 0x4008
addsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movsd 0x1872(%rip), %xmm0     # 0x4010
callq 0x2250
mulsd 0x186d(%rip), %xmm0     # 0x4018
addsd (%rsp), %xmm0
ucomisd 0x1868(%rip), %xmm0     # 0x4020
setbe %al
cmpl $0x3, %r15d
setae %cl
orb %al, %cl
movsd 0x185c(%rip), %xmm1     # 0x4028
movsd %xmm0, (%rsp)
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
andb %cl, %al
movzbl %al, %r12d
jmp 0x27f9
movl $0x1, %r12d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rax
cmpq %r14, %rax
je 0x2820
xorl %ecx, %ecx
movl 0x28(%rax), %ebp
decl %ebp
cmpl %ecx, %ebp
cmovbel %ecx, %ebp
movq %rax, %rdi
callq 0x20e0
movl %ebp, %ecx
cmpq %r14, %rax
jne 0x2805
jmp 0x2822
xorl %ebp, %ebp
movl (%rbx), %edx
leaq 0x18f3(%rip), %rdi      # 0x411e
movl %r15d, %esi
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x2030
cmpl $0x1, %ebp
jbe 0x2855
leaq 0x191d(%rip), %rdi      # 0x4163
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
movl $0x1, %r12d
leaq 0x18(%rsp), %rdi
callq 0x32ee
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 0x32ee
movq %rbx, %rdi
callq 0x2260