// File: /workspace/github_cpp_makefile_star2_O3/SeanChao[P]KV-Store/kvstore.cc
// Function: KVStore::readSsTable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void KVStore::readSsTable(std::string path) {
    // load index table into indexTableList
    std::ifstream fs(path, std::ios::binary);
    // std::clog << "read ss table from " << path << std::endl;
    // reads the offest of the begining of the index part
    if (!fs.is_open()) {
        // std::clog << "Error open file " << path << std::endl;
    }
    fs.seekg(-8, std::ios::end);
    uint64_t offset = 0;
    fs.read(reinterpret_cast<char *>(&offset), sizeof(offset));
    // std::clog << "read: get offset of index table at " << std::hex << offset
    //           << std::dec << std::endl;
    // reads keys and indices and saves them in indexTable
    fs.seekg(offset);
    std::vector<Index> indexTable;
    while (!fs.eof()) {
        uint64_t key = 0;
        uint64_t off = 0;
        // int64_t time = 0;
        fs.read(reinterpret_cast<char *>(&key), sizeof(key));
        // fs.read(reinterpret_cast<char *>(&time), sizeof(time));
        fs.read(reinterpret_cast<char *>(&off), sizeof(off));
        if (fs.gcount() == 0)
            break;  // if fs comes to meta data then break, this condition may
                    // fail if the meta data changes
        // std::clog << "read key: " << key << std::hex << " @0x" << off << " "
        // << std::dec << fs.gcount() << std::endl;
        indexTable.push_back(Index(key, off));
    }
    fs.close();
    // for(auto i: indexTable) {
    //     std::clog << "key " << i.key << "offset "
    // }
    indexTableList.push_back(indexTable);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdi, %rbx
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movl $0x4, %edx
callq 0x3370
movq %r14, %rdi
movq $-0x8, %rsi
movl $0x2, %edx
callq 0x3330
leaq 0x38(%rsp), %rsi
movq $0x0, (%rsi)
leaq 0x40(%rsp), %rdi
movl $0x8, %edx
callq 0x32f0
movq 0x38(%rsp), %rsi
leaq 0x40(%rsp), %rdi
xorl %edx, %edx
callq 0x3300
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x60(%rsp,%rax)
jne 0x795c
xorl %r13d, %r13d
leaq 0x40(%rsp), %r14
leaq 0x20(%rsp), %r15
leaq 0x18(%rsp), %r12
leaq 0x28(%rsp), %rbp
movq %r13, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x32f0
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x32f0
cmpq $0x0, 0x48(%rsp)
je 0x795c
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rax, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x7941
movups 0x28(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rsp)
jmp 0x794c
movq %rsp, %rdi
movq %rbp, %rdx
callq 0xa1b4
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x60(%rsp,%rax)
je 0x78df
leaq 0x40(%rsp), %rdi
callq 0x3060
addq $0x40, %rbx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x913a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x798b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3280
leaq 0x40(%rsp), %rdi
callq 0x30b0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x79ab
jmp 0x79b2
movq %rax, %rbx
jmp 0x79cb
jmp 0x79b2
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x79cb
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3280
leaq 0x40(%rsp), %rdi
callq 0x30b0
movq %rbx, %rdi
callq 0x33f0
nop