// File: /workspace/github_cpp_makefile_star2_O1/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 0xd204
leaq 0x210(%rbx), %rax
movq 0x210(%rbx), %r13
cmpq %rax, %r13
movq %rax, -0x48(%rbp)
je 0xd048
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 0x570a
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 0xbbbc
movl %eax, %r12d
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xcfcd
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 0xcf6b
testl %r14d, %r14d
jne 0xd037
leaq -0x40(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xa420
movq (%r13), %r13
movq -0x48(%rbp), %rax
cmpq %rax, %r13
jne 0xcf5d
movq -0x40(%rbp), %rax
cmpq %rax, -0x38(%rbp)
je 0xd1be
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 0x570a
leaq -0x98(%rbp), %rsi
callq 0xd28e
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0xd0a9
callq 0x4360
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r12, %rdx
jbe 0xd1f3
movq -0x8(%rax,%r13), %rsi
movq (%rax,%r13), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x69de(%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
jbe 0xd1e2
leaq -0xa8(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movq -0x8(%rax,%r13), %rsi
movq (%rax,%r13), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %r14
movq %r14, %rdi
callq 0x570a
leaq -0xe0(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xe6b4
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x1003a
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0xd187
callq 0x4360
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xd19f
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 0xd05f
movq -0x70(%rbp), %rdi
callq 0x42a0
leaq -0x40(%rbp), %rdi
callq 0xa38c
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x678c(%rip), %rdi      # 0x13975
movq %r12, %rsi
xorl %eax, %eax
callq 0x44e0
leaq 0x677b(%rip), %rdi      # 0x13975
movq %r12, %rsi
xorl %eax, %eax
callq 0x44e0
movl %eax, %edi
callq 0x4240
jmp 0xd25a
jmp 0xd25a
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
jmp 0xd272
jmp 0xd25a
jmp 0xd25a
jmp 0xd25a
movq %rax, %rbx
jmp 0xd248
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0xd248
callq 0x4360
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
jmp 0xd272
jmp 0xd25a
movq %rax, %rbx
jmp 0xd27c
movq %rax, %rdi
callq 0xa677
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xd27c
callq 0x4360
leaq -0x40(%rbp), %rdi
callq 0xa38c
movq %rbx, %rdi
callq 0x4630
nop