// File: /workspace/github_cpp_makefile_star2_O1/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 0x7e0e
movq %r14, 0x8(%rsp)
movq (%r14), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x7020
leaq 0x30(%rsp), %r12
movq %rsp, %r13
movq (%rsp), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
sete %cl
je 0x6fe6
cmpq %r15, (%rdi)
jae 0x6fd4
movq %rdi, %rax
movq 0x28(%rdi), %rdi
testq %rdi, %rdi
sete %cl
je 0x6fe2
cmpq %r15, (%rdi)
jb 0x6fbc
movq %rax, (%rsp)
testb %cl, %cl
jne 0x6fe6
cmpq %r15, (%rdi)
jne 0x6fe6
jmp 0x718c
movq %rax, (%rsp)
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x7004
movq %rax, (%rcx)
addq $0x8, 0x60(%rsp)
jmp 0x700f
movq %r12, %rdi
movq %r13, %rsi
callq 0x7f84
movq (%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, (%rsp)
testq %rax, %rax
jne 0x6fa7
leaq 0x20(%rsp), %r12
xorl %r14d, %r14d
movq 0x60(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x7061
movq 0x68(%rsp), %rdi
movq %rax, %rcx
cmpq %rdi, %rax
jne 0x7052
movq 0x78(%rsp), %rcx
movq -0x8(%rcx), %rcx
movl $0x200, %edx            # imm = 0x200
addq %rdx, %rcx
movq -0x8(%rcx), %r13
cmpq %rdi, %rax
je 0x709d
addq $-0x8, %rax
jmp 0x70d0
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 0x70d5
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)
addq $0x1f8, %rax            # imm = 0x1F8
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 0x558a
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 0x7127
movq %rdx, 0x8(%rbp)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rbp)
jmp 0x712f
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 0x7028
movq 0x8(%rsp), %rax
incq 0x8(%rax)
leaq 0x30(%rsp), %rdi
callq 0x7d4e
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
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 0x7190
jmp 0x7170
jmp 0x71b5
jmp 0x71b5
jmp 0x71b5
movq %rax, %rbx
jmp 0x71ca
movq %rax, %rbx
movl $0x38, %esi
movq %rbp, %rdi
callq 0x3280
leaq 0x30(%rsp), %rdi
callq 0x7d4e
movq %rbx, %rdi
callq 0x3460