// File: luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::readFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, char**)
size_t FileSystem::readFile(std::string filename, char** buffer)
{
    std::string root = "files/";
    std::ifstream file(root + filename, std::ifstream::binary);

    if (!file.good())
    {
        std::cout << "readFile: Could not open file: " << filename << std::endl;
        logFile << "readFile: Could not open file: " << filename << std::endl;
        return 0;
    }

    file.seekg (0, file.end);
    size_t length = file.tellg();
    file.seekg (0, file.beg);        

    *buffer = new char [length];

    file.read (*buffer,length);
    file.close();

    logFile << "readFile " << root + filename << " read" << std::endl;
    // std::cout << "readFile " << root + filename << " read" << std::endl;

    return length;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rsi, -0x2d8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x46b0
movq -0x2c8(%rbp), %rdx
leaq 0x94a3(%rip), %rsi      # 0x1cb7a
leaq -0x40(%rbp), %rdi
callq 0x4510
jmp 0x136e2
leaq -0x41(%rbp), %rdi
callq 0x4430
movq -0x2d8(%rbp), %rdx
leaq -0x280(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x16820
jmp 0x13704
leaq -0x260(%rbp), %rdi
leaq -0x280(%rbp), %rsi
movl $0x4, %edx
callq 0x45f0
jmp 0x1371e
leaq -0x280(%rbp), %rdi
callq 0x42a0
movq -0x260(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x260(%rbp,%rax), %rdi
callq 0x4620
movb %al, -0x2d9(%rbp)
jmp 0x1374a
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x13864
jmp 0x1375a
movq 0x1385f(%rip), %rdi     # 0x26fc0
leaq 0x942a(%rip), %rsi      # 0x1cb92
callq 0x43f0
movq %rax, -0x2e8(%rbp)
jmp 0x13776
movq -0x2d8(%rbp), %rsi
movq -0x2e8(%rbp), %rdi
callq 0x4370
movq %rax, -0x2f0(%rbp)
jmp 0x13792
movq -0x2f0(%rbp), %rdi
movq 0x13808(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x137a7
movq -0x2d0(%rbp), %rdi
leaq 0x93dd(%rip), %rsi      # 0x1cb92
callq 0x43f0
movq %rax, -0x2f8(%rbp)
jmp 0x137c3
movq -0x2d8(%rbp), %rsi
movq -0x2f8(%rbp), %rdi
callq 0x4370
movq %rax, -0x300(%rbp)
jmp 0x137df
movq -0x300(%rbp), %rdi
movq 0x137bb(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x137f4
movq $0x0, -0x8(%rbp)
movl $0x1, -0x284(%rbp)
jmp 0x139f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x4430
jmp 0x13a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x13a22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x42a0
jmp 0x13a22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x13a16
xorl %eax, %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
movl $0x2, %edx
callq 0x44f0
jmp 0x1387b
leaq -0x260(%rbp), %rdi
callq 0x4680
movq %rdx, -0x310(%rbp)
movq %rax, -0x308(%rbp)
jmp 0x13897
movq -0x310(%rbp), %rax
movq -0x308(%rbp), %rcx
movq %rcx, -0x2a0(%rbp)
movq %rax, -0x298(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x168e0
movq %rax, -0x318(%rbp)
jmp 0x138c8
movq -0x318(%rbp), %rax
movq %rax, -0x290(%rbp)
xorl %edx, %edx
movl %edx, %esi
leaq -0x260(%rbp), %rdi
callq 0x44f0
jmp 0x138e8
movq -0x290(%rbp), %rdi
callq 0x4030
movq %rax, -0x320(%rbp)
jmp 0x138fd
movq -0x320(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movq -0x290(%rbp), %rdx
leaq -0x260(%rbp), %rdi
callq 0x4480
jmp 0x13927
leaq -0x260(%rbp), %rdi
callq 0x4100
jmp 0x13935
movq -0x2d0(%rbp), %rdi
leaq 0x926f(%rip), %rsi      # 0x1cbb2
callq 0x43f0
movq %rax, -0x328(%rbp)
jmp 0x13951
movq -0x2d8(%rbp), %rdx
leaq -0x2c0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x16820
jmp 0x1396a
movq -0x328(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x4370
movq %rax, -0x330(%rbp)
jmp 0x13986
movq -0x330(%rbp), %rdi
leaq 0x9228(%rip), %rsi      # 0x1cbbc
callq 0x43f0
movq %rax, -0x338(%rbp)
jmp 0x139a2
movq -0x338(%rbp), %rdi
movq 0x135f8(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x139b7
leaq -0x2c0(%rbp), %rdi
callq 0x42a0
movq -0x290(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x284(%rbp)
jmp 0x139f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x42a0
jmp 0x13a16
leaq -0x260(%rbp), %rdi
callq 0x4120
leaq -0x40(%rbp), %rdi
callq 0x42a0
movq -0x8(%rbp), %rax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x4120
leaq -0x40(%rbp), %rdi
callq 0x42a0
movq -0x50(%rbp), %rdi
callq 0x46a0
nopw %cs:(%rax,%rax)