// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x5e09(%rip), %rsi      # 0x13b91
leaq 0x5e08(%rip), %rdx      # 0x13b97
leaq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0xa686
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10162
leaq -0x270(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x4, %edx
callq 0x4570
leaq -0x38(%rbp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0xddd1
callq 0x4360
movq -0x270(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x250(%rbp,%rax)
je 0xde94
movq 0xb1cf(%rip), %rdi      # 0x18fc0
leaq 0x5db1(%rip), %rsi      # 0x13ba9
movl $0x1f, %edx
callq 0x43f0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0xb1b0(%rip), %rdi      # 0x18fc0
callq 0x43f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
leaq 0x5d63(%rip), %rsi      # 0x13ba9
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x43f0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
xorl %r15d, %r15d
jmp 0xdf70
leaq -0x270(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x4470
leaq -0x270(%rbp), %rdi
callq 0x4600
movq %rax, %r15
leaq -0x270(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4470
movq %r15, %rdi
callq 0x4030
movq %rax, (%r12)
leaq -0x270(%rbp), %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x4420
leaq -0x270(%rbp), %rdi
callq 0x40d0
leaq 0x5cd2(%rip), %rsi      # 0x13bc9
movl $0x9, %edx
movq %rbx, %rdi
callq 0x43f0
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movq %r14, %rdx
callq 0x10162
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x5ca5(%rip), %rsi      # 0x13bd3
movl $0x5, %edx
movq %rax, %rdi
callq 0x43f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0xdf70
callq 0x4360
leaq -0x270(%rbp), %rdi
callq 0x40f0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xdf8e
callq 0x4360
movq %r15, %rax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdfd8
jmp 0xdfd8
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdfe7
callq 0x4360
jmp 0xdfe7
movq %rax, %rbx
jmp 0xdfe7
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0xdfdb
callq 0x4360
jmp 0xdfdb
jmp 0xdfd8
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
callq 0x40f0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xdff9
callq 0x4360
movq %rbx, %rdi
callq 0x4630
nop