// File: /workspace/github_cpp_makefile_star2_O1/SeanChao[P]KV-Store/./skiplist.h
// Function: SkipList<unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>::remove(unsigned long, std::shared_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>)
bool SkipList<Key, Value>::remove(Key key, std::shared_ptr<Value> backupVal) {
    std::shared_ptr<Node> ptr = skipSearch(key);
    if (!valid(ptr) || ptr->key != key) return false;
    if (backupVal) *backupVal = ptr->val;
    while (ptr) {
        ptr->pred->succ = ptr->succ;
        ptr->succ->pred = ptr->pred;
        // if this level is empty and it's not bottom then delete it
        if (!ptr->pred->pred && !ptr->succ->succ && ptr->below) {
            if (head->succ == tail && tail->pred == head) {
                head = head->below;
                head->above = nullptr;
                tail = tail->below;
                tail->above = nullptr;
            }
        }
        ptr = ptr->below;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x98fa
movq (%r12), %rax
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x8d87
movq 0x624f(%rip), %rcx      # 0xefc8
cmpb $0x0, (%rcx)
je 0x8d83
incl 0x8(%rdi)
jmp 0x8d87
lock
incl 0x8(%rdi)
testq %rax, %rax
je 0x8ef4
cmpq $0x0, 0x28(%rax)
je 0x8ef4
cmpq $0x0, 0x38(%rax)
je 0x8ef4
movq 0x8(%rsp), %rax
movq (%rax), %r12
testq %rdi, %rdi
je 0x8db8
callq 0x9408
cmpq %r15, %r12
jne 0x8efe
movq (%r14), %rdi
testq %rdi, %rdi
je 0x8dd7
movq 0x8(%rsp), %rsi
addq $0x8, %rsi
callq 0x3170
movq 0x8(%rsp), %rsi
movb $0x1, %bpl
testq %rsi, %rsi
je 0x8f00
leaq 0x10(%rsp), %r14
leaq 0x8(%rbx), %r15
leaq 0x18(%rbx), %r12
xorl %r13d, %r13d
movq 0x28(%rsi), %rdi
movq 0x38(%rsi), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
addq $0x40, %rsi
callq 0x9478
movq 0x8(%rsp), %rsi
movq 0x28(%rsi), %rax
movq 0x38(%rsi), %rdi
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
addq $0x30, %rsi
callq 0x9478
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rcx
cmpq $0x0, 0x28(%rcx)
jne 0x8e4a
movq 0x38(%rax), %rcx
cmpq $0x0, 0x38(%rcx)
je 0x8e73
movq 0x8(%rsp), %rsi
movq 0x58(%rsi), %rax
movq %rax, 0x8(%rsp)
addq $0x60, %rsi
movq %r14, %rdi
callq 0x9478
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
jne 0x8df8
jmp 0x8f00
cmpq $0x0, 0x58(%rax)
je 0x8e4a
movq (%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, 0x38(%rsi)
jne 0x8e4a
cmpq %rsi, 0x28(%rax)
jne 0x8e4a
movq 0x58(%rsi), %rax
movq %rax, (%rbx)
addq $0x60, %rsi
movq %r15, %rdi
callq 0x9478
movq (%rbx), %rax
movq %r13, 0x48(%rax)
movq 0x50(%rax), %rdi
movq %r13, 0x50(%rax)
testq %rdi, %rdi
je 0x8eb9
callq 0x9408
movq 0x10(%rbx), %rsi
movq 0x58(%rsi), %rax
movq %rax, 0x10(%rbx)
addq $0x60, %rsi
movq %r12, %rdi
callq 0x9478
movq 0x10(%rbx), %rax
movq %r13, 0x48(%rax)
movq 0x50(%rax), %rdi
movq %r13, 0x50(%rax)
testq %rdi, %rdi
je 0x8e4a
callq 0x9408
jmp 0x8e4a
testq %rdi, %rdi
je 0x8efe
callq 0x9408
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8f0f
callq 0x9408
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8f32
callq 0x9408
movq %rbx, %rdi
callq 0x33f0