// File: /workspace/github_cpp_makefile_star2_O2/cjc12[P]ezSTL/src/../include/rbtree.h
// Function: ezSTL::rbtree<int, ezSTL::less<int>, ezSTL::allocator<ezSTL::__rbtree_node<int>>>::delete_fixup(ezSTL::__rbtree_node<int>*, ezSTL::__rbtree_node<int>*)
void rbtree<T, Compare, Alloc>::delete_fixup(link_type father, link_type son) {
		while (son != root() && (!son || son->color == __rbtree_black)) {
			link_type brother = nullptr;
			if (son == father->left) {
				brother = father->right;
				// case 1: color of brother is red
				if (brother->color == __rbtree_red) {
					brother->color = __rbtree_black;
					father->color = __rbtree_red;
					left_rotate(father);
					brother = father->right;
				}
				// case 2: color of brother's sons are both black
				if ((!brother->left || brother->left->color == __rbtree_black) &&
					(!brother->right || brother->right->color == __rbtree_black)) {
					brother->color = __rbtree_red;
					son = father;
					father = father->parent;
				}
				else {
					// case 3: color of brother's right son is black
					if (!brother->right || brother->right->color == __rbtree_black) {
						brother->color = __rbtree_red;
						if (brother->left)
							brother->left->color = __rbtree_black;
						right_rotate(brother);
						brother = father->right;
					}
					// case 4: color of brother's left son is black
					brother->color = father->color;
					father->color = __rbtree_black;
					if (brother->right)
						brother->right->color = __rbtree_black;
					left_rotate(father);
					break;
				}
			}
			// similar as above, only change left to right, change right to left
			else {
				brother = father->left;
				if (brother->color == __rbtree_red) {
					brother->color = __rbtree_black;
					father->color = __rbtree_red;
					right_rotate(father);
					brother = father->left;
				}
				if ((!brother->right || brother->right->color == __rbtree_black) &&
					(!brother->left || brother->left->color == __rbtree_black)) {
					brother->color = __rbtree_red;
					son = father;
					father = father->parent;
				}
				else {
					if (!brother->left || brother->left->color == __rbtree_black) {
						brother->color = __rbtree_red;
						if (brother->right)
							brother->right->color = __rbtree_black;
						left_rotate(brother);
						brother = father->left;
					}
					brother->color = father->color;
					father->color = __rbtree_black;
					if (brother->left)
						brother->left->color = __rbtree_black;
					right_rotate(father);
					break;
				}
			}
		}
		if (son)
			son->color = __rbtree_black;
	}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rdi, %r14
movq %rbx, %r15
movq 0x8(%r14), %rax
cmpq 0x8(%rax), %rbx
je 0x8e07
movq %rsi, %rbx
testq %r15, %r15
je 0x8cee
cmpb $0x1, (%r15)
jne 0x8e0c
movq 0x10(%rbx), %rsi
cmpq %rsi, %r15
je 0x8d2f
cmpb $0x0, (%rsi)
jne 0x8d11
movb $0x1, (%rsi)
movb $0x0, (%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8c40
movq 0x10(%rbx), %rsi
movq 0x18(%rsi), %rax
testq %rax, %rax
je 0x8d1f
cmpb $0x1, (%rax)
jne 0x8d75
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x8d69
cmpb $0x0, (%rcx)
jne 0x8d69
jmp 0x8d7e
movq 0x18(%rbx), %rsi
cmpb $0x0, (%rsi)
jne 0x8d4d
movb $0x1, (%rsi)
movb $0x0, (%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8bee
movq 0x18(%rbx), %rsi
movq 0x10(%rsi), %rax
testq %rax, %rax
je 0x8d5b
cmpb $0x1, (%rax)
jne 0x8d8d
movq 0x18(%rsi), %rcx
testq %rcx, %rcx
je 0x8d69
cmpb $0x0, (%rcx)
je 0x8d96
movb $0x0, (%rsi)
movq 0x8(%rbx), %rsi
jmp 0x8ccb
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x8da5
cmpb $0x1, (%rcx)
jne 0x8dbb
movb $0x0, (%rsi)
testq %rax, %rax
jne 0x8da8
jmp 0x8dab
movq 0x18(%rsi), %rcx
testq %rcx, %rcx
je 0x8dd7
cmpb $0x1, (%rcx)
jne 0x8ded
movb $0x0, (%rsi)
testq %rax, %rax
jne 0x8dda
jmp 0x8ddd
movb $0x0, (%rsi)
movb $0x1, (%rax)
movq %r14, %rdi
callq 0x8bee
movq 0x10(%rbx), %rsi
movq 0x10(%rsi), %rcx
movb (%rbx), %al
movb %al, (%rsi)
movb $0x1, (%rbx)
testq %rcx, %rcx
je 0x8dca
movb $0x1, (%rcx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8c40
jmp 0x8e07
movb $0x0, (%rsi)
movb $0x1, (%rax)
movq %r14, %rdi
callq 0x8c40
movq 0x18(%rbx), %rsi
movq 0x18(%rsi), %rcx
movb (%rbx), %al
movb %al, (%rsi)
movb $0x1, (%rbx)
testq %rcx, %rcx
je 0x8dfc
movb $0x1, (%rcx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8bee
testq %r15, %r15
je 0x8e10
movb $0x1, (%r15)
popq %rbx
popq %r14
popq %r15
retq