// File: /workspace/github_cpp_makefile_star2_O2/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), %r8
movq 0x10(%rdi), %rsi
testq %rsi, %rsi
je 0x779b
testq %r8, %r8
je 0x77af
movq %r8, %rax
movq %rax, %rdx
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x7760
movq (%rdx), %rcx
movq 0x8(%rdx), %r14
movq %rcx, %rax
andq $-0x4, %rax
testq %r14, %r14
je 0x778c
movq (%r14), %r9
andl $0x3, %r9d
orq %rax, %r9
movq %r9, (%r14)
cmpq %rdi, %rax
je 0x77ca
movq %r14, 0x10(%rax)
movq 0x10(%rdi), %rsi
jmp 0x77d5
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
testq %r8, %r8
je 0x7827
movq %r8, %rsi
jmp 0x77b9
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
movq (%rsi), %rdx
andl $0x3, %edx
orq %rax, %rdx
movq %rdx, (%rsi)
movq %rsi, %r14
jmp 0x782a
movq %r14, 0x8(%rax)
movq 0x8(%rdi), %r8
movq %rdx, %rax
movq (%rdi), %r9
movq %r9, (%rdx)
movq %r8, 0x8(%rdx)
movq %rsi, 0x10(%rdx)
movq %rbx, %rsi
andq $-0x4, %r9
je 0x77fc
leaq 0x10(%r9), %r8
leaq 0x8(%r9), %rsi
cmpq %rdi, 0x10(%r9)
cmoveq %r8, %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 0x7846
movq (%rsi), %rdi
andl $0x3, %edi
orq %rdx, %rdi
movq %rdi, (%rsi)
jmp 0x7846
xorl %r14d, %r14d
testq %rax, %rax
je 0x783b
cmpq %rdi, 0x10(%rax)
je 0x7842
movq %r14, 0x8(%rax)
jmp 0x7846
movq %r14, (%rbx)
xorl %eax, %eax
jmp 0x7846
movq %r14, 0x10(%rax)
testb $0x1, %cl
je 0x79c8
movq %r14, %rcx
movq %rax, %r14
testq %rcx, %rcx
je 0x7865
movq (%rcx), %rax
testb $0x1, %al
je 0x79c1
cmpq (%rbx), %rcx
je 0x79b9
movq 0x10(%r14), %rdi
cmpq %rcx, %rdi
je 0x78bd
movq (%rdi), %rax
testb $0x1, %al
jne 0x7898
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x76ea
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x78aa
testb $0x1, (%rax)
je 0x7938
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x7905
movq (%rcx), %rdx
testb $0x1, %dl
jne 0x7905
jmp 0x7914
movq 0x8(%r14), %rdi
movq (%rdi), %rax
testb $0x1, %al
jne 0x78e2
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7690
movq 0x8(%r14), %rdi
movq 0x10(%rdi), %rcx
testq %rcx, %rcx
je 0x78f3
movq (%rcx), %rdx
testb $0x1, %dl
je 0x7964
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x7905
testb $0x1, (%rax)
je 0x798c
andb $-0x2, (%rdi)
movq (%r14), %rax
andq $-0x4, %rax
jmp 0x784f
testq %rax, %rax
je 0x791e
testb $0x1, (%rax)
je 0x7938
orq $0x1, %rdx
movq %rdx, (%rcx)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x7690
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rax
movq (%r14), %rcx
andl $0x1, %ecx
movq (%rdi), %rdx
andq $-0x2, %rdx
orq %rcx, %rdx
movq %rdx, (%rdi)
orb $0x1, (%r14)
testq %rax, %rax
je 0x7957
orb $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x76ea
jmp 0x79b6
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x7972
testb $0x1, (%rax)
je 0x798c
orq $0x1, %rdx
movq %rdx, (%rcx)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x76ea
movq 0x8(%r14), %rdi
movq 0x8(%rdi), %rax
movq (%r14), %rcx
andl $0x1, %ecx
movq (%rdi), %rdx
andq $-0x2, %rdx
orq %rcx, %rdx
movq %rdx, (%rdi)
orb $0x1, (%r14)
testq %rax, %rax
je 0x79ab
orb $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7690
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x79c8
movq (%rcx), %rax
orq $0x1, %rax
movq %rax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq