// File: /workspace/github_cpp_makefile_star2_O3/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 0x9936
movq (%r12), %rax
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x8db1
movq 0x6225(%rip), %rcx      # 0xefc8
cmpb $0x0, (%rcx)
je 0x8dad
incl 0x8(%rdi)
jmp 0x8db1
lock
incl 0x8(%rdi)
testq %rax, %rax
je 0x8f1e
cmpq $0x0, 0x28(%rax)
je 0x8f1e
cmpq $0x0, 0x38(%rax)
je 0x8f1e
movq 0x8(%rsp), %rax
movq (%rax), %r12
testq %rdi, %rdi
je 0x8de2
callq 0x9436
cmpq %r15, %r12
jne 0x8f28
movq (%r14), %rdi
movq 0x8(%rsp), %rsi
testq %rdi, %rdi
je 0x8e06
addq $0x8, %rsi
callq 0x3170
movq 0x8(%rsp), %rsi
movb $0x1, %bpl
testq %rsi, %rsi
je 0x8f2a
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 0x94a6
movq 0x8(%rsp), %rsi
movq 0x28(%rsi), %rax
movq 0x38(%rsi), %rdi
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
addq $0x30, %rsi
callq 0x94a6
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rcx
cmpq $0x0, 0x28(%rcx)
jne 0x8e74
movq 0x38(%rax), %rcx
cmpq $0x0, 0x38(%rcx)
je 0x8e9d
movq 0x8(%rsp), %rsi
movq 0x58(%rsi), %rax
movq %rax, 0x8(%rsp)
addq $0x60, %rsi
movq %r14, %rdi
callq 0x94a6
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
jne 0x8e22
jmp 0x8f2a
cmpq $0x0, 0x58(%rax)
je 0x8e74
movq (%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, 0x38(%rsi)
jne 0x8e74
cmpq %rsi, 0x28(%rax)
jne 0x8e74
movq 0x58(%rsi), %rax
movq %rax, (%rbx)
addq $0x60, %rsi
movq %r15, %rdi
callq 0x94a6
movq (%rbx), %rax
movq %r13, 0x48(%rax)
movq 0x50(%rax), %rdi
movq %r13, 0x50(%rax)
testq %rdi, %rdi
je 0x8ee3
callq 0x9436
movq 0x10(%rbx), %rsi
movq 0x58(%rsi), %rax
movq %rax, 0x10(%rbx)
addq $0x60, %rsi
movq %r12, %rdi
callq 0x94a6
movq 0x10(%rbx), %rax
movq %r13, 0x48(%rax)
movq 0x50(%rax), %rdi
movq %r13, 0x50(%rax)
testq %rdi, %rdi
je 0x8e74
callq 0x9436
jmp 0x8e74
testq %rdi, %rdi
je 0x8f28
callq 0x9436
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8f39
callq 0x9436
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 0x8f5c
callq 0x9436
movq %rbx, %rdi
callq 0x33f0