// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x3078, %rsp           # imm = 0x3078
movl $0x0, 0x3074(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x7b3a(%rip), %rsi      # 0x8da8
movl $0x38, %edx
callq 0x1100
leaq 0x38(%rsp), %rdi
callq 0x48e0
leaq 0x4f22(%rip), %rdi      # 0x61ab
movb $0x0, %al
callq 0x1090
leaq 0x4d6d(%rip), %rdi      # 0x6004
movb $0x0, %al
callq 0x1090
movl $0x0, 0x34(%rsp)
cmpl $0x400, 0x34(%rsp)      # imm = 0x400
jge 0x130b
movl 0x34(%rsp), %edi
callq 0x16e0
movq %rax, %rcx
movslq 0x34(%rsp), %rax
movq %rcx, 0x1070(%rsp,%rax,8)
movl 0x34(%rsp), %ecx
movslq 0x34(%rsp), %rax
movl %ecx, 0x70(%rsp,%rax,4)
movslq 0x34(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rsi
movslq 0x34(%rsp), %rax
leaq 0x70(%rsp), %rdx
shlq $0x2, %rax
addq %rax, %rdx
leaq 0x38(%rsp), %rdi
callq 0x17b0
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x12a6
leaq 0x4cfd(%rip), %rdi      # 0x600f
movb $0x0, %al
callq 0x1090
movl 0x68(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
callq 0x17f0
movl 0x8(%rsp), %esi
movl %eax, %edx
leaq 0x4cdd(%rip), %rdi      # 0x6015
movb $0x0, %al
callq 0x1090
leaq 0x4e65(%rip), %rdi      # 0x61ab
movb $0x0, %al
callq 0x1090
leaq 0x4cda(%rip), %rdi      # 0x602e
movb $0x0, %al
callq 0x1090
leaq 0x38(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x545(%rip), %rdx       # 0x18b0
callq 0x1870
leaq 0x4c98(%rip), %rdi      # 0x600f
movb $0x0, %al
callq 0x1090
leaq 0x4e26(%rip), %rdi      # 0x61ab
movb $0x0, %al
callq 0x1090
leaq 0x38(%rsp), %rdi
callq 0x1910
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rsi
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
leaq 0x4c82(%rip), %rdi      # 0x6037
movb $0x0, %al
callq 0x1090
leaq 0x38(%rsp), %rdi
callq 0x1930
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rsi
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
leaq 0x4c61(%rip), %rdi      # 0x6046
movb $0x0, %al
callq 0x1090
leaq 0x4db8(%rip), %rdi      # 0x61ab
movb $0x0, %al
callq 0x1090
leaq 0x4c54(%rip), %rdi      # 0x6055
movb $0x0, %al
callq 0x1090
movl $0x0, 0x24(%rsp)
cmpl $0x400, 0x24(%rsp)      # imm = 0x400
jge 0x145d
movslq 0x24(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x1950
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x144e
leaq 0x4c1b(%rip), %rdi      # 0x6060
movb $0x0, %al
callq 0x1090
jmp 0x145d
jmp 0x1450
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1410
leaq 0x4bab(%rip), %rdi      # 0x600f
movb $0x0, %al
callq 0x1090
leaq 0x4d39(%rip), %rdi      # 0x61ab
movb $0x0, %al
callq 0x1090
leaq 0x4bee(%rip), %rdi      # 0x606e
movb $0x0, %al
callq 0x1090
movl $0x0, 0x20(%rsp)
cmpl $0x400, 0x20(%rsp)      # imm = 0x400
jge 0x1500
movslq 0x20(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x1950
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdi
callq 0x1980
movslq 0x20(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x1950
cmpq $0x0, %rax
je 0x14f1
leaq 0x4b7f(%rip), %rdi      # 0x6067
movb $0x0, %al
callq 0x1090
jmp 0x1500
jmp 0x14f3
movl 0x20(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x20(%rsp)
jmp 0x148f
movl $0x1, 0x1c(%rsp)
cmpl $0x400, 0x1c(%rsp)      # imm = 0x400
jge 0x1555
movslq 0x1c(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x1950
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x1546
leaq 0x4b2a(%rip), %rdi      # 0x6067
movb $0x0, %al
callq 0x1090
jmp 0x1555
jmp 0x1548
movl 0x1c(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1508
movl $0x1, 0x18(%rsp)
cmpl $0x400, 0x18(%rsp)      # imm = 0x400
jge 0x158b
leaq 0x38(%rsp), %rdi
callq 0x1930
movq %rax, %rsi
leaq 0x38(%rsp), %rdi
callq 0x1980
movl 0x18(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x18(%rsp)
jmp 0x155d
movl $0x0, 0x14(%rsp)
cmpl $0x400, 0x14(%rsp)      # imm = 0x400
jge 0x15d2
movslq 0x14(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rsi
movslq 0x14(%rsp), %rax
leaq 0x70(%rsp), %rdx
shlq $0x2, %rax
addq %rax, %rdx
leaq 0x38(%rsp), %rdi
callq 0x17b0
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x1593
movl $0x0, 0x10(%rsp)
cmpl $0x400, 0x10(%rsp)      # imm = 0x400
jge 0x1608
leaq 0x38(%rsp), %rdi
callq 0x1910
movq %rax, %rsi
leaq 0x38(%rsp), %rdi
callq 0x1980
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x15da
leaq 0x4a00(%rip), %rdi      # 0x600f
movb $0x0, %al
callq 0x1090
leaq 0x4b8e(%rip), %rdi      # 0x61ab
movb $0x0, %al
callq 0x1090
leaq 0x38(%rsp), %rdi
callq 0x49c0
movl $0x0, 0xc(%rsp)
cmpl $0x400, 0xc(%rsp)       # imm = 0x400
jge 0x165f
movslq 0xc(%rsp), %rax
movq 0x1070(%rsp,%rax,8), %rdi
callq 0x1030
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x1636
xorl %eax, %eax
addq $0x3078, %rsp           # imm = 0x3078
retq
nopl (%rax)