// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %rbx
leaq 0x228(%rdi), %r15
movq %r15, %rdi
callq 0x44d0
testl %eax, %eax
jne 0xdb71
leaq 0x210(%rbx), %r12
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0xd97b
leaq 0x10(%r13), %rdi
movq %r14, %rsi
callq 0x4050
testl %eax, %eax
jne 0xd955
movq %r15, %rdi
callq 0x42a0
jmp 0xdb5d
movq %r15, %rdi
callq 0x42a0
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x61ff(%rip), %rsi      # 0x13b91
leaq 0x61fe(%rip), %rdx      # 0x13b97
leaq -0x80(%rbp), %r13
movq %r13, %rdi
callq 0xa592
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1001e
leaq -0x2c0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x4, %edx
callq 0x46a0
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd9db
callq 0x4360
leaq -0x2c0(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4460
leaq -0x2c0(%rbp), %rdi
callq 0x44a0
leaq -0xb0(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x56fa
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xe562
movq -0xc0(%rbp), %rdi
cmpq %r13, %rdi
je 0xda3d
callq 0x4360
movq %r15, %rdi
callq 0x44d0
testl %eax, %eax
jne 0xdb78
leaq -0x60(%rbp), %rsi
movq %r12, %rdi
callq 0x10164
movq %rax, %rdi
movq %r12, %rsi
callq 0x4080
incq 0x220(%rbx)
movq %r15, %rdi
callq 0x42a0
leaq 0x611e(%rip), %rsi      # 0x13b98
movl $0x9, %edx
movq %rbx, %rdi
callq 0x43f0
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movq %r14, %rdx
callq 0x1001e
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x60e8(%rip), %rsi      # 0x13ba2
movl $0x6, %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
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdb03
callq 0x4360
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0xdb15
callq 0x4360
movq 0xb49c(%rip), %rax      # 0x18fb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x2b8(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x2c0(%rbp,%rcx)
callq 0x42f0
leaq -0x1c8(%rbp), %rdi
callq 0x4160
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0xdb5d
callq 0x4360
movb $0x1, %al
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4240
movl %eax, %edi
callq 0x4240
jmp 0xdbb5
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r13, %rdi
jne 0xdbdf
jmp 0xdbe4
jmp 0xdbb0
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdbf0
callq 0x4360
jmp 0xdbf0
movq %rax, %rbx
jmp 0xdbf0
movq %rax, %rbx
jmp 0xdbe4
movq %rax, %rbx
jmp 0xdbd2
movq %rax, %rbx
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdbd2
callq 0x4360
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0xdbe4
callq 0x4360
leaq -0x2c0(%rbp), %rdi
callq 0x46c8
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0xdc02
callq 0x4360
movq %rbx, %rdi
callq 0x4630