// File: xx01cyx[P]LSM-Tree/kvstore.cc
// Function: KVStore::readSSTFromDisk(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long)
SSTPtr KVStore::readSSTFromDisk(const string& filename, size_t level) {
    SSTHeader sstHeader;
    bool* byteArray = new bool[BLOOM_FILTER_SIZE];
    vector<DataIndex> dataIndexes;

    ifstream sstFile(filename, ios::binary | ios::in);
    if (!sstFile) {
        cerr << "Cannot open file `" << filename << "`." << endl;
        exit(-1);
    }

    sstFile.read((char*)&sstHeader, HEADER_SIZE);
    sstFile.read((char*)byteArray, BLOOM_FILTER_SIZE);

    uint64_t keyNumber = sstHeader.keyNumber;
    for (uint32_t i = 0; i < keyNumber; ++i) {
        DataIndex dataIndex;
        sstFile.read((char*)&dataIndex, DATA_INDEX_SIZE);
        dataIndexes.push_back(dataIndex);
    }

    BloomFilter bloomFilter(byteArray);
    SSTPtr sst = make_shared<SSTable>(level, sstHeader, bloomFilter, dataIndexes);
    return sst;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x2b8(%rbp)
movq %rdi, %rax
movq %rax, -0x2b0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xd190
movl $0x2800, %edi           # imm = 0x2800
callq 0x4030
movq %rax, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xd1a0
movq -0x10(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x9bb0
movl %eax, -0x2a0(%rbp)
jmp 0x1177a
movl -0x2a0(%rbp), %edx
movq -0x2a8(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x44f0
jmp 0x11795
movq -0x260(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x260(%rbp,%rax), %rdi
callq 0x4150
movb %al, -0x2b9(%rbp)
jmp 0x117b5
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x117c4
jmp 0x11862
movq 0x20825(%rip), %rdi     # 0x31ff0
leaq 0x119c6(%rip), %rsi     # 0x23198
callq 0x42c0
movq %rax, -0x2c8(%rbp)
jmp 0x117e0
movq -0x2c8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4270
movq %rax, -0x2d0(%rbp)
jmp 0x117f9
movq -0x2d0(%rbp), %rdi
leaq 0x119a4(%rip), %rsi     # 0x231ab
callq 0x42c0
movq %rax, -0x2d8(%rbp)
jmp 0x11815
movq -0x2d8(%rbp), %rdi
movq 0x2078d(%rip), %rsi     # 0x31fb0
callq 0x4300
jmp 0x1182a
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x119b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x119aa
leaq -0x260(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0x20, %edx
callq 0x43a0
jmp 0x11879
movq -0x40(%rbp), %rsi
leaq -0x260(%rbp), %rdi
movl $0x2800, %edx           # imm = 0x2800
callq 0x43a0
jmp 0x11890
movq -0x30(%rbp), %rax
movq %rax, -0x278(%rbp)
movl $0x0, -0x27c(%rbp)
movl -0x27c(%rbp), %eax
cmpq -0x278(%rbp), %rax
jae 0x11901
leaq -0x290(%rbp), %rdi
callq 0x16480
jmp 0x118c2
leaq -0x260(%rbp), %rdi
leaq -0x290(%rbp), %rsi
movl $0xc, %edx
callq 0x43a0
jmp 0x118dc
leaq -0x58(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0xd1f0
jmp 0x118ee
jmp 0x118f0
movl -0x27c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27c(%rbp)
jmp 0x118a5
movq -0x40(%rbp), %rsi
leaq -0x298(%rbp), %rdi
callq 0x8140
jmp 0x11913
movq -0x2b8(%rbp), %rdi
movb $0x0, -0x299(%rbp)
leaq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x298(%rbp), %rcx
leaq -0x58(%rbp), %r8
callq 0x16490
jmp 0x1193b
movb $0x1, -0x299(%rbp)
testb $0x1, -0x299(%rbp)
jne 0x11979
jmp 0x1196d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x8190
jmp 0x119aa
movq -0x2b8(%rbp), %rdi
callq 0xd350
leaq -0x298(%rbp), %rdi
callq 0x8190
leaq -0x260(%rbp), %rdi
callq 0x40a0
leaq -0x58(%rbp), %rdi
callq 0x9b30
movq -0x2b0(%rbp), %rax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x40a0
leaq -0x58(%rbp), %rdi
callq 0x9b30
movq -0x268(%rbp), %rdi
callq 0x4560
nopl (%rax,%rax)