// File: /workspace/github_cpp_makefile_star2_O3/xx01cyx[P]LSM-Tree/MemTable.cc
// Function: MemTable::put(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void MemTable::put(LsmKey k, const LsmValue& v) {

    stack<Node*> path = stack<Node*>();
    Node* p = head;

    while (p) {
        while (p->next && p->next->key < k)
            p = p->next;
        if (p->next && k == p->next->key) {    // substitute
            p = p->next;        // p points to the topmost existing node
            while (p) {
                p->value = v;
                p = p->down;
            }
            return;
        }
        path.push(p);
        p = p->down;
    }

    Node* prevAddedNode = nullptr;
    do {                                // 50% add a new layer
        Node* prev;
        if (!path.empty()) {
            prev = path.top();
            path.pop();
        } else {
            prev = head = new Node(head);
        }
        Node* newNode = new Node(k, v, prev->next, prevAddedNode);
        prev->next = newNode;
        prevAddedNode = newNode;
    } while (rand() & 1);

    keyNumber++;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x7ce6
movq %r14, 0x8(%rsp)
movq (%r14), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x6f2e
leaq 0x30(%rsp), %r12
movq %rsp, %r13
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0x6ef4
movq (%rdi), %rcx
cmpq %r15, %rcx
jae 0x6ee6
movq %rdi, %rax
movq 0x28(%rdi), %rdi
testq %rdi, %rdi
je 0x6ef0
movq (%rdi), %rcx
cmpq %r15, %rcx
jb 0x6ece
movq %rax, (%rsp)
cmpq %r15, %rcx
jne 0x6ef4
jmp 0x707c
movq %rax, (%rsp)
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x6f12
movq %rax, (%rcx)
addq $0x8, 0x60(%rsp)
jmp 0x6f1d
movq %r12, %rdi
movq %r13, %rsi
callq 0x7e5c
movq (%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, (%rsp)
testq %rax, %rax
jne 0x6ebd
leaq 0x20(%rsp), %r12
xorl %r14d, %r14d
movq 0x60(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x6f59
movq 0x68(%rsp), %rdi
cmpq %rdi, %rax
je 0x6f95
movq -0x8(%rax), %r13
addq $-0x8, %rax
jmp 0x6fda
movl $0x38, %edi
callq 0x3270
movq %rax, %r13
movq 0x8(%rsp), %rdx
movq (%rdx), %rax
xorl %esi, %esi
movq %rsi, (%r13)
movq %r13, %rcx
addq $0x18, %rcx
movq %rcx, 0x8(%r13)
movq %rsi, 0x10(%r13)
movb $0x0, 0x18(%r13)
movq %rsi, 0x28(%r13)
movq %rax, 0x30(%r13)
movq %r13, (%rdx)
jmp 0x6fdf
movq 0x78(%rsp), %rax
movq -0x8(%rax), %rax
movq 0x1f8(%rax), %r13
movl $0x200, %esi            # imm = 0x200
callq 0x3280
movq 0x78(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x78(%rsp)
movq -0x8(%rax), %rax
movq %rax, 0x68(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x70(%rsp)
movl $0x1f8, %ecx            # imm = 0x1F8
addq %rcx, %rax
movq %rax, 0x60(%rsp)
movl $0x38, %edi
callq 0x3270
movq %rax, %rbp
movq %r12, 0x10(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x55b2
movq 0x28(%r13), %rax
movq %r15, (%rbp)
movq %rbp, %rcx
addq $0x18, %rcx
movq %rcx, 0x8(%rbp)
movq 0x10(%rsp), %rdx
cmpq %r12, %rdx
je 0x7031
movq %rdx, 0x8(%rbp)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rbp)
jmp 0x7039
movups (%r12), %xmm0
movups %xmm0, (%rcx)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rbp)
movq %r12, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %rax, 0x28(%rbp)
movq %r14, 0x30(%rbp)
movq %rbp, 0x28(%r13)
callq 0x3080
movq %rbp, %r14
testb $0x1, %al
jne 0x6f36
movq 0x8(%rsp), %rax
incq 0x8(%rax)
jmp 0x709d
movq %rdi, (%rsp)
addq $0x8, %rdi
movq %rbx, %rsi
callq 0x3160
movq (%rsp), %rax
movq 0x30(%rax), %rdi
movq %rdi, (%rsp)
testq %rdi, %rdi
jne 0x7080
leaq 0x30(%rsp), %rdi
callq 0x7c1e
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x70bf
jmp 0x70bf
jmp 0x70bf
movq %rax, %rbx
jmp 0x70d4
movq %rax, %rbx
movl $0x38, %esi
movq %rbp, %rdi
callq 0x3280
leaq 0x30(%rsp), %rdi
callq 0x7c1e
movq %rbx, %rdi
callq 0x3460