// File: DRSY[P]MyRBTree/main.cpp
// Function: RBTree::remove_atleastonenull(Node*)
void remove_atleastonenull(NodePtr_t node_to_remove) {
        // red leaf node
        if(isred(node_to_remove) && isleaf(node_to_remove)) {
            auto father = node_to_remove->father;
            if(node_to_remove==father->left)
                father->left = NULL;
            else
                father->right = NULL;
        }
        // black leaf node
        else if(isblack(node_to_remove) && isleaf(node_to_remove)) {
            if(node_to_remove==this->root) {delete node_to_remove; this->root=NULL;return;}
            assert(node_to_remove->father!=NULL);
            NodePtr_t father = node_to_remove->father;
            NodePtr_t brother = NULL;
            if(node_to_remove==father->left) {
                father->left = NULL;
                brother = father->right;
            }else {
                father->right = NULL;
                brother = father->left;
            }
            delete node_to_remove;
            assert(brother!=NULL);
            if(brother->color==Color::black) {
                black_black(father, brother);
            }else if(brother==father->right) {
                brother->color = Color::black;
                father->color = Color::red;
                rotate_left(father, brother);
                black_black(father, father->right);
            }
            else{
                brother->color = Color::black;
                father->color = Color::red;
                rotate_right(brother, father);
                black_black(father, father->left);
            }
        }
        // black node with one red leaf node
        else {
            assert(node_to_remove->color==Color::black);
            NodePtr_t child = (node_to_remove->left)?node_to_remove->left:node_to_remove->right;
            assert(isred(child));
            node_to_remove->value = child->value;
            if(child==node_to_remove->left)  node_to_remove->left=NULL;
            else  node_to_remove->right=NULL;
            delete child;
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x5201
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x5201
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x5201
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x51f0
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x51fc
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0x54b0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x53d9
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x53d9
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x53d9
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
cmpq (%rcx), %rax
jne 0x5266
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x5256
movq -0x40(%rbp), %rdi
movl $0x20, %esi
callq 0x2180
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
jmp 0x54b0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5273
jmp 0x5292
leaq 0xe3c(%rip), %rdi       # 0x60b6
leaq 0xe52(%rip), %rsi       # 0x60d3
movl $0x109, %edx            # imm = 0x109
leaq 0xe4f(%rip), %rcx       # 0x60dc
callq 0x20d0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x52ce
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x52e6
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x5302
movq -0x48(%rbp), %rdi
movl $0x20, %esi
callq 0x2180
cmpq $0x0, -0x28(%rbp)
je 0x530b
jmp 0x532a
leaq 0xdf8(%rip), %rdi       # 0x610a
leaq 0xdba(%rip), %rsi       # 0x60d3
movl $0x114, %edx            # imm = 0x114
leaq 0xdb7(%rip), %rcx       # 0x60dc
callq 0x20d0
movq -0x28(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x534a
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x5530
jmp 0x53d4
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x5396
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x3780
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdx
callq 0x5530
jmp 0x53d2
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x36d0
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x5530
jmp 0x53d4
jmp 0x54ae
movq -0x10(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x53e5
jmp 0x5404
leaq 0xd2c(%rip), %rdi       # 0x6118
leaq 0xce0(%rip), %rsi       # 0x60d3
movl $0x126, %edx            # imm = 0x126
leaq 0xcdd(%rip), %rcx       # 0x60dc
callq 0x20d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x541d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x5429
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x543d
jmp 0x545c
leaq 0xcf8(%rip), %rdi       # 0x613c
leaq 0xc88(%rip), %rsi       # 0x60d3
movl $0x128, %edx            # imm = 0x128
leaq 0xc85(%rip), %rcx       # 0x60dc
callq 0x20d0
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x5484
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x5490
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x54ac
movq -0x58(%rbp), %rdi
movl $0x20, %esi
callq 0x2180
jmp 0x54ae
jmp 0x54b0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)