// File: 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
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rsi, -0x240(%rbp)
movq %rdx, -0x238(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x46b0
movq -0x228(%rbp), %rdx
leaq 0x9f95(%rip), %rsi      # 0x1ca76
leaq -0x120(%rbp), %rdi
callq 0x4510
jmp 0x12aef
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x1b130
jmp 0x12b04
leaq -0x120(%rbp), %rdi
callq 0x42a0
leaq -0x121(%rbp), %rdi
callq 0x4430
leaq -0x100(%rbp), %rdi
callq 0x1b5b0
jmp 0x12b2a
movq -0x238(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x41e0
jmp 0x12b3f
leaq -0x158(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x10600
movq -0x250(%rbp), %rdi
movl %eax, -0x248(%rbp)
callq 0x42a0
movl -0x248(%rbp), %eax
movq -0x230(%rbp), %rdi
movl %eax, -0x138(%rbp)
movl -0x138(%rbp), %esi
callq 0x11010
movl %eax, -0x244(%rbp)
jmp 0x12b8a
movq -0x240(%rbp), %rsi
movl -0x244(%rbp), %eax
movl %eax, -0x15c(%rbp)
movl -0x15c(%rbp), %eax
movl %eax, -0x254(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x41e0
jmp 0x12bb7
movq -0x238(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x41e0
jmp 0x12bcc
movl -0x254(%rbp), %esi
movq -0x230(%rbp), %rdi
leaq -0x180(%rbp), %rdx
leaq -0x1a0(%rbp), %rcx
callq 0x11a80
movb %al, -0x255(%rbp)
jmp 0x12bf4
leaq -0x1a0(%rbp), %rdi
callq 0x42a0
leaq -0x180(%rbp), %rdi
callq 0x42a0
movb -0x255(%rbp), %al
andb $0x1, %al
movb %al, -0x15d(%rbp)
testb $0x1, -0x15d(%rbp)
jne 0x12dc3
movq 0x14392(%rip), %rdi     # 0x26fc0
leaq 0x9e7e(%rip), %rsi      # 0x1cab3
callq 0x43f0
movq %rax, -0x260(%rbp)
jmp 0x12c43
movq -0x260(%rbp), %rdi
movq 0x14357(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x12c58
movq -0x240(%rbp), %rsi
movl -0x15c(%rbp), %eax
incl %eax
movl %eax, -0x264(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x41e0
jmp 0x12c7b
movq -0x238(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x41e0
jmp 0x12c90
movl -0x264(%rbp), %esi
movq -0x230(%rbp), %rdi
leaq -0x1c0(%rbp), %rdx
leaq -0x1e0(%rbp), %rcx
callq 0x11a80
movb %al, -0x265(%rbp)
jmp 0x12cb8
movb -0x265(%rbp), %al
andb $0x1, %al
movb %al, -0x15d(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x42a0
leaq -0x1c0(%rbp), %rdi
callq 0x42a0
jmp 0x12dc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x12d15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x42a0
leaq -0x121(%rbp), %rdi
callq 0x4430
jmp 0x130de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x130d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x12d6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x42a0
leaq -0x180(%rbp), %rdi
callq 0x42a0
jmp 0x130d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x12db2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x42a0
leaq -0x1c0(%rbp), %rdi
callq 0x42a0
jmp 0x130d2
testb $0x1, -0x15d(%rbp)
jne 0x12ecd
movq 0x141e9(%rip), %rdi     # 0x26fc0
leaq 0x9cd5(%rip), %rsi      # 0x1cab3
callq 0x43f0
movq %rax, -0x270(%rbp)
jmp 0x12dec
movq -0x270(%rbp), %rdi
movq 0x141ae(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x12e01
movq -0x240(%rbp), %rsi
movl -0x15c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x274(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x41e0
jmp 0x12e25
movq -0x238(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x41e0
jmp 0x12e3a
movl -0x274(%rbp), %esi
movq -0x230(%rbp), %rdi
leaq -0x200(%rbp), %rdx
leaq -0x220(%rbp), %rcx
callq 0x11a80
movb %al, -0x275(%rbp)
jmp 0x12e62
movb -0x275(%rbp), %al
andb $0x1, %al
movb %al, -0x15d(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x42a0
leaq -0x200(%rbp), %rdi
callq 0x42a0
jmp 0x12ecd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x12ebc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x42a0
leaq -0x200(%rbp), %rdi
callq 0x42a0
jmp 0x130d2
testb $0x1, -0x15d(%rbp)
jne 0x12f25
movq 0x140e3(%rip), %rdi     # 0x26fc0
leaq 0x9bdc(%rip), %rsi      # 0x1cac0
callq 0x43f0
movq %rax, -0x280(%rbp)
jmp 0x12ef2
movq -0x238(%rbp), %rsi
movq -0x280(%rbp), %rdi
callq 0x4370
movq %rax, -0x288(%rbp)
jmp 0x12f0e
movq -0x288(%rbp), %rdi
movq 0x1408c(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x12f23
jmp 0x12f25
leaq -0x100(%rbp), %rdi
callq 0x1b640
jmp 0x12f33
testb $0x1, -0x15d(%rbp)
je 0x13000
movq 0x14079(%rip), %rdi     # 0x26fc0
leaq 0x9c68(%rip), %rsi      # 0x1cbb6
callq 0x43f0
movq %rax, -0x290(%rbp)
jmp 0x12f5c
movq -0x238(%rbp), %rsi
movq -0x290(%rbp), %rdi
callq 0x4370
movq %rax, -0x298(%rbp)
jmp 0x12f78
movq -0x298(%rbp), %rdi
leaq 0x9b4c(%rip), %rsi      # 0x1cad2
callq 0x43f0
movq %rax, -0x2a0(%rbp)
jmp 0x12f94
leaq -0x100(%rbp), %rdi
callq 0x1b760
movq %rax, -0x2a8(%rbp)
jmp 0x12fa9
movq -0x2a0(%rbp), %rdi
movq -0x2a8(%rbp), %rax
movss 0x34(%rax), %xmm0
callq 0x42e0
movq %rax, -0x2b0(%rbp)
jmp 0x12fca
movq -0x2b0(%rbp), %rdi
leaq 0x9aad(%rip), %rsi      # 0x1ca85
callq 0x43f0
movq %rax, -0x2b8(%rbp)
jmp 0x12fe6
movq -0x2b8(%rbp), %rdi
movq 0x13fb4(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x12ffb
jmp 0x130bd
movq 0x13fb9(%rip), %rdi     # 0x26fc0
leaq 0x9ba8(%rip), %rsi      # 0x1cbb6
callq 0x43f0
movq %rax, -0x2c0(%rbp)
jmp 0x1301c
movq -0x238(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
callq 0x4370
movq %rax, -0x2c8(%rbp)
jmp 0x13038
movq -0x2c8(%rbp), %rdi
leaq 0x9a9a(%rip), %rsi      # 0x1cae0
callq 0x43f0
movq %rax, -0x2d0(%rbp)
jmp 0x13054
leaq -0x100(%rbp), %rdi
callq 0x1b760
movq %rax, -0x2d8(%rbp)
jmp 0x13069
movq -0x2d0(%rbp), %rdi
movq -0x2d8(%rbp), %rax
movss 0x34(%rax), %xmm0
callq 0x42e0
movq %rax, -0x2e0(%rbp)
jmp 0x1308a
movq -0x2e0(%rbp), %rdi
leaq 0x99ed(%rip), %rsi      # 0x1ca85
callq 0x43f0
movq %rax, -0x2e8(%rbp)
jmp 0x130a6
movq -0x2e8(%rbp), %rdi
movq 0x13ef4(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x130bb
jmp 0x130bd
leaq -0x100(%rbp), %rdi
callq 0x1b1c0
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x100(%rbp), %rdi
callq 0x1b1c0
movq -0x130(%rbp), %rdi
callq 0x46a0
nopw (%rax,%rax)