// 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>>>::put(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool SkipList<Key, Value>::put(Key key, Value value) {
    std::shared_ptr<Node> newNode(new Node(key, value));
    std::shared_ptr<Node> ptr = skipSearch(key);  // nearest element's top level
    // if the key exists, then update its value
    if (ptr->key == key && valid(ptr)) {
        while (ptr) {
            ptr->val = value;
            ptr = ptr->below;
        }
        return true;
    }

    while (ptr->below) ptr = ptr->below;
    newNode->pred = ptr;
    newNode->succ = ptr->succ;
    ptr->succ->pred = newNode;
    ptr->succ = newNode;

    // randomly grow higher
    while (rand() & 1) {
        // find the nearest node with higher level
        while (ptr->pred && !ptr->above) ptr = ptr->pred;
        // generate the head for new higher level
        if (!ptr->above) {
            std::shared_ptr<Node> newHead(new Node());  // new head
            std::shared_ptr<Node> newTail(new Node());  // new trailing node
            newHead->below = head;
            newHead->succ = newTail;
            head->above = newHead;
            newTail->pred = newHead;
            newTail->below = tail;
            tail->above = newTail;
            head = newHead;
            tail = newTail;
        }
        ptr = ptr->above;
        // build the new level
        std::shared_ptr<Node> growNode(new Node(key, value));
        growNode->pred = ptr;
        growNode->succ = ptr->succ;
        growNode->below = newNode;
        ptr->succ->pred = growNode;
        ptr->succ = growNode;
        newNode->above = growNode;
        newNode = growNode;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, 0x30(%rsp)
movl $0x68, %edi
callq 0x3270
movq %rax, %r12
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq %rbx, 0x48(%rsp)
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x95b2
movb $0x1, %bpl
leaq 0x88(%rsp), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x98de
leaq 0x28(%rsp), %rdi
movq %r12, -0x8(%rdi)
xorl %ebp, %ebp
movq %r12, %rsi
callq 0x9648
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x872d
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3280
movq %rsp, %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0x9936
movq (%rsp), %rax
cmpq %r13, (%rax)
jne 0x87e3
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8765
movq 0x686d(%rip), %rcx      # 0xefc8
cmpb $0x0, (%rcx)
je 0x8775
incl 0x8(%rdi)
jmp 0x8779
cmpq $0x0, 0x28(%rax)
je 0x87e3
cmpq $0x0, 0x38(%rax)
jne 0x8793
jmp 0x87e3
lock
incl 0x8(%rdi)
cmpq $0x0, 0x28(%rax)
je 0x87d9
movq 0x38(%rax), %r14
testq %rdi, %rdi
je 0x878e
callq 0x9436
testq %r14, %r14
je 0x87e3
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8be3
leaq 0x8(%rsp), %r14
addq $0x8, %rdi
movq 0x48(%rsp), %rsi
callq 0x3170
movq (%rsp), %rsi
movq 0x58(%rsi), %rax
movq %rax, (%rsp)
addq $0x60, %rsi
movq %r14, %rdi
callq 0x94a6
movq (%rsp), %rdi
testq %rdi, %rdi
jne 0x87a5
jmp 0x8be3
testq %rdi, %rdi
je 0x87e3
callq 0x9436
movq (%rsp), %rsi
movq 0x58(%rsi), %rax
testq %rax, %rax
movq %r13, 0x80(%rsp)
je 0x881a
leaq 0x8(%rsp), %r14
movq %rax, (%rsp)
addq $0x60, %rsi
movq %r14, %rdi
callq 0x94a6
movq (%rsp), %rsi
movq 0x58(%rsi), %rax
testq %rax, %rax
jne 0x87fd
movq 0x20(%rsp), %rdi
movq %rsi, 0x28(%rdi)
addq $0x30, %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0x94a6
movq -0x8(%r13), %rsi
movq 0x20(%rsp), %rdi
movq 0x38(%rsi), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
addq $0x40, %rsi
callq 0x94a6
movq -0x8(%r13), %rax
movq 0x38(%rax), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
leaq 0x28(%rsp), %r14
movq %r14, %rsi
callq 0x94a6
movq -0x8(%r13), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
movq %r14, %rsi
callq 0x94a6
callq 0x30e0
testb $0x1, %al
je 0x8be3
leaq 0x40(%rsp), %r14
movq 0x30(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x78(%rsp)
addq $0x18, %rax
movq %rax, 0x70(%rsp)
leaq 0x60(%rsp), %rbx
leaq 0x18(%rsp), %rbp
leaq 0x50(%rsp), %r12
movq (%rsp), %rsi
movq 0x28(%rsi), %rax
testq %rax, %rax
je 0x88eb
cmpq $0x0, 0x48(%rsi)
jne 0x88eb
movq %rax, (%rsp)
addq $0x30, %rsi
movq %r13, %rdi
callq 0x94a6
jmp 0x88c5
movq 0x48(%rsi), %rax
testq %rax, %rax
jne 0x8a88
movl $0x68, %edi
callq 0x3270
movq %rax, %rcx
addq $0x18, %rcx
movq %rcx, 0x8(%rax)
movq $0x0, 0x10(%rax)
movb $0x0, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movups %xmm0, 0x48(%rax)
movups %xmm0, 0x58(%rax)
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x9648
movl $0x68, %edi
callq 0x3270
movq %rax, %rcx
addq $0x18, %rcx
movq %rcx, 0x8(%rax)
movq $0x0, 0x10(%rax)
movb $0x0, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movups %xmm0, 0x48(%rax)
movups %xmm0, 0x58(%rax)
movq %rax, 0x38(%rsp)
movq %r14, %rdi
movq %rax, %rsi
callq 0x9648
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %r15
movq (%r15), %rax
movq %rax, 0x58(%rdi)
addq $0x60, %rdi
movq 0x78(%rsp), %rbp
movq %rbp, %rsi
callq 0x94a6
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
movq %r14, %rsi
callq 0x94a6
movq (%r15), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rdi)
addq $0x50, %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x94a6
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
movq %rbx, %rsi
callq 0x94a6
movq 0x38(%rsp), %rdi
movq 0x10(%r15), %rax
movq %rax, 0x58(%rdi)
addq $0x60, %rdi
movq 0x70(%rsp), %r12
movq %r12, %rsi
callq 0x94a6
movq 0x10(%r15), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x48(%rdi)
addq $0x50, %rdi
movq %r14, %rsi
callq 0x94a6
movq 0x10(%rsp), %rax
movq %rax, (%r15)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x94a6
movq 0x38(%rsp), %rax
movq %rax, 0x10(%r15)
movq %r12, %rdi
movq %r14, %rsi
callq 0x94a6
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x8a62
callq 0x9436
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
leaq 0x18(%rsp), %rbp
leaq 0x50(%rsp), %r12
leaq 0x60(%rsp), %rbx
je 0x8a80
callq 0x9436
movq (%rsp), %rsi
movq 0x48(%rsi), %rax
movq %r14, %r15
movq %rax, (%rsp)
addq $0x50, %rsi
movq %r13, %rdi
callq 0x94a6
movl $0x68, %edi
callq 0x3270
movq %rax, %r14
movq %rbx, 0x50(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x95b2
movq %r12, %rdx
movb $0x1, %r12b
movq %r14, %rdi
movq 0x80(%rsp), %rsi
callq 0x98de
movq %r14, 0x10(%rsp)
xorl %r12d, %r12d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x9648
movq 0x50(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8b04
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x10(%rsp), %rdi
movq (%rsp), %rax
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
movq %r13, %rsi
callq 0x94a6
movq (%rsp), %rsi
movq 0x10(%rsp), %rdi
movq 0x38(%rsi), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
addq $0x40, %rsi
callq 0x94a6
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x58(%rdi)
addq $0x60, %rdi
leaq 0x28(%rsp), %r14
movq %r14, %rsi
callq 0x94a6
movq (%rsp), %rax
movq 0x38(%rax), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rdi)
addq $0x30, %rdi
movq %rbp, %rsi
callq 0x94a6
movq (%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
movq %rbp, %rsi
callq 0x94a6
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rdi)
addq $0x50, %rdi
movq %rbp, %rsi
callq 0x94a6
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x94a6
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
leaq 0x50(%rsp), %r12
je 0x8bd3
callq 0x9436
callq 0x30e0
testb $0x1, %al
movq %r15, %r14
jne 0x88c5
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8bf2
callq 0x9436
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8c01
callq 0x9436
movb $0x1, %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x8cb3
movq %rax, %r15
jmp 0x8c47
movq %rax, %r15
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x8c42
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3280
testb %bpl, %bpl
je 0x8cc2
movl $0x68, %esi
movq %r12, %rdi
callq 0x3280
jmp 0x8cc2
jmp 0x8c6e
movq %rax, %r15
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x8ca4
callq 0x9436
jmp 0x8ca4
jmp 0x8c6e
movq %rax, %r15
jmp 0x8ca4
movq %rax, %r15
jmp 0x8c97
movq %rax, %r15
movq 0x50(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8c92
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3280
testb %r12b, %r12b
je 0x8ca4
movl $0x68, %esi
movq %r14, %rdi
callq 0x3280
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8cb3
callq 0x9436
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8cc2
callq 0x9436
movq %r15, %rdi
callq 0x33f0