// File: attractivechaos[P]udb2/khashl/test-block.c
// Function: test_int
KHASHL_CMAP_INIT(, blockmap_t, blockmap, udb_data_t, int, hash_fn_block, hash_eq_block)

uint32_t test_int(uint32_t n, uint32_t x0)
{
	uint32_t i, x, z = 0;
	khint_t k;
	udb_data_t t0, t;
	uint8_t block[MAX_BLOCK_LEN];
	blockmap_t *h;

	t0.data = block;
	h = blockmap_init();
	for (i = 0, x = x0; i < n; ++i) {
		khint_t k;
		int absent;
		x = hash32(x);
		t0.len = get_key_block(n, x, t0.data);
		k = blockmap_put(h, t0, &absent);
		if (absent) {
			t.len = t0.len;
			t.data = (uint8_t*)malloc(t.len);
			memcpy(t.data, t0.data, t.len);
			kh_key(h, k) = t;
			kh_val(h, k) = 0;
		}
		z += ++kh_val(h, k);
	}
	fprintf(stderr, "# unique keys: %d; checksum: %u; capacity: %u\n", kh_size(h), z, kh_capacity(h));
	x = kh_size(h);
	for (k = 0; k != kh_end(h); ++k)
		if (kh_exist(h, k))
			free(kh_key(h, k).data);
	blockmap_destroy(h);
	return x;
}

// Assembly:
subq $0x78, %rsp
movl %edi, 0x74(%rsp)
movl %esi, 0x70(%rsp)
movl $0x0, 0x64(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x58(%rsp)
callq 0x19d0
movq %rax, 0x28(%rsp)
movl $0x0, 0x6c(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x68(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0x74(%rsp), %eax
jae 0x18ac
movl 0x68(%rsp), %edi
callq 0x1270
movl %eax, 0x68(%rsp)
movl 0x74(%rsp), %edi
movl 0x68(%rsp), %esi
movq 0x58(%rsp), %rdx
callq 0x12e0
movl %eax, 0x50(%rsp)
movq 0x28(%rsp), %rdi
movl 0x50(%rsp), %esi
movq 0x58(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x1e60
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x1877
movl 0x50(%rsp), %eax
movl %eax, 0x40(%rsp)
movslq 0x40(%rsp), %rdi
callq 0x10a0
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movq 0x58(%rsp), %rsi
movslq 0x40(%rsp), %rdx
callq 0x1090
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x24(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x40(%rsp), %rcx
movq %rcx, (%rax)
movq 0x48(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x24(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x10(%rax)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rcx
movl 0x24(%rsp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movl 0x10(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x10(%rcx)
addl 0x64(%rsp), %eax
movl %eax, 0x64(%rsp)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x17b8
movq 0x3745(%rip), %rax      # 0x4ff8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x18(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x18ef
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0xc(%rsp)
jmp 0x18f7
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x18f7
movl 0x1c(%rsp), %ecx
movl 0x18(%rsp), %edx
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %r8d
leaq 0x1765(%rip), %rsi      # 0x3075
movb $0x0, %al
callq 0x1080
movq 0x28(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x68(%rsp)
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1953
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x4(%rsp)
jmp 0x195b
xorl %eax, %eax
movl %eax, 0x4(%rsp)
jmp 0x195b
movl 0x8(%rsp), %eax
movl 0x4(%rsp), %ecx
cmpl %ecx, %eax
je 0x19bc
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x60(%rsp), %ecx
shrl $0x5, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl 0x60(%rsp), %ecx
andl $0x1f, %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x19aa
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x60(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x1030
jmp 0x19ac
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x192b
movq 0x28(%rsp), %rdi
callq 0x1a00
movl 0x68(%rsp), %eax
addq $0x78, %rsp
retq
nop