// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
addq $0x228, %rdi            # imm = 0x228
movq %rdi, -0x70(%rbp)
callq 0x44d0
testl %eax, %eax
jne 0xd0c7
leaq 0x210(%rbx), %rax
movq 0x210(%rbx), %r13
movq %rax, -0x48(%rbp)
cmpq %rax, %r13
je 0xd081
leaq 0x10(%r13), %rax
movq %rax, -0x78(%rbp)
xorl %r15d, %r15d
xorl %r14d, %r14d
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x56fa
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
callq 0x40c0
movl %eax, %ecx
imulq $0x10624dd3, %rcx, %rcx # imm = 0x10624DD3
shrq $0x26, %rcx
imull $0x3e8, %ecx, %ecx      # imm = 0x3E8
subl %ecx, %eax
movq %rbx, %rdi
movl %eax, %esi
callq 0xba82
movl %eax, %r12d
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xce93
callq 0x4360
addl %r15d, %r12d
movslq %r12d, %rax
movq 0x250(%rbx), %rcx
movq 0x258(%rbx), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rsi
addq %rsi, %rax
xorl %edx, %edx
divq %rsi
movslq %edx, %rax
leaq (%rax,%rax,4), %rax
movl 0x20(%rcx,%rax,8), %eax
cmpl 0x2b8(%rbx), %eax
movl $0x1, %eax
cmovel %eax, %r14d
incl %r15d
cmpl $0x3, %r15d
jne 0xce31
testl %r14d, %r14d
jne 0xcefd
leaq -0x40(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xa33c
movq (%r13), %r13
cmpq -0x48(%rbp), %r13
jne 0xce23
movq -0x40(%rbp), %rax
cmpq %rax, -0x38(%rbp)
je 0xd081
movl $0x8, %r13d
xorl %r12d, %r12d
leaq -0x88(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq -0x8(%rax,%r13), %rsi
movq (%rax,%r13), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x56fa
leaq -0x98(%rbp), %rsi
callq 0xd150
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0xcf6c
callq 0x4360
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r12, %rdx
jbe 0xd0b6
movq -0x8(%rax,%r13), %rsi
movq (%rax,%r13), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x6b1b(%rip), %rsi      # 0x13ac2
callq 0x43f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r12, %rdx
leaq -0xb8(%rbp), %r14
jbe 0xd0a5
leaq -0xa8(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movq -0x8(%rax,%r13), %rsi
movq (%rax,%r13), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x56fa
leaq -0xe0(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xe562
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0xfef6
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0xd04a
callq 0x4360
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xd062
callq 0x4360
incq %r12
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x20, %r13
cmpq %r12, %rcx
ja 0xcf22
movq -0x70(%rbp), %rdi
callq 0x42a0
leaq -0x40(%rbp), %rdi
callq 0xa29e
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68c9(%rip), %rdi      # 0x13975
movq %r12, %rsi
xorl %eax, %eax
callq 0x44e0
leaq 0x68b8(%rip), %rdi      # 0x13975
movq %r12, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
jmp 0xd11d
jmp 0xd11d
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
jmp 0xd135
jmp 0xd11d
jmp 0xd11d
jmp 0xd11d
movq %rax, %rbx
jmp 0xd10b
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0xd10b
callq 0x4360
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
jmp 0xd135
jmp 0xd11d
movq %rax, %rbx
jmp 0xd13f
movq %rax, %rdi
callq 0xa583
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xd13f
callq 0x4360
leaq -0x40(%rbp), %rdi
callq 0xa29e
movq %rbx, %rdi
callq 0x4630