// File: xx01cyx[P]LSM-Tree/SSTable.cc
// Function: SSTable::getValuesFromDisk(std::unordered_map<unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<std::pair<unsigned long const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&) const
void SSTable::getValuesFromDisk(KVPair& sstData) const {

    string filename = getFilename();
    ifstream table(filename, ios::in | ios::binary);
    if (!table) {
        cerr << "Cannot open file `" << filename << "`." << endl;
        exit(-1);
    }

    table.seekg(0, ios::end);
    uint32_t fileLength = table.tellg();

    uint32_t dataStart = HEADER_SIZE + BLOOM_FILTER_SIZE + DATA_INDEX_SIZE * header.keyNumber;
    table.seekg(dataStart, ios::beg);

    uint32_t start = dataStart;
    uint32_t end;

    auto it = dataIndexes.cbegin();
    LsmKey key = (*it).key;
    it++;
    while (it != dataIndexes.cend()) {
        end = (*it).offset;
        LsmValue value = readValueFromFile(table, start, end, true);
        sstData[key] = value;
        start = end;
        key = (*it).key;    // Get key for the next loop.
        it++;
    }

    // Set the last k-v pair.
    end = fileLength;
    LsmValue value = readValueFromFile(table, start, end, true);
    sstData[key] = value;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x2e0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9070
movl $0x8, %edi
movl $0x4, %esi
callq 0x9bb0
movl %eax, -0x2d4(%rbp)
jmp 0x94ee
movl -0x2d4(%rbp), %edx
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x44f0
jmp 0x9506
movq -0x238(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x238(%rbp,%rax), %rdi
callq 0x4150
movb %al, -0x2e1(%rbp)
jmp 0x9526
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x9535
jmp 0x95d3
movq 0x28ab4(%rip), %rdi     # 0x31ff0
leaq 0x19c55(%rip), %rsi     # 0x23198
callq 0x42c0
movq %rax, -0x2f0(%rbp)
jmp 0x9551
movq -0x2f0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4270
movq %rax, -0x2f8(%rbp)
jmp 0x956a
movq -0x2f8(%rbp), %rdi
leaq 0x19c33(%rip), %rsi     # 0x231ab
callq 0x42c0
movq %rax, -0x300(%rbp)
jmp 0x9586
movq -0x300(%rbp), %rdi
movq 0x28a1c(%rip), %rsi     # 0x31fb0
callq 0x4300
jmp 0x959b
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x9885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x9879
xorl %eax, %eax
movl %eax, %esi
leaq -0x238(%rbp), %rdi
movl $0x2, %edx
callq 0x43f0
jmp 0x95ea
leaq -0x238(%rbp), %rdi
callq 0x4540
movq %rdx, -0x310(%rbp)
movq %rax, -0x308(%rbp)
jmp 0x9606
movq -0x310(%rbp), %rax
movq -0x308(%rbp), %rcx
movq %rcx, -0x258(%rbp)
movq %rax, -0x250(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x9c10
movq %rax, -0x318(%rbp)
jmp 0x9637
movq -0x2e0(%rbp), %rax
movq -0x318(%rbp), %rcx
movl %ecx, -0x248(%rbp)
movl 0x10(%rax), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %ecx
movl %ecx, %eax
leal 0x2820(,%rax,4), %eax
movl %eax, -0x25c(%rbp)
movl -0x25c(%rbp), %eax
movl %eax, %esi
leaq -0x238(%rbp), %rdi
xorl %edx, %edx
callq 0x43f0
jmp 0x967a
movq -0x2e0(%rbp), %rdi
movl -0x25c(%rbp), %eax
movl %eax, -0x260(%rbp)
addq $0x30, %rdi
callq 0x9c30
movq %rax, -0x270(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x9c60
movq (%rax), %rax
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
xorl %esi, %esi
callq 0x9c80
movq %rax, -0x280(%rbp)
movq -0x2e0(%rbp), %rdi
addq $0x30, %rdi
callq 0x9d00
movq %rax, -0x288(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x9cc0
testb $0x1, %al
jne 0x96fb
jmp 0x97d0
leaq -0x270(%rbp), %rdi
callq 0x9c60
movl 0x8(%rax), %eax
movl %eax, -0x264(%rbp)
movl -0x260(%rbp), %edx
movl -0x264(%rbp), %ecx
leaq -0x2a8(%rbp), %rdi
leaq -0x238(%rbp), %rsi
movl $0x1, %r8d
callq 0x93d0
jmp 0x9737
movq -0x10(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x9d30
movq %rax, -0x320(%rbp)
jmp 0x9750
movq -0x320(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x4050
jmp 0x9765
movl -0x264(%rbp), %eax
movl %eax, -0x260(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x9c60
movq (%rax), %rax
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
xorl %esi, %esi
callq 0x9c80
movq %rax, -0x2b0(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x4608
jmp 0x96c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x4608
jmp 0x9879
movl -0x248(%rbp), %eax
movl %eax, -0x264(%rbp)
movl -0x260(%rbp), %edx
movl -0x264(%rbp), %ecx
leaq -0x2d0(%rbp), %rdi
leaq -0x238(%rbp), %rsi
movl $0x1, %r8d
callq 0x93d0
jmp 0x9803
movq -0x10(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x9d30
movq %rax, -0x328(%rbp)
jmp 0x981c
movq -0x328(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x4050
jmp 0x9831
leaq -0x2d0(%rbp), %rdi
callq 0x4608
leaq -0x238(%rbp), %rdi
callq 0x40a0
leaq -0x30(%rbp), %rdi
callq 0x4608
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x4608
leaq -0x238(%rbp), %rdi
callq 0x40a0
leaq -0x30(%rbp), %rdi
callq 0x4608
movq -0x240(%rbp), %rdi
callq 0x4560
nopw (%rax,%rax)