// File: /workspace/github_c_makefile_star2_O1/cyb70289[P]tt/tests/tree.c
// Function: main
int main(void)
{
	char *key[NUM];
	int v[NUM];

	struct tt_bintree bt = {
		.knum	= {
			.size	= 0,	/* Not used */
			.cmp	= keycmp,
			.swap	= NULL,	/* Not used */
		},
		.ops	= NULL,
	};

	tt_bintree_init(&bt);
	printf("\n");

	printf("Insert... ");
	for (int i = 0; i < NUM; i++) {
		key[i] = v2key(i);
		v[i] = i;
		tt_bintree_insert(&bt, key[i], &v[i]);
	}
	printf("Done\n");
	printf("Nodes = %d, height = %d\n", bt._count, tree_height(bt._root));
	printf("\n");

	printf("Walk... ");
	tt_bintree_walk(&bt, NULL, walk);
	printf("Done\n");
	printf("\n");

	struct tt_bintree_node *node = tt_bintree_min(&bt);
	printf("Min: %s -> %d\n", (const char *)node->key, *(int *)node->data);
	node = tt_bintree_max(&bt);
	printf("Max: %s -> %d\n", (const char *)node->key, *(int *)node->data);
	printf("\n");

	printf("Search... ");
	for (int i = 0; i < NUM; i++) {
		node = tt_bintree_search(&bt, key[i]);
		if (!node) {
			printf("Search error\n");
			break;
		}
	}
	printf("Done\n");
	printf("\n");

	printf("Delete... ");
	/* Delete half nodes */
	for (int i = 0; i < NUM; i += 2) {
		node = tt_bintree_search(&bt, key[i]);
		tt_bintree_delete(&bt, node);
		/* Verify deleted */
		if (tt_bintree_search(&bt, key[i])) {
			printf("error\n");
			break;
		}
	}
	/* Verify undeleted */
	for (int i = 1; i < NUM; i += 2) {
		node = tt_bintree_search(&bt, key[i]);
		if (!node) {
			printf("error\n");
			break;
		}
	}
	/* Delete all */
	for (int i = 1; i < NUM; i += 2)
		tt_bintree_delete(&bt, tt_bintree_max(&bt));
	/* Insert & delete again */
	for (int i = 0; i < NUM; i++)
		tt_bintree_insert(&bt, key[i], &v[i]);
	for (int i = 0; i < NUM; i++)
		tt_bintree_delete(&bt, tt_bintree_min(&bt));
	printf("Done\n");
	printf("\n");

	tt_bintree_free(&bt);

	for (int i = 0; i < NUM; i++)
		free(key[i]);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x3058, %rsp           # imm = 0x3058
movq 0x5950(%rip), %rax      # 0x6d70
movq %rsp, %rbx
movq %rax, 0x30(%rbx)
movups 0x5932(%rip), %xmm0     # 0x6d60
movaps %xmm0, 0x20(%rbx)
movups 0x5917(%rip), %xmm0     # 0x6d50
movaps %xmm0, 0x10(%rbx)
movups 0x58fc(%rip), %xmm0     # 0x6d40
movaps %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x2ed0
movl $0xa, %edi
callq 0x1040
leaq 0x2ba4(%rip), %rdi      # 0x4004
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x10b0
movl $0x0, %edi
movl %r14d, %eax
cmpq $0x1a, %r14
jb 0x14ac
xorl %edi, %edi
movl %r14d, %eax
movl %eax, %ecx
movl %eax, %eax
imulq $0x4ec4ec4f, %rax, %rax # imm = 0x4EC4EC4F
shrq $0x23, %rax
leal (%rax,%rax,4), %edx
leal (%rdx,%rdx,4), %edx
addl %eax, %edx
movl %ecx, %esi
subl %edx, %esi
addb $0x61, %sil
movb %sil, 0x46(%rsp,%rdi)
incq %rdi
cmpl $0x2a3, %ecx            # imm = 0x2A3
ja 0x147d
addb $0x61, %al
leal 0x1(%rdi), %ebp
movl %edi, %ecx
movb %al, 0x46(%rsp,%rcx)
addl $0x2, %edi
callq 0x1130
movslq %ebp, %rcx
movq %rax, %rdx
movb 0x45(%rsp,%rcx), %sil
movb %sil, (%rdx)
incq %rdx
decq %rcx
jne 0x14c5
movb $0x0, (%rdx)
movq %rax, 0x50(%rsp,%r14,8)
leaq (%rsp,%r14,4), %rdx
addq $0x2050, %rdx           # imm = 0x2050
movl %r14d, (%rdx)
movq 0x20(%rsp), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x18(%rcx)
incq %r14
cmpq $0x400, %r14            # imm = 0x400
jne 0x146a
leaq 0x2b62(%rip), %r14      # 0x4072
movq %r14, %rdi
callq 0x1060
movq %rsp, %rbx
movl 0x30(%rbx), %ebp
movq 0x28(%rbx), %rdi
callq 0x17bf
leaq 0x2ae1(%rip), %rdi      # 0x400f
xorl %r15d, %r15d
movl %ebp, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
leaq 0x2adb(%rip), %rdi      # 0x4028
xorl %eax, %eax
callq 0x10b0
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rdi
leaq 0x28c(%rip), %rdx       # 0x17ef
xorl %esi, %esi
callq *0x28(%rax)
movq %r14, %rdi
callq 0x1060
movl $0xa, %edi
callq 0x1040
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rdi
callq *(%rax)
movq (%rax), %rsi
movq 0x8(%rax), %rax
movl (%rax), %edx
leaq 0x2a9d(%rip), %rdi      # 0x4031
xorl %eax, %eax
callq 0x10b0
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rdi
callq *0x8(%rax)
movq (%rax), %rsi
movq 0x8(%rax), %rax
movl (%rax), %edx
leaq 0x2a8a(%rip), %rdi      # 0x4040
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
leaq 0x2a81(%rip), %rdi      # 0x404f
xorl %eax, %eax
callq 0x10b0
movq 0x50(%rsp,%r15,8), %rsi
movq 0x20(%rsp), %rax
movq %rbx, %rdi
callq *0x10(%rax)
testq %rax, %rax
je 0x15f8
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x15d5
jmp 0x1604
leaq 0x2a66(%rip), %rdi      # 0x4065
callq 0x1060
leaq 0x2a67(%rip), %rdi      # 0x4072
callq 0x1060
movl $0xa, %edi
callq 0x1040
leaq 0x2a39(%rip), %rdi      # 0x405a
xorl %eax, %eax
callq 0x10b0
movq $-0x2, %r15
movq %rsp, %rbx
movq 0x60(%rsp,%r15,8), %r14
movq 0x20(%rsp), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x20(%rcx)
movq 0x20(%rsp), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x10(%rax)
testq %rax, %rax
jne 0x1675
addq $0x2, %r15
cmpq $0x3fd, %r15            # imm = 0x3FD
jbe 0x1632
jmp 0x1681
leaq 0x29f0(%rip), %rdi      # 0x406c
callq 0x1060
movq $-0x1, %r14
movq %rsp, %rbx
movq 0x60(%rsp,%r14,8), %rsi
movq 0x20(%rsp), %rax
movq %rbx, %rdi
callq *0x10(%rax)
testq %rax, %rax
je 0x16af
addq $0x2, %r14
cmpq $0x3fd, %r14            # imm = 0x3FD
jbe 0x168b
jmp 0x16bb
leaq 0x29b6(%rip), %rdi      # 0x406c
callq 0x1060
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rsp, %rbx
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdi
callq *0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x20(%rcx)
addl $0x2, %ebp
cmpl $0x3fe, %ebp            # imm = 0x3FE
jb 0x16c3
xorl %r14d, %r14d
movq %rsp, %rbx
movq 0x50(%rsp,%r14,2), %rsi
leaq (%rsp,%r14), %rdx
addq $0x2050, %rdx           # imm = 0x2050
movq 0x20(%rsp), %rax
movq %rbx, %rdi
callq *0x18(%rax)
addq $0x4, %r14
cmpq $0x1000, %r14           # imm = 0x1000
jne 0x16ef
movl $0x400, %ebp            # imm = 0x400
movq %rsp, %rbx
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdi
callq *(%rax)
movq 0x20(%rsp), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x20(%rcx)
decl %ebp
jne 0x171f
leaq 0x292e(%rip), %rdi      # 0x4072
callq 0x1060
movl $0xa, %edi
callq 0x1040
movq %rsp, %rdi
callq 0x2f61
xorl %ebx, %ebx
movq 0x50(%rsp,%rbx,8), %rdi
callq 0x1030
incq %rbx
cmpq $0x400, %rbx            # imm = 0x400
jne 0x175d
xorl %eax, %eax
addq $0x3058, %rsp           # imm = 0x3058
popq %rbx
popq %r14
popq %r15
popq %rbp
retq