// File: xx01cyx[P]LSM-Tree/SSTable.cc
// Function: SSTable::getValueFromDisk[abi:cxx11](unsigned long) const
LsmValue SSTable::getValueFromDisk(size_t index) const {

    string filename = getFilename();

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

    // Find the start and end of the value.
    uint32_t start = dataIndexes[index].offset;
    uint32_t end;
    if (index != dataIndexes.size() - 1)
        end = dataIndexes[index + 1].offset;
    else {      // If `key` is the last key, set `end` as the length of the file.
        table.seekg(0, ios::end);
        end = table.tellg();
    }

    // Read value from the file.
    LsmValue value = readValueFromFile(table, start, end, false);

    // Close the file.
    table.close();

    return value;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x288(%rbp)
movq %rdi, %rax
movq %rax, -0x280(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x278(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x9070
movl $0x8, %edi
movl $0x4, %esi
callq 0x9bb0
movl %eax, -0x270(%rbp)
jmp 0x8de3
movl -0x270(%rbp), %edx
leaq -0x240(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x44f0
jmp 0x8dfb
movq -0x240(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x240(%rbp,%rax), %rdi
callq 0x4150
movb %al, -0x289(%rbp)
jmp 0x8e1b
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0x8e2a
jmp 0x8ec8
movq 0x291bf(%rip), %rdi     # 0x31ff0
leaq 0x1a360(%rip), %rsi     # 0x23198
callq 0x42c0
movq %rax, -0x298(%rbp)
jmp 0x8e46
movq -0x298(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4270
movq %rax, -0x2a0(%rbp)
jmp 0x8e5f
movq -0x2a0(%rbp), %rdi
leaq 0x1a33e(%rip), %rsi     # 0x231ab
callq 0x42c0
movq %rax, -0x2a8(%rbp)
jmp 0x8e7b
movq -0x2a8(%rbp), %rdi
movq 0x29127(%rip), %rsi     # 0x31fb0
callq 0x4300
jmp 0x8e90
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x904f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x9043
movq -0x278(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0x9bd0
movq -0x278(%rbp), %rdi
movl 0x8(%rax), %eax
movl %eax, -0x250(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x2b0(%rbp)
addq $0x30, %rdi
callq 0x9bf0
movq %rax, %rcx
movq -0x2b0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x8f36
movq -0x278(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
callq 0x9bd0
movl 0x8(%rax), %eax
movl %eax, -0x254(%rbp)
jmp 0x8fa7
xorl %eax, %eax
movl %eax, %esi
leaq -0x240(%rbp), %rdi
movl $0x2, %edx
callq 0x43f0
jmp 0x8f4d
leaq -0x240(%rbp), %rdi
callq 0x4540
movq %rdx, -0x2c0(%rbp)
movq %rax, -0x2b8(%rbp)
jmp 0x8f69
movq -0x2c0(%rbp), %rax
movq -0x2b8(%rbp), %rcx
movq %rcx, -0x268(%rbp)
movq %rax, -0x260(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x9c10
movq %rax, -0x2c8(%rbp)
jmp 0x8f9a
movq -0x2c8(%rbp), %rax
movl %eax, -0x254(%rbp)
movq -0x288(%rbp), %rdi
movb $0x0, -0x269(%rbp)
movl -0x250(%rbp), %edx
movl -0x254(%rbp), %ecx
leaq -0x240(%rbp), %rsi
xorl %r8d, %r8d
callq 0x93d0
jmp 0x8fd2
leaq -0x240(%rbp), %rdi
callq 0x4070
jmp 0x8fe0
movb $0x1, -0x269(%rbp)
testb $0x1, -0x269(%rbp)
jne 0x901e
jmp 0x9012
movq -0x288(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
callq 0x4608
jmp 0x9043
movq -0x288(%rbp), %rdi
callq 0x4608
leaq -0x240(%rbp), %rdi
callq 0x40a0
leaq -0x38(%rbp), %rdi
callq 0x4608
movq -0x280(%rbp), %rax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0x240(%rbp), %rdi
callq 0x40a0
leaq -0x38(%rbp), %rdi
callq 0x4608
movq -0x248(%rbp), %rdi
callq 0x4560
nopw %cs:(%rax,%rax)