// File: /workspace/github_c_makefile_star2_O3/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movl $0x1, %edi
movl $0x30, %esi
callq 0x10e0
testq %rax, %rax
je 0x4244
movq %rax, %r14
movq %r12, (%rax)
movq %r15, 0x8(%rax)
leaq 0x28(%rbx), %r15
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x424b
movq %rax, %r12
movq (%r14), %rsi
movq (%rax), %rdx
movq %rbx, %rdi
callq *0x8(%rbx)
notl %eax
shrl $0x1f, %eax
movq 0x18(%r12,%rax,8), %rax
testq %rax, %rax
jne 0x402d
movq %r12, 0x10(%r14)
movq (%r14), %rsi
movq (%r12), %rdx
movq %rbx, %rdi
callq *0x8(%rbx)
notl %eax
shrl $0x1f, %eax
movq %r14, 0x18(%r12,%rax,8)
movq 0x10(%r14), %rcx
testq %rcx, %rcx
je 0x424e
movq %r14, %rdx
addq $0x10, %rdx
movl $0x1, %eax
cmpl $0x0, 0x28(%rcx)
jne 0x424e
movq 0x10(%rcx), %rsi
movq 0x18(%rsi), %rdi
cmpq %rdi, %rcx
je 0x410c
testq %rdi, %rdi
je 0x40a5
cmpl $0x0, 0x28(%rdi)
je 0x418c
movq 0x18(%rcx), %rdi
cmpq %rdi, %r14
je 0x41ac
movl $0x1, 0x28(%rcx)
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
movl $0x0, 0x28(%rcx)
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
movq 0x20(%rcx), %rdx
movq 0x18(%rdx), %rsi
movq %rsi, 0x20(%rcx)
testq %rsi, %rsi
je 0x40e3
movq %rcx, 0x10(%rsi)
movq 0x10(%rcx), %rdi
movq %rdi, 0x10(%rdx)
movq %r15, %rsi
testq %rdi, %rdi
je 0x4103
leaq 0x18(%rdi), %r8
leaq 0x20(%rdi), %rsi
cmpq %rcx, 0x18(%rdi)
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %rcx, 0x18(%rdx)
jmp 0x4180
movq 0x20(%rsi), %rdi
testq %rdi, %rdi
je 0x411b
cmpl $0x0, 0x28(%rdi)
je 0x418c
movq 0x20(%rcx), %rdi
cmpq %rdi, %r14
je 0x41cf
movl $0x1, 0x28(%rcx)
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
movl $0x0, 0x28(%rcx)
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
movq 0x18(%rcx), %rdx
movq 0x20(%rdx), %rsi
movq %rsi, 0x18(%rcx)
testq %rsi, %rsi
je 0x4159
movq %rcx, 0x10(%rsi)
movq 0x10(%rcx), %rdi
movq %rdi, 0x10(%rdx)
movq %r15, %rsi
testq %rdi, %rdi
je 0x4179
leaq 0x18(%rdi), %r8
leaq 0x20(%rdi), %rsi
cmpq %rcx, 0x18(%rdi)
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %rcx, 0x20(%rdx)
movq %rdx, 0x10(%rcx)
movq %r14, %rcx
jmp 0x422e
movl %eax, 0x28(%rcx)
movl %eax, 0x28(%rdi)
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
movl $0x0, 0x28(%rcx)
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
jmp 0x422e
movq 0x20(%rdi), %rdx
movq %rdx, 0x18(%rcx)
testq %rdx, %rdx
je 0x41f2
movq %rcx, 0x10(%rdx)
movq 0x10(%rcx), %rsi
movq %rsi, 0x10(%rdi)
movq %r15, %rdx
testq %rsi, %rsi
jne 0x41f6
jmp 0x4206
movq 0x18(%rdi), %rdx
movq %rdx, 0x20(%rcx)
testq %rdx, %rdx
je 0x420f
movq %rcx, 0x10(%rdx)
movq 0x10(%rcx), %rsi
movq %rsi, 0x10(%rdi)
movq %r15, %rdx
testq %rsi, %rsi
jne 0x4213
jmp 0x4223
movq %rsi, 0x10(%rdi)
leaq 0x18(%rsi), %r8
leaq 0x20(%rsi), %rdx
cmpq %rcx, 0x18(%rsi)
cmoveq %r8, %rdx
movq %rdi, (%rdx)
movq %rcx, 0x20(%rdi)
jmp 0x422a
movq %rsi, 0x10(%rdi)
leaq 0x18(%rsi), %r8
leaq 0x20(%rsi), %rdx
cmpq %rcx, 0x18(%rsi)
cmoveq %r8, %rdx
movq %rdi, (%rdx)
movq %rcx, 0x18(%rdi)
movq %rdi, 0x10(%rcx)
movq %rcx, %r14
leaq 0x10(%rcx), %rdx
movq 0x10(%rcx), %rcx
testq %rcx, %rcx
jne 0x407f
jmp 0x424e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x425e
movq %r14, (%r15)
movq 0x28(%rbx), %rax
movl $0x1, 0x28(%rax)
incl 0x30(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq