// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_btree.c
// Function: bcore_btree_vd_s_remove
int bcore_btree_vd_s_remove( bcore_btree_vd_s* o, bcore_btree_vd_key_t key )
{
    if( !o       ) return -1;
    if( !o->root ) return  0;
    bcore_btree_node_vd_s* node = bcore_btree_node_vd_s_find( o->root, key );
    if( !node    ) return -1;

    if( node->kv1.key == key )
    {
        if( !bcore_btree_node_vd_s_is_leaf( node ) )
        {
            bcore_btree_node_vd_s* trace = node->child0;
            while( !bcore_btree_node_vd_s_is_leaf( trace ) ) trace = ( trace->child2 ) ? trace->child2 : trace->child1;
            if( bcore_btree_node_vd_s_is_full( trace ) )
            {
                node->kv1   = trace->kv2;
                trace->child2 = NULL;
            }
            else
            {
                node->kv1 = trace->kv1;
                trace->child1 = trace->child2 = NULL;
                bcore_btree_vd_s_pull( o, trace->parent );
            }
        }
        else if( bcore_btree_node_vd_s_is_full( node ) )
        {
            node->kv1 = node->kv2;
            node->child2 = NULL;
        }
        else
        {
            node->child1 = node->child2 = NULL;
            if( node->parent )
            {
                bcore_btree_vd_s_pull( o, node->parent );
            }
            else
            {
                bcore_btree_vd_s_delete_node( o, node );
                o->root = NULL;
            }
        }
        return 1;
    }

    if( node->kv2.key == key )
    {
        if( !bcore_btree_node_vd_s_is_leaf( node ) )
        {
            bcore_btree_node_vd_s* trace = ( node->child2 ) ? node->child2 : node->child1;
            while( !bcore_btree_node_vd_s_is_leaf( trace ) ) trace = trace->child0;
            if( bcore_btree_node_vd_s_is_full( trace ) )
            {
                node->kv2     = trace->kv1;
                trace->kv1    = trace->kv2;
                trace->child2 = NULL;
            }
            else
            {
                node->kv2   = trace->kv1;
                trace->child1 = trace->child2 = NULL;
                bcore_btree_vd_s_pull( o, trace->parent );
            }
        }
        else if( bcore_btree_node_vd_s_is_full( node ) )
        {
            node->child2 = NULL;
        }
        else
        {
            node->child1 = node->child2 = NULL;
            if( node->parent )
            {
                bcore_btree_vd_s_pull( o, node->parent );
            }
            else
            {
                bcore_btree_vd_s_delete_node( o, node );
                o->root = NULL;
            }
        }
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
pushq $-0x1
popq %rbp
testq %rdi, %rdi
je 0xa4a40
movq %rdi, %rbx
movq (%rdi), %rdi
testq %rdi, %rdi
je 0xa498a
movq %rsi, %r14
callq 0xa38bf
testq %rax, %rax
je 0xa4a40
cmpq %r14, (%rax)
je 0xa4991
movl $0x0, %ebp
cmpq %r14, 0x8(%rax)
jne 0xa4a40
leaq 0x74aac(%rip), %rcx     # 0x1193f0
movq 0x28(%rax), %rdx
cmpq %rcx, 0x18(%rax)
je 0xa49da
testq %rdx, %rdx
jne 0xa495b
movq 0x20(%rax), %rdx
movq %rdx, %rsi
movq 0x18(%rdx), %rdx
cmpq %rcx, %rdx
jne 0xa495b
cmpq $0x0, 0x28(%rsi)
movq (%rsi), %rcx
movq %rcx, 0x8(%rax)
je 0xa4a2a
movq 0x8(%rsi), %rax
movq %rax, (%rsi)
andq $0x0, 0x28(%rsi)
jmp 0xa4a3d
xorl %ebp, %ebp
jmp 0xa4a40
movq 0x18(%rax), %rsi
leaq 0x74a54(%rip), %rdx     # 0x1193f0
cmpq %rdx, %rsi
jne 0xa49ba
cmpq $0x0, 0x28(%rax)
je 0xa49f9
movq 0x8(%rax), %rcx
movq %rcx, (%rax)
jmp 0xa49df
testq %rsi, %rsi
jne 0xa49ba
movq 0x20(%rcx), %rsi
movq %rsi, %rcx
movq 0x28(%rsi), %rsi
cmpq %rdx, 0x18(%rcx)
jne 0xa49b1
testq %rsi, %rsi
je 0xa49e6
movq 0x8(%rcx), %rdx
movq %rdx, (%rax)
andq $0x0, 0x28(%rcx)
jmp 0xa4a3d
testq %rdx, %rdx
je 0xa49f9
andq $0x0, 0x28(%rax)
jmp 0xa4a3d
movq (%rcx), %rdx
movq %rdx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rcx)
movq 0x10(%rcx), %rsi
jmp 0xa4a35
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movq 0x10(%rax), %rsi
testq %rsi, %rsi
jne 0xa4a35
movq %rax, %rcx
addq $0x18, %rcx
andq $0x0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x20(%rbx), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x20(%rbx)
andq $0x0, (%rbx)
jmp 0xa4a3d
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsi)
movq 0x10(%rsi), %rsi
movq %rbx, %rdi
callq 0xa44b4
pushq $0x1
popq %rbp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq