// File: sun98[P]Mini-DFS/datanode.cpp
// Function: DataServer::read()
void DataServer::read()
{
    int start = 0;
    buf = new char[bufSize];
    while (start < bufSize)
    {
        int offset = start / chunkSize;
        std::string filePath = name_ + "/" + std::to_string(fid) + " " + std::to_string(offset);
        std::ifstream is(filePath);
        // file not found in this server.
        if (!is)
        {
            delete[] buf;
            bufSize = 0;
            break;
        }
        is.read(&buf[start], std::min(chunkSize, bufSize - start));
        start += chunkSize;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movl $0x0, -0xc(%rbp)
movslq 0xa4(%rax), %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x2f8(%rbp), %rax
movq %rcx, 0xb0(%rax)
movq -0x2f8(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0xa4(%rcx), %eax
jge 0x4197
movq -0x2f8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl 0x13435(%rip), %ecx     # 0x172f8
cltd
idivl %ecx
movl %eax, -0x10(%rbp)
leaq 0xc15e(%rip), %rdx      # 0x1002e
leaq -0x90(%rbp), %rdi
callq 0x4ba0
movq -0x2f8(%rbp), %rax
movl 0xa0(%rax), %esi
leaq -0xb0(%rbp), %rdi
callq 0x4c20
jmp 0x3ef7
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x4a80
jmp 0x3f10
leaq 0xc2fe(%rip), %rdx      # 0x10215
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4b50
jmp 0x3f26
movl -0x10(%rbp), %esi
leaq -0xe0(%rbp), %rdi
callq 0x4c20
jmp 0x3f37
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x4a80
jmp 0x3f4d
leaq -0xe0(%rbp), %rdi
callq 0x3210
leaq -0x50(%rbp), %rdi
callq 0x3210
leaq -0x70(%rbp), %rdi
callq 0x3210
leaq -0xb0(%rbp), %rdi
callq 0x3210
leaq -0x90(%rbp), %rdi
callq 0x3210
leaq -0x2e8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x34c0
jmp 0x3f9a
movq -0x2e8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2e8(%rbp,%rax), %rdi
callq 0x3190
movb %al, -0x2f9(%rbp)
jmp 0x3fba
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x3fc9
jmp 0x40e7
movq -0x2f8(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x308(%rbp)
cmpq $0x0, %rax
je 0x3ff0
movq -0x308(%rbp), %rdi
callq 0x33b0
movq -0x2f8(%rbp), %rax
movl $0x0, 0xa4(%rax)
movl $0x3, -0x2ec(%rbp)
jmp 0x4164
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x409c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4090
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4087
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x407e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x3210
leaq -0x50(%rbp), %rdi
callq 0x3210
leaq -0x70(%rbp), %rdi
callq 0x3210
leaq -0xb0(%rbp), %rdi
callq 0x3210
leaq -0x90(%rbp), %rdi
callq 0x3210
jmp 0x41a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x418c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x30e0
jmp 0x418c
movq -0x2f8(%rbp), %rax
movq 0xb0(%rax), %rdx
movslq -0xc(%rbp), %rsi
movl %esi, %ecx
addq %rsi, %rdx
movq %rdx, -0x318(%rbp)
movl 0xa4(%rax), %eax
subl %ecx, %eax
movl %eax, -0x2f0(%rbp)
leaq 0x131de(%rip), %rdi     # 0x172f8
leaq -0x2f0(%rbp), %rsi
callq 0x4d40
movq %rax, -0x310(%rbp)
jmp 0x412f
movq -0x318(%rbp), %rsi
movq -0x310(%rbp), %rax
movslq (%rax), %rdx
leaq -0x2e8(%rbp), %rdi
callq 0x3390
jmp 0x414e
movl 0x131a4(%rip), %eax     # 0x172f8
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movl $0x0, -0x2ec(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x30e0
leaq -0x30(%rbp), %rdi
callq 0x3210
movl -0x2ec(%rbp), %eax
testl %eax, %eax
je 0x4187
jmp 0x4185
jmp 0x4197
jmp 0x3e9d
leaq -0x30(%rbp), %rdi
callq 0x3210
jmp 0x41a0
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0x3560
nopl (%rax)