// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/common/tree.c
// Function: tt_rbtree_insert
static int tt_rbtree_insert(struct tt_bintree *tree, const void *key,
		const void *v)
{
	struct tt_bintree_node *z = calloc(1, sizeof(struct tt_bintree_node));
	if (!z)
		return TT_ENOMEM;
	z->key = (void *)key;
	z->data = (void *)v;
	z->ext.color = TT_BINTREE_RED;

	/* Insert as normal binary search tree */
	struct tt_bintree_node *y = NULL, *x = tree->_root;
	while (x) {
		y = x;
		if (tree->knum.cmp(&tree->knum, z->key, x->key) < 0)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if (!y)
		tree->_root = z;	/* Empty tree */
	else if (tree->knum.cmp(&tree->knum, z->key, y->key) < 0)
		y->left = z;
	else
		y->right = z;

	/* Rotate to maintain red-black property */
	while (z->parent && z->parent->ext.color == TT_BINTREE_RED) {
		if (z->parent == z->parent->parent->left) {
			y = z->parent->parent->right;
			if (y && y->ext.color == TT_BINTREE_RED) {
				z->parent->ext.color = TT_BINTREE_BLACK;
				y->ext.color = TT_BINTREE_BLACK;
				z->parent->parent->ext.color = TT_BINTREE_RED;
				z = z->parent->parent;
			} else if (z == z->parent->right) {
				z = z->parent;
				tt_rbtree_rotate_left(tree, z);
			} else {
				z->parent->ext.color = TT_BINTREE_BLACK;
				z->parent->parent->ext.color = TT_BINTREE_RED;
				tt_rbtree_rotate_right(tree, z->parent->parent);
			}
		} else {
			y = z->parent->parent->left;
			if (y && y->ext.color == TT_BINTREE_RED) {
				z->parent->ext.color = TT_BINTREE_BLACK;
				y->ext.color = TT_BINTREE_BLACK;
				z->parent->parent->ext.color = TT_BINTREE_RED;
				z = z->parent->parent;
			} else if (z == z->parent->left) {
				z = z->parent;
				tt_rbtree_rotate_right(tree, z);
			} else {
				z->parent->ext.color = TT_BINTREE_BLACK;
				z->parent->parent->ext.color = TT_BINTREE_RED;
				tt_rbtree_rotate_left(tree, z->parent->parent);
			}
		}
	}
	tree->_root->ext.color = TT_BINTREE_BLACK;

	tree->_count++;
	return 0;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x10e0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x652c
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x686d
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rax
movl $0x0, 0x28(%rax)
movq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x65c1
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq (%rcx), %rsi
movq 0x10(%rsp), %rcx
movq (%rcx), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x65b1
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x65bf
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x656a
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, 0x18(%rsp)
jne 0x65e7
movq 0x20(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x28(%rax)
jmp 0x662c
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq (%rcx), %rsi
movq 0x18(%rsp), %rcx
movq (%rcx), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x661c
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0x662a
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
jmp 0x662c
jmp 0x662e
movq 0x20(%rsp), %rcx
xorl %eax, %eax
cmpq $0x0, 0x10(%rcx)
movb %al, 0xf(%rsp)
je 0x6654
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, 0x28(%rax)
sete %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x6661
jmp 0x6847
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jne 0x6763
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x66ee
movq 0x18(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x66ee
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl $0x1, 0x28(%rax)
movq 0x18(%rsp), %rax
movl $0x1, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movl $0x0, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x675e
movq 0x20(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x20(%rcx), %rax
jne 0x6721
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x6e40
jmp 0x675c
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl $0x1, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movl $0x0, 0x28(%rax)
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x6f10
jmp 0x675e
jmp 0x6842
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x67d0
movq 0x18(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x67d0
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl $0x1, 0x28(%rax)
movq 0x18(%rsp), %rax
movl $0x1, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movl $0x0, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x6840
movq 0x20(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jne 0x6803
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x6f10
jmp 0x683e
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl $0x1, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movl $0x0, 0x28(%rax)
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x6e40
jmp 0x6840
jmp 0x6842
jmp 0x662e
movq 0x38(%rsp), %rax
movq 0x28(%rax), %rax
movl $0x1, 0x28(%rax)
movq 0x38(%rsp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)