// File: /workspace/github_c_makefile_star2_O3/CarlosLunaMota[P]BinaryTrees/BinaryTrees.c
// Function: sp_tree_remove
void *sp_tree_remove(sp_tree *tree, const void *data) {

    sp_node *old_root;
    void    *old_data = NULL;

    // Sanity Checks:
    assert(tree != NULL);
    assert(data != NULL);

    // Avoid trivial case: empty tree
    if (tree->root != NULL) {

        // Splay the data to the root:
        splay(tree, data);

        // If it is here: remove it!
        if ((tree->comp)(tree->root->data, data) == 0) {
            old_root = tree->root;
            old_data = tree->root->data;
            if (tree->root->right == NULL) { tree->root = tree->root->left; }
            else {
                tree->root = tree->root->right;
                splay_left(tree);
                tree->root->left = old_root->left;
            }
            free(old_root);
        }
    }

    // Return
    return old_data;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
testq %rdi, %rdi
je 0xc6aa
movq %rsi, %r14
testq %rsi, %rsi
je 0xc6c9
movq %rdi, %rbx
movq (%rdi), %r13
testq %r13, %r13
je 0xc61b
xorps %xmm0, %xmm0
leaq 0x8(%rsp), %r15
movups %xmm0, 0x8(%r15)
movq %r15, %r12
movq (%r13), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
js 0xc5a2
je 0xc5e5
movq 0x10(%r13), %rax
testq %rax, %rax
je 0xc5e5
movq (%rax), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
jle 0xc594
movq 0x10(%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%r13)
movq %r13, 0x8(%rax)
cmpq $0x0, 0x10(%rax)
movq %rax, %r13
je 0xc5e8
movq %r13, 0x10(%r12)
leaq 0x10(%r13), %rax
movq %r13, %r12
jmp 0xc5dd
movq 0x8(%r13), %rax
testq %rax, %rax
je 0xc5e5
movq (%rax), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
jns 0xc5d2
movq 0x8(%r13), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x8(%r13)
movq %r13, 0x10(%rax)
cmpq $0x0, 0x8(%rax)
movq %rax, %r13
je 0xc5e8
movq %r13, 0x8(%r15)
leaq 0x8(%r13), %rax
movq %r13, %r15
movq (%rax), %r13
jmp 0xc550
movq %r13, %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%r12)
movq 0x10(%rax), %rcx
movq %rcx, 0x8(%r15)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, (%rbx)
movq (%rax), %rdi
movq %r14, %rsi
callq *0x8(%rbx)
testl %eax, %eax
je 0xc620
xorl %r14d, %r14d
jmp 0xc699
movq (%rbx), %rdi
movq (%rdi), %r14
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0xc66c
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq 0x8(%rax), %rdx
leaq 0x8(%rsp), %rcx
testq %rdx, %rdx
je 0xc678
movq %rdx, %rsi
movq 0x10(%rdx), %rdx
movq %rdx, 0x8(%rax)
movq %rax, 0x10(%rsi)
cmpq $0x0, 0x8(%rsi)
je 0xc675
movq %rsi, 0x8(%rcx)
movq 0x8(%rsi), %rax
movq 0x8(%rax), %rdx
movq %rsi, %rcx
jmp 0xc640
movq 0x8(%rdi), %rax
movq %rax, (%rbx)
jmp 0xc694
movq %rsi, %rax
movq 0x10(%rax), %rdx
movq %rdx, 0x8(%rcx)
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, (%rbx)
movq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rax)
callq 0x1120
movq %r14, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x1bd2(%rip), %rdi      # 0xe283
leaq 0x1b55(%rip), %rsi      # 0xe20d
leaq 0x264b(%rip), %rcx      # 0xed0a
movl $0x13a8, %edx           # imm = 0x13A8
callq 0x1080
leaq 0x1c32(%rip), %rdi      # 0xe302
leaq 0x1b36(%rip), %rsi      # 0xe20d
leaq 0x262c(%rip), %rcx      # 0xed0a
movl $0x13a9, %edx           # imm = 0x13A9
callq 0x1080