// File: /workspace/github_c_makefile_star2_O2/xemul[P]cylang/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))
			node = 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;

		child = node->rb_right;
		parent = rb_parent(node);
		color = rb_color(node);

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

			node->rb_right = old->rb_right;
			rb_set_parent(old->rb_right, node);
		}

		node->rb_parent_color = old->rb_parent_color;
		node->rb_left = old->rb_left;
		rb_set_parent(old->rb_left, 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), %rsi
movq 0x10(%rdi), %r14
testq %r14, %r14
je 0x618d
testq %rsi, %rsi
je 0x61a1
movq %rsi, %rdx
movq 0x10(%rsi), %rsi
testq %rsi, %rsi
jne 0x611d
movq (%rdi), %rsi
movq %rsi, %rcx
movq %rbx, %rax
andq $-0x4, %rcx
je 0x6148
leaq 0x10(%rcx), %r8
leaq 0x8(%rcx), %rax
cmpq %rdi, 0x10(%rcx)
cmoveq %r8, %rax
movq %rdx, (%rax)
movq (%rdx), %rcx
movq 0x8(%rdx), %r14
movq %rcx, %rax
andq $-0x4, %rax
cmpq %rdi, %rax
je 0x61b9
testq %r14, %r14
je 0x616f
movq (%r14), %rsi
andl $0x3, %esi
orq %rax, %rsi
movq %rsi, (%r14)
movq %r14, 0x10(%rax)
movq 0x8(%rdi), %rsi
movq %rsi, 0x8(%rdx)
movq (%rsi), %r8
andl $0x3, %r8d
orq %rdx, %r8
movq %r8, (%rsi)
movq (%rdi), %rsi
jmp 0x61bc
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
testq %rsi, %rsi
je 0x61d5
movq %rsi, %r14
jmp 0x61ab
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
movq (%r14), %rdx
andl $0x3, %edx
orq %rax, %rdx
movq %rdx, (%r14)
jmp 0x61d8
movq %rdx, %rax
movq %rsi, (%rdx)
movq 0x10(%rdi), %rsi
movq %rsi, 0x10(%rdx)
movq (%rsi), %rdi
andl $0x3, %edi
orq %rdx, %rdi
movq %rdi, (%rsi)
jmp 0x61f4
xorl %r14d, %r14d
testq %rax, %rax
je 0x61e9
cmpq %rdi, 0x10(%rax)
je 0x61f0
movq %r14, 0x8(%rax)
jmp 0x61f4
movq %r14, (%rbx)
xorl %eax, %eax
jmp 0x61f4
movq %r14, 0x10(%rax)
testb $0x1, %cl
je 0x636f
movq %r14, %rcx
movq %rax, %r14
testq %rcx, %rcx
je 0x6213
movq (%rcx), %rax
testb $0x1, %al
je 0x6368
cmpq (%rbx), %rcx
je 0x6360
movq 0x10(%r14), %rdi
cmpq %rcx, %rdi
je 0x626b
movq (%rdi), %rax
testb $0x1, %al
jne 0x6246
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x60a6
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x6258
testb $0x1, (%rax)
je 0x62e6
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x62b3
movq (%rcx), %rdx
testb $0x1, %dl
jne 0x62b3
jmp 0x62c2
movq 0x8(%r14), %rdi
movq (%rdi), %rax
testb $0x1, %al
jne 0x6290
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x604c
movq 0x8(%r14), %rdi
movq 0x10(%rdi), %rcx
testq %rcx, %rcx
je 0x62a1
movq (%rcx), %rdx
testb $0x1, %dl
je 0x630d
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x62b3
testb $0x1, (%rax)
je 0x6338
andb $-0x2, (%rdi)
movq (%r14), %rax
andq $-0x4, %rax
jmp 0x61fd
testq %rax, %rax
je 0x62cc
testb $0x1, (%rax)
je 0x62e6
orq $0x1, %rdx
movq %rdx, (%rcx)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x604c
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)
orb $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x60a6
jmp 0x635d
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x631e
testb $0x1, (%rax)
je 0x6338
movq (%rcx), %rdx
orq $0x1, %rdx
movq %rdx, (%rcx)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x60a6
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)
orb $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x604c
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x636f
movq (%rcx), %rax
orq $0x1, %rax
movq %rax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq