// File: /workspace/github_cpp_makefile_star2_O1/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 $0x2a8, %rsp            # imm = 0x2A8
movq %rcx, -0x48(%rbp)
movq %rdx, -0x40(%rbp)
movq %rsi, %r14
movq %rdi, %rbx
addq $0x228, %rdi            # imm = 0x228
movq %rdi, -0x30(%rbp)
callq 0x44d0
testl %eax, %eax
jne 0xdcc3
movq %rbx, -0x38(%rbp)
leaq 0x210(%rbx), %r15
xorl %r13d, %r13d
movl $0x1, %ebx
movq %r15, %r12
movq (%r12), %r12
cmpq %r15, %r12
je 0xdaae
leaq 0x10(%r12), %rdi
movq %r14, %rsi
callq 0x4050
movzbl %r13b, %r13d
testl %eax, %eax
cmovel %ebx, %r13d
jne 0xda8c
movq -0x30(%rbp), %rdi
callq 0x42a0
testb $0x1, %r13b
jne 0xdcaf
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x60c1(%rip), %rsi      # 0x13b91
leaq 0x60c0(%rip), %rdx      # 0x13b97
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0xa686
leaq -0x90(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x10162
leaq -0x2d0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x4, %edx
callq 0x46a0
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
movq %rax, %r12
cmpq %rax, %rdi
je 0xdb22
callq 0x4360
leaq -0x2d0(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4460
leaq -0x2d0(%rbp), %rdi
callq 0x44a0
leaq -0xc0(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x570a
leaq -0x90(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xe6b4
movq -0xd0(%rbp), %rdi
cmpq %r13, %rdi
je 0xdb87
callq 0x4360
movq -0x30(%rbp), %rdi
callq 0x44d0
testl %eax, %eax
movq -0x38(%rbp), %rbx
jne 0xdcca
leaq -0x90(%rbp), %rsi
movq %r15, %rdi
callq 0x102a8
movq %rax, %rdi
movq %r15, %rsi
callq 0x4080
incq 0x220(%rbx)
movq -0x30(%rbp), %rdi
callq 0x42a0
leaq 0x5fcb(%rip), %rsi      # 0x13b98
movl $0x9, %edx
movq %rbx, %rdi
callq 0x43f0
leaq -0xb0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movq %r14, %rdx
callq 0x10162
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x5f95(%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 -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdc56
callq 0x4360
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0xdc67
callq 0x4360
movq 0xb34a(%rip), %rax      # 0x18fb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x2c8(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x2d0(%rbp,%rcx)
callq 0x42f0
leaq -0x1d8(%rbp), %rdi
callq 0x4160
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xdcaf
callq 0x4360
movb $0x1, %al
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4240
movl %eax, %edi
callq 0x4240
jmp 0xdd07
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r13, %rdi
jne 0xdd30
jmp 0xdd35
jmp 0xdd02
movq %rax, %rbx
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdd41
callq 0x4360
jmp 0xdd41
movq %rax, %rbx
jmp 0xdd41
movq %rax, %rbx
jmp 0xdd35
movq %rax, %rbx
jmp 0xdd24
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xdd24
callq 0x4360
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0xdd35
callq 0x4360
leaq -0x2d0(%rbp), %rdi
callq 0x46c8
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xdd53
callq 0x4360
movq %rbx, %rdi
callq 0x4630
nop