// File: luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::addToVirtualRing(Node)
int FileSystem::addToVirtualRing( Node n ){
    VirtualNode newNode;
    newNode.ip_str = n.ip_str;
    newNode.key = hashString(newNode.ip_str);

    virtualRingLock.lock();
    
    virtualRing.push_back(newNode);
    std::sort(virtualRing.begin(), virtualRing.end());
    myPosition = find( virtualRing.begin(), virtualRing.end(), myself ) - virtualRing.begin();
    int joinPosition = find( virtualRing.begin(), virtualRing.end(), newNode ) - virtualRing.begin();

    virtualRingLock.unlock();

    int positionClock = joinPosition - myPosition;
    if(positionClock < 0) 
        positionClock += virtualRing.size() + 1;

    return positionClock;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rsi, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x162f0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x4050
jmp 0x1484a
leaq -0x68(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41e0
jmp 0x14859
leaq -0x68(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x10600
movq -0xe8(%rbp), %rdi
movl %eax, -0x18(%rbp)
callq 0x42a0
movq -0xe0(%rbp), %rdi
addq $0x268, %rdi            # imm = 0x268
callq 0xb5f0
jmp 0x1488d
movq -0xe0(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
leaq -0x38(%rbp), %rsi
callq 0x16900
jmp 0x148a6
movq -0xe0(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movq %rdi, -0xf0(%rbp)
callq 0x169b0
movq -0xf0(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0x169e0
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x16970
jmp 0x148e3
movq -0xe0(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movq %rdi, -0x100(%rbp)
callq 0x169b0
movq -0x100(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x169e0
movq -0xe0(%rbp), %rdx
movq %rax, -0x90(%rbp)
addq $0x298, %rdx            # imm = 0x298
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x16a60
movq %rax, -0xf8(%rbp)
jmp 0x14941
movq -0xe0(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq %rax, -0x80(%rbp)
addq $0x250, %rdi            # imm = 0x250
movq %rdi, -0x110(%rbp)
callq 0x169b0
movq %rax, -0x98(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x16a10
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movq -0xe0(%rbp), %rax
movl %ecx, 0x290(%rax)
callq 0x169b0
movq -0x110(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x169e0
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x16a60
movq %rax, -0x108(%rbp)
jmp 0x149d3
movq -0xe0(%rbp), %rdi
movq -0x108(%rbp), %rax
movq %rax, -0xa8(%rbp)
addq $0x250, %rdi            # imm = 0x250
callq 0x169b0
movq %rax, -0xc0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x16a10
movq -0xe0(%rbp), %rdi
movl %eax, -0x9c(%rbp)
addq $0x268, %rdi            # imm = 0x268
callq 0xb620
jmp 0x14a29
movq -0xe0(%rbp), %rcx
movl -0x9c(%rbp), %eax
subl 0x290(%rcx), %eax
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jge 0x14a8e
movq -0xe0(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
callq 0x16470
movq %rax, %rcx
addq $0x1, %rcx
movslq -0xc4(%rbp), %rax
addq %rcx, %rax
movl %eax, -0xc4(%rbp)
jmp 0x14a8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x163d0
jmp 0x14ab2
movl -0xc4(%rbp), %eax
movl %eax, -0x114(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x163d0
movl -0x114(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x46a0
nopl (%rax,%rax)