// File: /workspace/github_cpp_makefile_star2_O2/luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::saveFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, char*, unsigned long)
bool FileSystem::saveFile(std::string filename, char* buffer, size_t length)
{
    bool alreadyThere = false;
    filesLock.lock();  
    for(auto &file : files){
        if(file.filename.compare(filename) == 0){
            alreadyThere = true;
            break;
        }
    }
    filesLock.unlock();

    if(alreadyThere)
        return true;

    std::string root = "files/";
    std::ofstream newfile(root + filename, std::ofstream::binary);

    newfile.write(buffer, length);
    newfile.close();

    FileEntry fileEntry(filename);

    filesLock.lock();
    files.push_back( fileEntry );
    filesLock.unlock();

    logFile << "saveFile " << root + filename << " saved" << std::endl;
    // cout << "saveFile " << root + filename << " saved" << std::endl;

    // cout<<"saveFile: "<<fileEntry.filename<<endl;

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rcx, -0x38(%rbp)
movq %rdx, -0x30(%rbp)
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x228(%rdi), %r15
movq %r15, %rdi
callq 0x8608
leaq 0x210(%r14), %r12
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0xb03b
leaq 0x10(%r13), %rdi
movq %rbx, %rsi
callq 0x4040
testl %eax, %eax
jne 0xb015
movq %r15, %rdi
callq 0x4290
jmp 0xb164
movq %r15, %rdi
callq 0x4290
leaq 0x4b1f(%rip), %rsi      # 0xfb69
leaq -0xc0(%rbp), %r13
leaq -0x2c0(%rbp), %rdx
movq %r13, %rdi
callq 0x4170
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xcad3
leaq -0x2c0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x4630
leaq -0x60(%rbp), %rdi
callq 0x41b0
leaq -0x2c0(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4430
leaq -0x2c0(%rbp), %rdi
callq 0x4480
leaq -0xa0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4450
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xb818
leaq -0xa0(%rbp), %rdi
callq 0x41b0
movq %r15, %rdi
callq 0x8608
leaq -0x60(%rbp), %rsi
movq %r12, %rdi
callq 0xcb0c
movq %r15, %rdi
callq 0x4290
leaq 0x4a77(%rip), %rsi      # 0xfb70
movq %r14, %rdi
callq 0x4370
movq %rax, %r14
leaq -0x80(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movq %rbx, %rdx
callq 0xcad3
leaq -0x80(%rbp), %rsi
movq %r14, %rdi
callq 0x4300
leaq 0x4a50(%rip), %rsi      # 0xfb7a
movq %rax, %rdi
callq 0x4370
movq %rax, %rdi
callq 0x41d0
leaq -0x80(%rbp), %rdi
callq 0x41b0
leaq -0x60(%rbp), %rdi
callq 0x41b0
leaq -0x2c0(%rbp), %rdi
callq 0x4678
leaq -0xc0(%rbp), %rdi
callq 0x41b0
movb $0x1, %al
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb1ae
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
jmp 0xb1b5
jmp 0xb19b
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x41b0
jmp 0xb1c6
movq %rax, %rbx
jmp 0xb1c6
movq %rax, %rbx
jmp 0xb1ba
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x41b0
jmp 0xb1b1
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x41b0
leaq -0x2c0(%rbp), %rdi
callq 0x4678
leaq -0xc0(%rbp), %rdi
callq 0x41b0
movq %rbx, %rdi
callq 0x45d0