// File: /workspace/github_c_makefile_star2_O3/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 0x7269
testq %rsi, %rsi
je 0x727d
movq %rsi, %rdx
movq 0x10(%rsi), %rsi
testq %rsi, %rsi
jne 0x71f9
movq (%rdi), %rsi
movq %rsi, %rcx
movq %rbx, %rax
andq $-0x4, %rcx
je 0x7224
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 0x7295
testq %r14, %r14
je 0x724b
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 0x7298
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
testq %rsi, %rsi
je 0x72b1
movq %rsi, %r14
jmp 0x7287
movq (%rdi), %rcx
movq %rcx, %rax
andq $-0x4, %rax
movq (%r14), %rdx
andl $0x3, %edx
orq %rax, %rdx
movq %rdx, (%r14)
jmp 0x72b4
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 0x72d0
xorl %r14d, %r14d
testq %rax, %rax
je 0x72c5
cmpq %rdi, 0x10(%rax)
je 0x72cc
movq %r14, 0x8(%rax)
jmp 0x72d0
movq %r14, (%rbx)
xorl %eax, %eax
jmp 0x72d0
movq %r14, 0x10(%rax)
testb $0x1, %cl
je 0x744b
movq %r14, %rcx
movq %rax, %r14
testq %rcx, %rcx
je 0x72ef
movq (%rcx), %rax
testb $0x1, %al
je 0x7444
cmpq (%rbx), %rcx
je 0x743c
movq 0x10(%r14), %rdi
cmpq %rcx, %rdi
je 0x7347
movq (%rdi), %rax
testb $0x1, %al
jne 0x7322
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7182
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x7334
testb $0x1, (%rax)
je 0x73c2
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x738f
movq (%rcx), %rdx
testb $0x1, %dl
jne 0x738f
jmp 0x739e
movq 0x8(%r14), %rdi
movq (%rdi), %rax
testb $0x1, %al
jne 0x736c
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7128
movq 0x8(%r14), %rdi
movq 0x10(%rdi), %rcx
testq %rcx, %rcx
je 0x737d
movq (%rcx), %rdx
testb $0x1, %dl
je 0x73e9
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x738f
testb $0x1, (%rax)
je 0x7414
andb $-0x2, (%rdi)
movq (%r14), %rax
andq $-0x4, %rax
jmp 0x72d9
testq %rax, %rax
je 0x73a8
testb $0x1, (%rax)
je 0x73c2
orq $0x1, %rdx
movq %rdx, (%rcx)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x7128
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 0x7182
jmp 0x7439
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x73fa
testb $0x1, (%rax)
je 0x7414
movq (%rcx), %rdx
orq $0x1, %rdx
movq %rdx, (%rcx)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x7182
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 0x7128
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x744b
movq (%rcx), %rax
orq $0x1, %rax
movq %rax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq