// File: /workspace/github_cpp_makefile_star2_O2/luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::checkFiles()
void FileSystem::checkFiles()
{
    // hashing function to find the machine/s where to store the file;
    
    std::vector<std::string> toremove;

    filesLock.lock();

    for ( auto &file : files)
    {
        int flag = false;
        for (int i = 0; i < 3; ++i)
        {
            int position = findPositionByKey( hashString(file.filename) ) + i;
            int nodePosition = ( position + virtualRing.size() ) % virtualRing.size();

            if (virtualRing[nodePosition].key == myself.key)
            {
                flag = true;
            }
        }

        if (!flag)
        {
            toremove.push_back(file.filename);
        }
    }

    for (int i = 0; i < toremove.size(); ++i)
    {
        if ( deleteFile( toremove.at(i) ) ) 
        {
            logFile << toremove.at(i) << "deleted" << std::endl;
        }
        files.remove(toremove.at(i));
    }

    filesLock.unlock();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
andq $0x0, -0x30(%rbp)
addq $0x228, %rdi            # imm = 0x228
movq %rdi, -0x58(%rbp)
callq 0x8608
leaq 0x210(%rbx), %rax
leaq -0xc0(%rbp), %r15
movq %rax, -0x48(%rbp)
movq %rax, %r14
movq (%r14), %r14
cmpq -0x48(%rbp), %r14
je 0xa9d7
movq %r14, -0x60(%rbp)
leaq 0x10(%r14), %rax
movq %rax, -0x50(%rbp)
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpl $0x3, %r12d
je 0xa9b8
movq %r15, %rdi
movq -0x50(%rbp), %rsi
callq 0x4450
movq %r15, %rdi
callq 0x95d4
movq %rbx, %rdi
movl %eax, %esi
callq 0x9c12
movl %eax, %r13d
addl %r12d, %r13d
movq %r15, %rdi
callq 0x41b0
movslq %r13d, %rcx
movq 0x250(%rbx), %rdi
movq 0x258(%rbx), %rax
subq %rdi, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
movq %rax, %rsi
addq %rax, %rcx
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movslq %edx, %rax
imulq $0x28, %rax, %rax
movl 0x20(%rdi,%rax), %eax
cmpl 0x2b8(%rbx), %eax
pushq $0x1
popq %rax
cmovel %eax, %r14d
incl %r12d
jmp 0xa93f
testl %r14d, %r14d
movq -0x60(%rbp), %r14
jne 0xa920
leaq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x8780
jmp 0xa920
xorl %r12d, %r12d
leaq -0xa0(%rbp), %r14
leaq -0x80(%rbp), %r15
leaq -0xe8(%rbp), %r13
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0xaa9c
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0xc9b4
movq %r14, %rdi
movq %rax, %rsi
callq 0x4450
movq %r14, %rsi
callq 0xab14
movq %r14, %rdi
callq 0x41b0
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0xc9b4
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4300
movq %rax, %rdi
leaq 0x5051(%rip), %rsi      # 0xfa9a
callq 0x4370
movq %rax, %rdi
callq 0x41d0
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0xc9b4
movq %r15, %rdi
movq %rax, %rsi
callq 0x4450
movq %r13, %rdi
movq %r15, %rsi
callq 0xb818
movq -0x48(%rbp), %rdi
movq %r13, %rsi
callq 0xc9d6
movq %r13, %rdi
callq 0x41b0
movq %r15, %rdi
callq 0x41b0
incq %r12
jmp 0xa9ec
movq -0x58(%rbp), %rdi
callq 0x4290
leaq -0x40(%rbp), %rdi
callq 0x8708
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaaee
jmp 0xaaee
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x41b0
jmp 0xaad8
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0xaafd
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
jmp 0xaafd
jmp 0xaaee
jmp 0xaaee
movq %rax, %rbx
jmp 0xab02
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x41b0
leaq -0x40(%rbp), %rdi
callq 0x8708
movq %rbx, %rdi
callq 0x45d0
nop