// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/lib/bcore/bcore_btree.c
// Function: bcore_btree_ip_s_remove
int bcore_btree_ip_s_remove( bcore_btree_ip_s* o, bcore_btree_ip_key_t key )
{
    if( !o       ) return -1;
    if( !o->root ) return  0;
    bcore_btree_node_ip_s* node = bcore_btree_node_ip_s_find( o->root, key );
    if( !node    ) return -1;

    if( node->kv1.key == key )
    {
        if( !bcore_btree_node_ip_s_is_leaf( node ) )
        {
            bcore_btree_node_ip_s* trace = node->child0;
            while( !bcore_btree_node_ip_s_is_leaf( trace ) ) trace = ( trace->child2 ) ? trace->child2 : trace->child1;
            if( bcore_btree_node_ip_s_is_full( trace ) )
            {
                node->kv1   = trace->kv2;
                trace->child2 = NULL;
            }
            else
            {
                node->kv1 = trace->kv1;
                trace->child1 = trace->child2 = NULL;
                bcore_btree_ip_s_pull( o, trace->parent );
            }
        }
        else if( bcore_btree_node_ip_s_is_full( node ) )
        {
            node->kv1 = node->kv2;
            node->child2 = NULL;
        }
        else
        {
            node->child1 = node->child2 = NULL;
            if( node->parent )
            {
                bcore_btree_ip_s_pull( o, node->parent );
            }
            else
            {
                bcore_btree_ip_s_delete_node( o, node );
                o->root = NULL;
            }
        }
        return 1;
    }

    if( node->kv2.key == key )
    {
        if( !bcore_btree_node_ip_s_is_leaf( node ) )
        {
            bcore_btree_node_ip_s* trace = ( node->child2 ) ? node->child2 : node->child1;
            while( !bcore_btree_node_ip_s_is_leaf( trace ) ) trace = trace->child0;
            if( bcore_btree_node_ip_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_ip_s_pull( o, trace->parent );
            }
        }
        else if( bcore_btree_node_ip_s_is_full( node ) )
        {
            node->child2 = NULL;
        }
        else
        {
            node->child1 = node->child2 = NULL;
            if( node->parent )
            {
                bcore_btree_ip_s_pull( o, node->parent );
            }
            else
            {
                bcore_btree_ip_s_delete_node( o, node );
                o->root = NULL;
            }
        }
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x12e328
movq %rdi, %rbx
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x12e22d
movq %rsi, %r14
callq 0x12d1fe
testq %rax, %rax
je 0x12e328
cmpq %r14, (%rax)
jne 0x12e234
movq 0x28(%rax), %rsi
leaq 0x7c12e(%rip), %rdx     # 0x1aa330
cmpq %rdx, %rsi
je 0x12e292
cmpq %rdx, 0x28(%rsi)
je 0x12e2a2
movq 0x38(%rsi), %rcx
testq %rcx, %rcx
jne 0x12e222
movq 0x30(%rsi), %rcx
movq %rcx, %rsi
cmpq %rdx, 0x28(%rcx)
jne 0x12e215
jmp 0x12e2a5
xorl %ebp, %ebp
jmp 0x12e328
movl $0x0, %ebp
cmpq %r14, 0x10(%rax)
jne 0x12e328
leaq 0x7c0e6(%rip), %rcx     # 0x1aa330
movq 0x38(%rax), %rdx
cmpq %rcx, 0x28(%rax)
je 0x12e2d0
testq %rdx, %rdx
jne 0x12e25d
movq 0x30(%rax), %rdx
addq $0x10, %rax
movq %rdx, %rsi
movq 0x28(%rdx), %rdx
cmpq %rcx, %rdx
jne 0x12e261
cmpq $0x0, 0x38(%rsi)
movups (%rsi), %xmm0
movups %xmm0, (%rax)
je 0x12e310
movups 0x10(%rsi), %xmm0
movups %xmm0, (%rsi)
movq $0x0, 0x38(%rsi)
jmp 0x12e323
cmpq $0x0, 0x38(%rax)
je 0x12e2df
movups 0x10(%rax), %xmm0
movups %xmm0, (%rax)
jmp 0x12e2d5
movq %rsi, %rcx
cmpq $0x0, 0x38(%rcx)
je 0x12e2bd
movups 0x10(%rcx), %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x38(%rcx)
jmp 0x12e323
movups (%rcx), %xmm0
movups %xmm0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rcx)
movq 0x20(%rcx), %rsi
jmp 0x12e31b
testq %rdx, %rdx
je 0x12e2df
movq $0x0, 0x38(%rax)
jmp 0x12e323
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movq 0x20(%rax), %rsi
testq %rsi, %rsi
jne 0x12e31b
movq %rax, %rcx
addq $0x28, %rcx
movups %xmm0, (%rcx)
xorl %edx, %edx
movq %rdx, 0x10(%rcx)
movq 0x20(%rbx), %rcx
movq %rcx, 0x20(%rax)
movq %rax, 0x20(%rbx)
movq %rdx, (%rbx)
jmp 0x12e323
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsi)
movq 0x20(%rsi), %rsi
movq %rbx, %rdi
callq 0x12dd52
movl $0x1, %ebp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq