// File: cjc12[P]ezSTL/src/../include/rbtree.h
// Function: ezSTL::rbtree<int, ezSTL::less<int>, ezSTL::allocator<ezSTL::__rbtree_node<int>>>::erase(ezSTL::__rbtree_iterator<int>)
void rbtree<T, Compare, Alloc>::erase(iterator pos) {
		// adjust leftmost and rightmost
		if (pos == begin())
			header.node->left = (pos + 1).node;
		if(pos == (end() - 1))
			header.node->right = (pos - 1).node;
		link_type todelete = nullptr;
		if (pos.node->left == nullptr || pos.node->right == nullptr)
			todelete = pos.node;
		else
			todelete = (pos + 1).node;
		
		// son: son of node todelete, father: parent of son
		link_type son = nullptr, father = nullptr;
		if (todelete->left != nullptr)
			son = todelete->left;
		else
			son = todelete->right;
		if (son)
			son->parent = todelete->parent;
		father = todelete->parent;
		if (todelete == father->left)
			father->left = son;
		else if(todelete == father->right)
			father->right = son;
		if (todelete == root())
			header.node->parent = son;
		// copy data from node to be deleted to pos
		if (todelete != pos.node)
			pos.node->data = todelete->data;
		// if the deleted node is black, then fix up
		if (todelete->color == __rbtree_black)
			delete_fixup(father, son);
		// deallocate node
		Alloc().destroy(todelete);
		Alloc().deallocate(todelete);
		--__size;
	}

// Assembly:
subq $0x78, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rsi
movq %rsi, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x120d0
movq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xd280
testb $0x1, %al
jne 0xd5cc
jmp 0xd5f2
movq 0x10(%rsp), %rsi
leaq 0x58(%rsp), %rdi
movl $0x1, %edx
callq 0x12a20
movq 0x8(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x8(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0xd2a0
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movl $0x1, %edx
callq 0x12a60
movq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xd280
testb $0x1, %al
jne 0xd62a
jmp 0xd650
movq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdi
movl $0x1, %edx
callq 0x12a60
movq 0x8(%rsp), %rax
movq 0x40(%rsp), %rcx
movq 0x8(%rax), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rax
movq $0x0, 0x38(%rsp)
movq (%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0xd677
movq 0x10(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0xd686
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0xd6a4
movq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdi
movl $0x1, %edx
callq 0x12a20
movq 0x30(%rsp), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0xd6d2
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0xd6e0
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0xd6fa
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq 0x10(%rcx), %rax
jne 0xd728
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0xd748
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jne 0xd746
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xd748
movq 0x8(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
callq 0x12390
movq %rax, %rcx
movq (%rsp), %rax
cmpq %rcx, %rax
jne 0xd779
movq 0x8(%rsp), %rax
movq 0x28(%rsp), %rcx
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq 0x38(%rsp), %rax
cmpq (%rcx), %rax
je 0xd79b
movq 0x10(%rsp), %rax
movq 0x38(%rsp), %rcx
movl 0x20(%rcx), %ecx
movq (%rax), %rax
movl %ecx, 0x20(%rax)
movq 0x38(%rsp), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xd7c0
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x12ab0
movq 0x38(%rsp), %rsi
leaq 0x1f(%rsp), %rdi
callq 0x12e20
movq 0x38(%rsp), %rsi
leaq 0x1e(%rsp), %rdi
movl $0x1, %edx
callq 0x12e40
movq 0x8(%rsp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)
nop