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

    sp_node *old_root;
    int      comp;

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

    // Trivial case: empty tree
    if (tree->root == NULL) { return NULL; }

    // Trivial case: null data == return maximum
    if (data == NULL) {
        splay_right(tree);
        return tree->root->data;
    }

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

    // Take a look at the current root:
    comp = (tree->comp)(tree->root->data, data);

    // If its bigger or equal we must find the predecessor in the left subtree:    
    if (comp >= 0) {
        if (tree->root->left == NULL) { return NULL; }
        else {
            old_root   = tree->root;
            tree->root = tree->root->left;
            old_root->left = NULL;
            splay_right(tree);
            tree->root->right = old_root;
        }
    }

    // Predecessor is at root now:
    return tree->root->data;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
testq %rdi, %rdi
je 0xc469
movq %rsi, %r14
testq %rsi, %rsi
je 0xc488
movq %rdi, %rbx
movq (%rdi), %r13
testq %r13, %r13
je 0xc436
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 0xc369
je 0xc3ac
movq 0x10(%r13), %rax
testq %rax, %rax
je 0xc3ac
movq (%rax), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
jle 0xc35b
movq 0x10(%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%r13)
movq %r13, 0x8(%rax)
cmpq $0x0, 0x10(%rax)
movq %rax, %r13
je 0xc3af
movq %r13, 0x10(%r12)
leaq 0x10(%r13), %rax
movq %r13, %r12
jmp 0xc3a4
movq 0x8(%r13), %rax
testq %rax, %rax
je 0xc3ac
movq (%rax), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
jns 0xc399
movq 0x8(%r13), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x8(%r13)
movq %r13, 0x10(%rax)
cmpq $0x0, 0x8(%rax)
movq %rax, %r13
je 0xc3af
movq %r13, 0x8(%r15)
leaq 0x8(%r13), %rax
movq %r13, %r15
movq (%rax), %r13
jmp 0xc317
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
js 0xc455
movq (%rbx), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0xc436
movq %rcx, (%rbx)
movq $0x0, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq 0x10(%rcx), %rsi
leaq 0x8(%rsp), %rdx
testq %rsi, %rsi
je 0xc43d
movq %rsi, %rdi
movq 0x8(%rsi), %rsi
movq %rsi, 0x10(%rcx)
movq %rcx, 0x8(%rdi)
cmpq $0x0, 0x10(%rdi)
je 0xc43a
movq %rdi, 0x10(%rdx)
movq 0x10(%rdi), %rcx
movq 0x10(%rcx), %rsi
movq %rdi, %rdx
jmp 0xc40a
xorl %eax, %eax
jmp 0xc45b
movq %rdi, %rcx
movq 0x8(%rcx), %rsi
movq %rsi, 0x10(%rdx)
movq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rcx)
movq %rcx, (%rbx)
movq %rax, 0x10(%rcx)
movq (%rbx), %rax
movq (%rax), %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x1e13(%rip), %rdi      # 0xe283
leaq 0x1d96(%rip), %rsi      # 0xe20d
leaq 0x2834(%rip), %rcx      # 0xecb2
movl $0x134b, %edx           # imm = 0x134B
callq 0x1080
leaq 0x1e73(%rip), %rdi      # 0xe302
leaq 0x1d77(%rip), %rsi      # 0xe20d
leaq 0x2815(%rip), %rcx      # 0xecb2
movl $0x134c, %edx           # imm = 0x134C
callq 0x1080