// File: /workspace/github_c_makefile_star2_O1/GangZhuo[P]rbtree/rbtree.c
// Function: rbtree_remove_fixup
static void rbtree_remove_fixup(rbtree_t *tree, rbnode_t *x, rbnode_t *p)
{
	rbnode_t *b;

	while (!rbnode_is_nil(p) && rbnode_is_black(x)) {
		if (rbnode_is_nil(x) || rbnode_is_left(x)) {
			b = p->right;
			if (rbnode_is_red(b)) {
				rbnode_set_black(b);
				rbnode_set_red(p);
				rbtree_left_rotate(tree, p);
				b = p->right;
			}
			if (rbnode_is_nil(b) || (rbnode_is_black(b->right) && rbnode_is_black(b->left))) {
				if (!rbnode_is_nil(b))
					rbnode_set_red(b);
				x = p;
                p = p->parent;
			}
			else {
				if (rbnode_is_black(b->right)) {
					rbnode_set_black(b->left);
					rbnode_set_red(b);
					rbtree_right_rotate(tree, b);
					b = p->right;
				}
				else
					rbnode_set_black(b->right);
				b->color = p->color;
				rbnode_set_black(p);
				rbtree_left_rotate(tree, p);
				x = tree->root;
                p = rbnode_nil;
			}
		}
		else {
			b = p->left;
			if (rbnode_is_red(b)) {
				rbnode_set_black(b);
				rbnode_set_red(p);
				rbtree_right_rotate(tree, p);
				b = p->left;
			}
			if (rbnode_is_nil(b) || (rbnode_is_black(b->right) && rbnode_is_black(b->left))) {
				if (!rbnode_is_nil(b))
					rbnode_set_red(b);
				x = p;
                p = p->parent;
			}
			else {
				if (rbnode_is_black(b->left)) {
					rbnode_set_black(b->right);
					rbnode_set_red(b);
					rbtree_left_rotate(tree, b);
					b = p->left;
				}
				else
					rbnode_set_black(b->left);
				b->color = p->color;
				rbnode_set_black(p);
				rbtree_right_rotate(tree, p);
				x = tree->root;
                p = rbnode_nil;
			}
		}
	}
    if (!rbnode_is_nil(x))
        rbnode_set_black(x);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdx, %rdx
je 0x15bc
movq %rdx, %r14
movq %rdi, %rbx
testq %rsi, %rsi
je 0x147c
cmpl $0x0, 0x8(%rsi)
jne 0x15bc
movq 0x20(%rsi), %rax
cmpq %rsi, 0x10(%rax)
je 0x147c
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x152a
cmpl $0x1, 0x8(%rsi)
jne 0x152c
movl $0x0, 0x8(%rsi)
movl $0x1, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1897
movq 0x10(%r14), %rsi
jmp 0x152c
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x14ab
cmpl $0x1, 0x8(%rsi)
jne 0x14ad
movl $0x0, 0x8(%rsi)
movl $0x1, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1855
movq 0x18(%r14), %rsi
jmp 0x14ad
xorl %esi, %esi
testq %rsi, %rsi
je 0x156e
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x14c5
cmpl $0x0, 0x8(%rax)
jne 0x14dc
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x1567
cmpl $0x0, 0x8(%rcx)
je 0x1567
testq %rax, %rax
je 0x14f0
cmpl $0x0, 0x8(%rax)
je 0x14f0
movl $0x0, 0x8(%rax)
jmp 0x150e
movq 0x10(%rsi), %rax
movl $0x0, 0x8(%rax)
movl $0x1, 0x8(%rsi)
movq %rbx, %rdi
callq 0x1897
movq 0x18(%r14), %rsi
movl 0x8(%r14), %eax
movl %eax, 0x8(%rsi)
movl $0x0, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1855
jmp 0x15a8
xorl %esi, %esi
testq %rsi, %rsi
je 0x156e
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x1540
cmpl $0x0, 0x8(%rax)
jne 0x154f
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x1567
cmpl $0x0, 0x8(%rcx)
je 0x1567
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x1574
cmpl $0x0, 0x8(%rcx)
je 0x1574
movl $0x0, 0x8(%rcx)
jmp 0x158e
movl $0x1, 0x8(%rsi)
movq 0x20(%r14), %rax
jmp 0x15ad
movl $0x0, 0x8(%rax)
movl $0x1, 0x8(%rsi)
movq %rbx, %rdi
callq 0x1855
movq 0x10(%r14), %rsi
movl 0x8(%r14), %eax
movl %eax, 0x8(%rsi)
movl $0x0, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1897
movq (%rbx), %r14
xorl %eax, %eax
movq %r14, %rsi
movq %rax, %r14
testq %rax, %rax
jne 0x1429
testq %rsi, %rsi
je 0x15c8
movl $0x0, 0x8(%rsi)
addq $0x8, %rsp
popq %rbx
popq %r14
retq