// File: /workspace/github_c_makefile_star2_O3/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 0xc4d1
movq %rsi, %r14
testq %rsi, %rsi
je 0xc4f0
movq %rdi, %rbx
movq (%rdi), %r13
testq %r13, %r13
je 0xc49e
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 0xc3d4
je 0xc417
movq 0x10(%r13), %rax
testq %rax, %rax
je 0xc417
movq (%rax), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
jle 0xc3c6
movq 0x10(%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%r13)
movq %r13, 0x8(%rax)
cmpq $0x0, 0x10(%rax)
movq %rax, %r13
je 0xc41a
movq %r13, 0x10(%r12)
leaq 0x10(%r13), %rax
movq %r13, %r12
jmp 0xc40f
movq 0x8(%r13), %rax
testq %rax, %rax
je 0xc417
movq (%rax), %rsi
movq %r14, %rdi
callq *0x8(%rbx)
testl %eax, %eax
jns 0xc404
movq 0x8(%r13), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x8(%r13)
movq %r13, 0x10(%rax)
cmpq $0x0, 0x8(%rax)
movq %rax, %r13
je 0xc41a
movq %r13, 0x8(%r15)
leaq 0x8(%r13), %rax
movq %r13, %r15
movq (%rax), %r13
jmp 0xc382
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)
movq (%rbx), %rcx
testl %eax, %eax
js 0xc4c0
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0xc49e
movq $0x0, 0x8(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
testq %rsi, %rsi
je 0xc4a5
movq %rsi, %rdi
movq 0x8(%rsi), %rsi
movq %rsi, 0x10(%rax)
movq %rax, 0x8(%rdi)
cmpq $0x0, 0x10(%rdi)
je 0xc4a2
movq %rdi, 0x10(%rdx)
movq 0x10(%rdi), %rax
movq 0x10(%rax), %rsi
movq %rdi, %rdx
jmp 0xc472
xorl %eax, %eax
jmp 0xc4c3
movq %rdi, %rax
movq 0x8(%rax), %rsi
movq %rsi, 0x10(%rdx)
movq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rax)
movq %rax, (%rbx)
movq %rcx, 0x10(%rax)
movq %rax, %rcx
movq (%rcx), %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x1dab(%rip), %rdi      # 0xe283
leaq 0x1d2e(%rip), %rsi      # 0xe20d
leaq 0x27cc(%rip), %rcx      # 0xecb2
movl $0x134b, %edx           # imm = 0x134B
callq 0x1080
leaq 0x1e0b(%rip), %rdi      # 0xe302
leaq 0x1d0f(%rip), %rsi      # 0xe20d
leaq 0x27ad(%rip), %rcx      # 0xecb2
movl $0x134c, %edx           # imm = 0x134C
callq 0x1080