// File: /workspace/github_c_makefile_star2_O1/ngkaho1234[P]ext4-extents-tree/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) != NULL)
			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 == EVENT_RB_BLACK)
		__rb_erase_color(child, parent, root);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %r14
testq %r14, %r14
je 0x377c
testq %rax, %rax
je 0x377f
movq %rax, %rdx
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x36ea
movq (%rdi), %rcx
movq %rbx, %rax
andq $-0x4, %rcx
je 0x3712
leaq 0x10(%rcx), %rsi
leaq 0x8(%rcx), %rax
cmpq %rdi, 0x10(%rcx)
cmoveq %rsi, %rax
movq %rdx, (%rax)
movq (%rdx), %rax
movq 0x8(%rdx), %r14
movq %rax, %rsi
andq $-0x4, %rsi
movq %rdx, %rcx
cmpq %rdi, %rsi
je 0x375c
testq %r14, %r14
je 0x373c
movq (%r14), %rcx
andl $0x3, %ecx
orq %rsi, %rcx
movq %rcx, (%r14)
movq %r14, 0x10(%rsi)
movq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rdx)
movq 0x8(%rdi), %rcx
movq (%rcx), %r8
andl $0x3, %r8d
orq %rdx, %r8
movq %r8, (%rcx)
movq %rsi, %rcx
movq (%rdi), %rsi
movq %rsi, (%rdx)
movq 0x10(%rdi), %rsi
movq %rsi, 0x10(%rdx)
movq 0x10(%rdi), %rsi
movq (%rsi), %rdi
andl $0x3, %edi
orq %rdx, %rdi
movq %rdi, (%rsi)
jmp 0x37b6
movq %rax, %r14
movq (%rdi), %rax
movq %rax, %rcx
andq $-0x4, %rcx
testq %r14, %r14
je 0x379a
movq (%r14), %rdx
andl $0x3, %edx
orq %rcx, %rdx
movq %rdx, (%r14)
testq %rcx, %rcx
je 0x37ab
cmpq %rdi, 0x10(%rcx)
je 0x37b2
movq %r14, 0x8(%rcx)
jmp 0x37b6
movq %r14, (%rbx)
xorl %ecx, %ecx
jmp 0x37b6
movq %r14, 0x10(%rcx)
testb $0x1, %al
je 0x3915
movq %r14, %rax
movq %rcx, %r14
testq %rax, %rax
je 0x37d2
testb $0x1, (%rax)
je 0x390d
cmpq (%rbx), %rax
je 0x390d
movq 0x10(%r14), %rdi
cmpq %rax, %rdi
je 0x3823
movq (%rdi), %rax
testb $0x1, %al
jne 0x3805
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3667
movq 0x10(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x3813
testb $0x1, (%rax)
je 0x3873
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x3864
testb $0x1, (%rcx)
jne 0x3864
jmp 0x3873
movq 0x8(%r14), %rdi
movq (%rdi), %rax
testb $0x1, %al
jne 0x3848
orq $0x1, %rax
movq %rax, (%rdi)
andb $-0x2, (%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3608
movq 0x8(%r14), %rdi
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x3856
testb $0x1, (%rax)
je 0x38c0
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x3864
testb $0x1, (%rcx)
je 0x38c0
andb $-0x2, (%rdi)
movq (%r14), %rcx
andq $-0x4, %rcx
jmp 0x37be
testq %rax, %rax
je 0x387d
testb $0x1, (%rax)
je 0x3894
movq 0x8(%rdi), %rax
orq $0x1, (%rax)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x3608
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
orq $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3667
jmp 0x390a
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x38ce
testb $0x1, (%rcx)
je 0x38e0
orb $0x1, (%rax)
andb $-0x2, (%rdi)
movq %rbx, %rsi
callq 0x3667
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
orq $0x1, (%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3608
movq (%rbx), %rax
testq %rax, %rax
je 0x3915
orb $0x1, (%rax)
popq %rbx
popq %r14
popq %rbp
retq