// File: /workspace/github_cpp_makefile_star2_O3/SeanChao[P]KV-Store/kvstore.cc
// Function: KVStore::merge(std::vector<Pair, std::allocator<Pair>>, std::vector<Pair, std::allocator<Pair>>)
std::vector<Pair> KVStore::merge(std::vector<Pair> a, std::vector<Pair> b) {
    std::vector<Pair> tmp;
    size_t i = 0, j = 0;
    while (i < a.size() && j < b.size()) {
        if (a[i].key < b[j].key)
            tmp.push_back(a[i++]);
        else if (a[i].key > b[j].key)
            tmp.push_back(b[j++]);
        else {
            // two entries with the same key, keeps the one with newer timestamp
            Pair p = a[i].time > b[j].time ? a[i] : b[j];
            tmp.push_back(p);
            i++;
            j++;
        }
    }
    while (i < a.size()) {
        tmp.push_back(a[i++]);
    }
    while (j < b.size()) {
        tmp.push_back(b[j++]);
    }
    // std::clog << "tmp merged: " << std::endl;
    // for (auto i : tmp) {
    //     std::clog << i.key << " " << i.val << std::endl;
    // }
    return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rdx), %rcx
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rcx, 0x8(%rdx)
je 0x83da
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%r14), %rdx
movq 0x8(%r14), %rax
subq %rdx, %rax
sarq $0x4, %rax
imulq %rbp, %rax
cmpq %rax, %r12
jae 0x83e0
leaq (,%r13,2), %rdi
addq %r13, %rdi
shlq $0x4, %rdi
leaq (%rcx,%rdi), %rsi
leaq (%r12,%r12,2), %r8
shlq $0x4, %r8
leaq (%rdx,%r8), %rax
movq (%rdx,%r8), %rdx
cmpq %rdx, (%rcx,%rdi)
jae 0x834b
movq %rbx, %rdi
callq 0x93b4
incq %r13
jmp 0x83bd
jbe 0x835a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x93b4
jmp 0x83ba
movq 0x8(%rsi), %rcx
cmpq 0x8(%rax), %rcx
jg 0x8367
movq %rax, %rsi
movups (%rsi), %xmm0
movaps %xmm0, (%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rdx
addq %rax, %rdx
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x95b2
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x93b4
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x83b7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3280
incq %r13
incq %r12
movq (%r15), %rcx
movq 0x8(%r15), %rax
subq %rcx, %rax
sarq $0x4, %rax
imulq %rbp, %rax
cmpq %rax, %r13
jb 0x82fa
jmp 0x83e0
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r13, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbp
decq %r13
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
sarq $0x4, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
incq %r13
cmpq %rax, %r13
jae 0x8423
addq %rbp, %rsi
addq $0x30, %rbp
movq %rbx, %rdi
callq 0x93b4
jmp 0x83ee
movq %r12, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %r15
decq %r12
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq (%r14), %rsi
movq 0x8(%r14), %rax
subq %rsi, %rax
sarq $0x4, %rax
imulq %r13, %rax
incq %r12
cmpq %rax, %r12
jae 0x8466
addq %r15, %rsi
addq $0x30, %r15
movq %rbx, %rdi
callq 0x93b4
jmp 0x843b
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x84a2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x84a2
jmp 0x849f
jmp 0x849f
jmp 0x849f
movq %rax, %r14
movq %rbx, %rdi
callq 0x9166
movq %r14, %rdi
callq 0x33f0