// File: /workspace/github_c_makefile_star2_O0/johsteffens[P]beth/lib/bcore/bcore_btree.c
// Function: bcore_btree_ps_s_remove
int bcore_btree_ps_s_remove( bcore_btree_ps_s* o, bcore_btree_ps_key_t key )
{
    if( !o       ) return -1;
    if( !o->root ) return  0;
    bcore_btree_node_ps_s* node = bcore_btree_node_ps_s_find( o->root, key );
    if( !node    ) return -1;

    if( node->kv1.key == key )
    {
        if( !bcore_btree_node_ps_s_is_leaf( node ) )
        {
            bcore_btree_node_ps_s* trace = node->child0;
            while( !bcore_btree_node_ps_s_is_leaf( trace ) ) trace = ( trace->child2 ) ? trace->child2 : trace->child1;
            if( bcore_btree_node_ps_s_is_full( trace ) )
            {
                node->kv1   = trace->kv2;
                trace->child2 = NULL;
            }
            else
            {
                node->kv1 = trace->kv1;
                trace->child1 = trace->child2 = NULL;
                bcore_btree_ps_s_pull( o, trace->parent );
            }
        }
        else if( bcore_btree_node_ps_s_is_full( node ) )
        {
            node->kv1 = node->kv2;
            node->child2 = NULL;
        }
        else
        {
            node->child1 = node->child2 = NULL;
            if( node->parent )
            {
                bcore_btree_ps_s_pull( o, node->parent );
            }
            else
            {
                bcore_btree_ps_s_delete_node( o, node );
                o->root = NULL;
            }
        }
        return 1;
    }

    if( node->kv2.key == key )
    {
        if( !bcore_btree_node_ps_s_is_leaf( node ) )
        {
            bcore_btree_node_ps_s* trace = ( node->child2 ) ? node->child2 : node->child1;
            while( !bcore_btree_node_ps_s_is_leaf( trace ) ) trace = trace->child0;
            if( bcore_btree_node_ps_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_ps_s_pull( o, trace->parent );
            }
        }
        else if( bcore_btree_node_ps_s_is_full( node ) )
        {
            node->child2 = NULL;
        }
        else
        {
            node->child1 = node->child2 = NULL;
            if( node->parent )
            {
                bcore_btree_ps_s_pull( o, node->parent );
            }
            else
            {
                bcore_btree_ps_s_delete_node( o, node );
                o->root = NULL;
            }
        }
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x124353
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12468d
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x124369
movl $0x0, -0x4(%rbp)
jmp 0x12468d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x1225e0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x124390
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x12468d
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x12450d
movq -0x20(%rbp), %rdi
callq 0x122d10
cmpl $0x0, %eax
jne 0x12447c
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x122d10
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1243d6
jmp 0x124405
movq -0x28(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x1243ef
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x1243fb
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1243bf
movq -0x28(%rbp), %rdi
callq 0x122d40
cmpl $0x0, %eax
je 0x124438
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0x124477
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x123ad0
jmp 0x124501
movq -0x20(%rbp), %rdi
callq 0x122d40
cmpl $0x0, %eax
je 0x1244af
movq -0x20(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0x1244ff
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1244e5
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x123ad0
jmp 0x1244fd
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x123760
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
jmp 0x1244ff
jmp 0x124501
movl $0x1, -0x4(%rbp)
jmp 0x12468d
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x124686
movq -0x20(%rbp), %rdi
callq 0x122d10
cmpl $0x0, %eax
jne 0x12460f
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x12454a
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x124556
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x122d10
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x124575
jmp 0x124583
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x12455e
movq -0x30(%rbp), %rdi
callq 0x122d40
cmpl $0x0, %eax
je 0x1245cd
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0x12460d
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x123ad0
jmp 0x12467d
movq -0x20(%rbp), %rdi
callq 0x122d40
cmpl $0x0, %eax
je 0x12462b
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0x12467b
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x124661
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x123ad0
jmp 0x124679
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x123760
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
jmp 0x12467b
jmp 0x12467d
movl $0x1, -0x4(%rbp)
jmp 0x12468d
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)