// File: /workspace/github_cpp_makefile_star2_O1/roberty65[P]bServer/common/src/rbtree.c
// Function: rb_erase
void rb_erase(struct rb_node *node, struct rb_root *root)
{
	struct rb_node *child, *parent;
	int color;

	if (!node->rb_left)
		child = node->rb_right;
	else if (!node->rb_right)
		child = node->rb_left;
	else
	{
		struct rb_node *old = node, *left;

		node = node->rb_right;
		while ((left = node->rb_left) != 0 /*NULL*/)
			node = left;
		child = node->rb_right;
		parent = rb_parent(node);
		color = rb_color(node);

		if (child)
			rb_set_parent(child, parent);
		if (parent == old) {
			parent->rb_right = child;
			parent = node;
		} else
			parent->rb_left = child;

		node->rb_parent_color = old->rb_parent_color;
		node->rb_right = old->rb_right;
		node->rb_left = old->rb_left;

		if (rb_parent(old))
		{
			if (rb_parent(old)->rb_left == old)
				rb_parent(old)->rb_left = node;
			else
				rb_parent(old)->rb_right = node;
		} else
			root->rb_node = node;

		rb_set_parent(old->rb_left, node);
		if (old->rb_right)
			rb_set_parent(old->rb_right, node);
		goto color;
	}

	parent = rb_parent(node);
	color = rb_color(node);

	if (child)
		rb_set_parent(child, parent);
	if (parent)
	{
		if (parent->rb_left == node)
			parent->rb_left = child;
		else
			parent->rb_right = child;
	}
	else
		root->rb_node = child;

 color:
	if (color == RB_BLACK)
		__rb_erase_color(child, parent, root);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %r14
testq %r14, %r14
je 0x7f63
testq %rax, %rax
je 0x7f66
movq %rax, %rdx
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x7ec9
movq (%rdx), %rcx
movq 0x8(%rdx), %r14
movq %rcx, %rax
andq $-0x4, %rax
testq %r14, %r14
je 0x7ef4
movq (%r14), %rsi
andl $0x3, %esi
orq %rax, %rsi
movq %rsi, (%r14)
xorl %esi, %esi
cmpq %rdi, %rax
setne %sil
movq %r14, 0x8(%rax,%rsi,8)
cmoveq %rdx, %rax
movq (%rdi), %rsi
movq %rsi, (%rdx)
movq 0x8(%rdi), %rsi
movq %rsi, 0x8(%rdx)
movq 0x10(%rdi), %rsi
movq %rsi, 0x10(%rdx)
movq (%rdi), %r8
movq %rbx, %rsi
andq $-0x4, %r8
je 0x7f38
leaq 0x10(%r8), %r9
leaq 0x8(%r8), %rsi
cmpq %rdi, 0x10(%r8)
cmoveq %r9, %rsi
movq %rdx, (%rsi)
movq 0x10(%rdi), %rsi
movq (%rsi), %r8
andl $0x3, %r8d
orq %rdx, %r8
movq %r8, (%rsi)
movq 0x8(%rdi), %rsi
testq %rsi, %rsi
je 0x7f9d
movq (%rsi), %rdi
andl $0x3, %edi
orq %rdx, %rdi
movq %rdi, (%rsi)
jmp 0x7f9d
movq %rax, %r14
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
testq %r14, %r14
je 0x7f81
movq (%r14), %rdx
andl $0x3, %edx
orq %rax, %rdx
movq %rdx, (%r14)
testq %rax, %rax
je 0x7f92
cmpq %rdi, 0x10(%rax)
je 0x7f99
movq %r14, 0x8(%rax)
jmp 0x7f9d
movq %r14, (%rbx)
xorl %eax, %eax
jmp 0x7f9d
movq %r14, 0x10(%rax)
testb $0x1, %cl
je 0x810e
movq %r14, %rcx
movq %rax, %r14
testq %rcx, %rcx
je 0x7fba
testb $0x1, (%rcx)
je 0x8106
cmpq (%rbx), %rcx
je 0x8106
movq 0x10(%r14), %rdi
cmpq %rcx, %rdi
je 0x800b
movq (%rdi), %rax
testb $0x1, %al
jne 0x7fed
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7e4e
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x7ffb
testb $0x1, (%rax)
je 0x805b
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x804c
testb $0x1, (%rcx)
jne 0x804c
jmp 0x805b
movq 0x8(%r14), %rdi
movq (%rdi), %rax
testb $0x1, %al
jne 0x8030
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7df4
movq 0x8(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x803e
testb $0x1, (%rax)
je 0x80b0
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x804c
testb $0x1, (%rcx)
je 0x80b0
andb $-0x2, (%rdi)
movq (%r14), %rax
andq $-0x4, %rax
jmp 0x7fa6
testq %rax, %rax
je 0x8065
testb $0x1, (%rax)
je 0x8080
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x8071
orb $0x1, (%rax)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x7df4
movq 0x10(%r14), %rdi
movq (%r14), %rax
andl $0x1, %eax
movq (%rdi), %rcx
andq $-0x2, %rcx
orq %rax, %rcx
movq %rcx, (%rdi)
orb $0x1, (%r14)
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x80a3
orb $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7e4e
jmp 0x8103
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x80be
testb $0x1, (%rcx)
je 0x80d5
testq %rax, %rax
je 0x80c6
orb $0x1, (%rax)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x7e4e
movq 0x8(%r14), %rdi
movq (%r14), %rax
andl $0x1, %eax
movq (%rdi), %rcx
andq $-0x2, %rcx
orq %rax, %rcx
movq %rcx, (%rdi)
orb $0x1, (%r14)
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x80f8
orb $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7df4
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x810e
orb $0x1, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq