// File: /workspace/github_cpp_makefile_star2_O2/luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FileSystem::get(std::string localFile, std::string remoteFile)
{
    //https://gitlab-beta.engr.illinois.edu/remis2/MP3-FileSystem.git
    // hashing function to find the machine where to ask for the file;

    ChronoCpu chrono("cpu");
    
    chrono.tic();

    int fileKey = hashString(remoteFile);
    int position = findPositionByKey(fileKey);

    // cout<<"get "<<localFile<<" "<<fileKey<<" from "<<position<<" "<<virtualRing[position].ip_str<<" "<<virtualRing[position].key<<endl;

    bool attempt = getFromNode( position, localFile, remoteFile );
    if(!attempt)
    {
        std::cout << "Retrying... " << std::endl;
        attempt = getFromNode( position+1, localFile, remoteFile );
    }
    if(!attempt)
    {
        std::cout << "Retrying... " << std::endl;
        attempt = getFromNode( position+2, localFile, remoteFile );
    }

    if (!attempt)
    {
        std::cout << "Error retrieving " << remoteFile << std::endl;
    }

    chrono.tac();
    if(attempt)
        std::cout << "File " << remoteFile << " received in " << chrono.getElapsedStats().lastTime_ms << " ms" << std::endl;
    else
        std::cout << "File " << remoteFile << " cannot be found. returning in " << chrono.getElapsedStats().lastTime_ms << " ms" << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x4edf(%rip), %rsi      # 0xfa65
leaq -0x110(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4170
leaq -0x218(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xe1a4
leaq -0x110(%rbp), %rdi
callq 0x41b0
leaq -0x218(%rbp), %rdi
callq 0xe4c6
leaq -0x130(%rbp), %rdi
movq %rbx, %rsi
callq 0x4450
leaq -0x130(%rbp), %r12
movq %r12, %rdi
callq 0x95d4
movl %eax, %r13d
movq %r12, %rdi
callq 0x41b0
movq %r14, %rdi
movl %r13d, %esi
callq 0x9c12
movl %eax, %r12d
leaq -0xf0(%rbp), %rdi
movq %r15, %rsi
callq 0x4450
leaq -0xd0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4450
leaq -0xf0(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq %r14, %rdi
movl %r12d, %esi
callq 0xa1d4
movl %eax, %r13d
leaq -0xd0(%rbp), %rdi
callq 0x41b0
leaq -0xf0(%rbp), %rdi
callq 0x41b0
movb $0x1, %al
movl %eax, -0x30(%rbp)
testb %r13b, %r13b
jne 0xad61
movq 0xb361(%rip), %rdi      # 0x15fc0
leaq 0x4e3c(%rip), %rsi      # 0xfaa2
callq 0x4370
movq %rax, %rdi
callq 0x41d0
leaq -0xb0(%rbp), %rdi
movq %r15, %rsi
callq 0x4450
leaq -0x90(%rbp), %rdi
movq %rbx, %rsi
callq 0x4450
leal 0x1(%r12), %esi
leaq -0xb0(%rbp), %rdx
leaq -0x90(%rbp), %rcx
movq %r14, %rdi
callq 0xa1d4
movl %eax, %r13d
leaq -0x90(%rbp), %rdi
callq 0x41b0
leaq -0xb0(%rbp), %rdi
callq 0x41b0
testb %r13b, %r13b
jne 0xad61
movq 0xb2e9(%rip), %rdi      # 0x15fc0
leaq 0x4dc4(%rip), %rsi      # 0xfaa2
callq 0x4370
movq %rax, %rdi
callq 0x41d0
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x4450
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x4450
addl $0x2, %r12d
leaq -0x70(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movq %r14, %rdi
movl %r12d, %esi
callq 0xa1d4
movl %eax, %r14d
leaq -0x50(%rbp), %rdi
callq 0x41b0
leaq -0x70(%rbp), %rdi
callq 0x41b0
testb %r14b, %r14b
jne 0xad61
movq 0xb285(%rip), %rdi      # 0x15fc0
leaq 0x4d6d(%rip), %rsi      # 0xfaaf
callq 0x4370
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4300
movq %rax, %rdi
callq 0x41d0
movl $0x0, -0x30(%rbp)
leaq -0x218(%rbp), %rdi
callq 0xe538
cmpb $0x0, -0x30(%rbp)
je 0xadb1
movq 0xb246(%rip), %rdi      # 0x15fc0
leaq 0x4e24(%rip), %rsi      # 0xfba5
callq 0x4370
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4300
leaq 0x4d29(%rip), %rsi      # 0xfac1
movq %rax, %rdi
callq 0x4370
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0xe5c6
jmp 0xaded
movq 0xb208(%rip), %rdi      # 0x15fc0
leaq 0x4de6(%rip), %rsi      # 0xfba5
callq 0x4370
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4300
leaq 0x4cf9(%rip), %rsi      # 0xfacf
movq %rax, %rdi
callq 0x4370
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0xe5c6
movss 0x34(%rax), %xmm0
movq %rbx, %rdi
callq 0x4270
leaq 0x4c73(%rip), %rsi      # 0xfa74
movq %rax, %rdi
callq 0x4370
movq %rax, %rdi
callq 0x41d0
leaq -0x218(%rbp), %rdi
callq 0xe1e4
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x41b0
jmp 0xae40
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0xae7e
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x41b0
jmp 0xae5a
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0xae7e
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x41b0
jmp 0xae77
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x41b0
jmp 0xaea4
jmp 0xaea1
jmp 0xaea1
jmp 0xaea1
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x41b0
jmp 0xaeb0
movq %rax, %rbx
jmp 0xaeb0
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0xe1e4
movq %rbx, %rdi
callq 0x45d0