// File: amadvance[P]tommyds/check.c
// Function: test_trie
void test_trie(void)
{
	tommy_trie trie;
	tommy_allocator alloc;
	struct object_trie* OBJ;
	struct object_trie DUP[2];
	unsigned i;
	const unsigned size = TOMMY_SIZE * 4;

	OBJ = malloc(size * sizeof(struct object_trie));

	for(i=0;i<size;++i)
		OBJ[i].value = i;

	START("trie");
	tommy_allocator_init(&alloc, TOMMY_TRIE_BLOCK_SIZE, TOMMY_TRIE_BLOCK_SIZE);
	tommy_trie_init(&trie, &alloc);

	/* insert */
	for(i=0;i<size;++i)
		tommy_trie_insert(&trie, &OBJ[i].node, &OBJ[i], OBJ[i].value);

	if (tommy_trie_memory_usage(&trie) < size * sizeof(tommy_trie_node))
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	if (tommy_allocator_memory_usage(&alloc) < trie.node_count * TOMMY_TRIE_BLOCK_SIZE)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	if (tommy_trie_count(&trie) != size)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	/* insert duplicate */
	for(i=0;i<2;++i) {
		DUP[i].value = 0;
		tommy_trie_insert(&trie, &DUP[i].node, &DUP[i], DUP[i].value);
	}

	/* search present */
	for(i=0;i<size/2;++i)
		if (tommy_trie_search(&trie, OBJ[i].value) == 0)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

	/* remove first duplicate */
	tommy_trie_remove_existing(&trie, &DUP[0].node);

	/* remove existing */
	for(i=0;i<size/2;++i)
		tommy_trie_remove_existing(&trie, &OBJ[i].node);

	/* remove missing using the same bucket of the duplicate */
	if (tommy_trie_remove(&trie, 1) != 0)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	/* search missing using the same bucket of the duplicate */
	if (tommy_trie_search(&trie, 1) != 0)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	/* remove second duplicate */
	tommy_trie_remove_existing(&trie, &DUP[1].node);

	/* remove missing */
	for(i=0;i<size/2;++i)
		if (tommy_trie_remove(&trie, OBJ[i].value) != 0)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

	/* search missing */
	for(i=0;i<size/2;++i)
		if (tommy_trie_search(&trie, OBJ[i].value) != 0)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

	/* remove present */
	for(i=0;i<size/2;++i)
		if (tommy_trie_remove(&trie, OBJ[size/2+i].value) == 0)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

	tommy_allocator_done(&alloc);
	STOP();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl $0x3d0900, -0x1c8(%rbp) # imm = 0x3D0900
movl $0xd59f800, %edi        # imm = 0xD59F800
callq 0x10b0
movq %rax, -0x148(%rbp)
movl $0x0, -0x1c4(%rbp)
cmpl $0x3d0900, -0x1c4(%rbp) # imm = 0x3D0900
jae 0x3f79
movl -0x1c4(%rbp), %ecx
movq -0x148(%rbp), %rax
movl -0x1c4(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x3f40
leaq 0x635f(%rip), %rdi      # 0xa2df
callq 0x13e0
leaq -0x140(%rbp), %rdi
movl $0x40, %edx
movq %rdx, %rsi
callq 0x55d0
leaq -0x118(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x6ac0
movl $0x0, -0x1c4(%rbp)
cmpl $0x3d0900, -0x1c4(%rbp) # imm = 0x3D0900
jae 0x4022
movq -0x148(%rbp), %rsi
movl -0x1c4(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x148(%rbp), %rdx
movl -0x1c4(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x148(%rbp), %rax
movl -0x1c4(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x118(%rbp), %rdi
callq 0x6b30
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x3fb6
leaq -0x118(%rbp), %rdi
callq 0x7260
cmpq $0x7a12000, %rax        # imm = 0x7A12000
jae 0x403b
callq 0x1040
leaq -0x140(%rbp), %rdi
callq 0x58b0
movq -0x10(%rbp), %rcx
shlq $0x6, %rcx
cmpq %rcx, %rax
jae 0x4059
callq 0x1040
leaq -0x118(%rbp), %rdi
callq 0x4340
cmpq $0x3d0900, %rax         # imm = 0x3D0900
je 0x4072
callq 0x1040
movl $0x0, -0x1c4(%rbp)
cmpl $0x2, -0x1c4(%rbp)
jae 0x410a
movl -0x1c4(%rbp), %eax
movl %eax, %ecx
leaq -0x1c0(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movl -0x1c4(%rbp), %eax
leaq -0x1c0(%rbp), %rsi
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movl -0x1c4(%rbp), %eax
leaq -0x1c0(%rbp), %rdx
imulq $0x38, %rax, %rax
addq %rax, %rdx
movl -0x1c4(%rbp), %eax
movl %eax, %ecx
leaq -0x1c0(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x118(%rbp), %rdi
callq 0x6b30
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x407c
movl $0x0, -0x1c4(%rbp)
cmpl $0x1e8480, -0x1c4(%rbp) # imm = 0x1E8480
jae 0x4161
movq -0x148(%rbp), %rax
movl -0x1c4(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x4360
cmpq $0x0, %rax
jne 0x414e
callq 0x1040
jmp 0x4150
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x4114
leaq -0x1c0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x118(%rbp), %rdi
callq 0x70a0
movl $0x0, -0x1c4(%rbp)
cmpl $0x1e8480, -0x1c4(%rbp) # imm = 0x1E8480
jae 0x41c3
movq -0x148(%rbp), %rsi
movl -0x1c4(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
leaq -0x118(%rbp), %rdi
callq 0x70a0
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x4182
leaq -0x118(%rbp), %rdi
movl $0x1, %esi
callq 0x6d70
cmpq $0x0, %rax
je 0x41df
callq 0x1040
leaq -0x118(%rbp), %rdi
movl $0x1, %esi
callq 0x4360
cmpq $0x0, %rax
je 0x41fb
callq 0x1040
leaq -0x1c0(%rbp), %rsi
addq $0x38, %rsi
addq $0x8, %rsi
leaq -0x118(%rbp), %rdi
callq 0x70a0
movl $0x0, -0x1c4(%rbp)
cmpl $0x1e8480, -0x1c4(%rbp) # imm = 0x1E8480
jae 0x426d
movq -0x148(%rbp), %rax
movl -0x1c4(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x6d70
cmpq $0x0, %rax
je 0x425a
callq 0x1040
jmp 0x425c
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x4220
movl $0x0, -0x1c4(%rbp)
cmpl $0x1e8480, -0x1c4(%rbp) # imm = 0x1E8480
jae 0x42c4
movq -0x148(%rbp), %rax
movl -0x1c4(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x4360
cmpq $0x0, %rax
je 0x42b1
callq 0x1040
jmp 0x42b3
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x4277
movl $0x0, -0x1c4(%rbp)
cmpl $0x1e8480, -0x1c4(%rbp) # imm = 0x1E8480
jae 0x4323
movq -0x148(%rbp), %rax
movl -0x1c4(%rbp), %ecx
addl $0x1e8480, %ecx         # imm = 0x1E8480
movl %ecx, %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
leaq -0x118(%rbp), %rdi
callq 0x6d70
cmpq $0x0, %rax
jne 0x4310
callq 0x1040
jmp 0x4312
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x42ce
leaq -0x140(%rbp), %rdi
callq 0x5670
callq 0x1460
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopl (%rax)