// File: DRSY[P]MyRBTree/main.cpp
// Function: RBTree::remove(int)
bool remove(int value) {
        NodePtr_t node_to_remove = findNodeToRemove(value);
        if(!node_to_remove) {
            std::cerr << red("Value to be removed not in the tree\n");
            return false;
        }
        if(!isfull(node_to_remove)) {
            remove_atleastonenull(node_to_remove);
            return true;
        }
        else {
            // find successor node first
            NodePtr_t successor_node = findSuccessor(node_to_remove);
            node_to_remove->value = successor_node->value;
            successor_node->color = node_to_remove->color;
            remove_atleastonenull(successor_node); // successor's left is NULL
            return true;
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
movl -0x14(%rbp), %esi
callq 0x5120
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2b34
leaq -0x81(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x2250
movq -0x100(%rbp), %rdx
leaq 0x36af(%rip), %rsi      # 0x6004
leaq -0x80(%rbp), %rdi
callq 0x3110
jmp 0x2960
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x2250
movq -0x108(%rbp), %rdx
leaq 0x3710(%rip), %rsi      # 0x6091
leaq -0xb8(%rbp), %rdi
callq 0x3110
jmp 0x298f
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x3040
jmp 0x29a5
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x2250
movq -0x110(%rbp), %rdx
leaq 0x366a(%rip), %rsi      # 0x6030
leaq -0xe0(%rbp), %rdi
callq 0x3110
jmp 0x29d4
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x3040
jmp 0x29ea
movq 0x65ff(%rip), %rdi      # 0x8ff0
leaq -0x40(%rbp), %rsi
callq 0x2150
jmp 0x29fc
leaq -0x40(%rbp), %rdi
callq 0x20c0
leaq -0xe0(%rbp), %rdi
callq 0x20c0
leaq -0xe1(%rbp), %rdi
callq 0x21a0
leaq -0x60(%rbp), %rdi
callq 0x20c0
leaq -0xb8(%rbp), %rdi
callq 0x20c0
leaq -0xb9(%rbp), %rdi
callq 0x21a0
leaq -0x80(%rbp), %rdi
callq 0x20c0
leaq -0x81(%rbp), %rdi
callq 0x21a0
movb $0x0, -0x1(%rbp)
jmp 0x2bae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2b23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2b0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2b02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2aed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2ae1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x20c0
leaq -0xe0(%rbp), %rdi
callq 0x20c0
leaq -0xe1(%rbp), %rdi
callq 0x21a0
leaq -0x60(%rbp), %rdi
callq 0x20c0
leaq -0xb8(%rbp), %rdi
callq 0x20c0
leaq -0xb9(%rbp), %rdi
callq 0x21a0
leaq -0x80(%rbp), %rdi
callq 0x20c0
leaq -0x81(%rbp), %rdi
callq 0x21a0
jmp 0x2bbc
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2b4a
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x2b60
movq -0xf8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x5190
movb $0x1, -0x1(%rbp)
jmp 0x2bae
movq -0xf8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x54c0
movq -0xf8(%rbp), %rdi
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0xf0(%rbp), %rsi
callq 0x5190
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x2240
nopl (%rax,%rax)