// File: luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::deleteFromVirtualRing(Node)
int FileSystem::deleteFromVirtualRing( Node n ){
    // cout<<"detect leave: "<<n.ip_str<<endl;

    VirtualNode changeNode;
    changeNode.ip_str = n.ip_str;
    changeNode.key = hashString(changeNode.ip_str);

    // cout<<"leave virtual node: "<<changeNode.ip_str<<" "<<changeNode.key<<endl;

    virtualRingLock.lock();
    
    int myOldPosition = myPosition;

    int leavePosition = find( virtualRing.begin(), virtualRing.end(), changeNode ) - virtualRing.begin();

    // cout<<"leave node position: "<<leavePosition<<endl;

    virtualRing.erase( virtualRing.begin() + leavePosition );

    if( leavePosition == myOldPosition )
        myPosition = -1;
    else
        myPosition = find( virtualRing.begin(), virtualRing.end(), myself ) - virtualRing.begin();
    
    virtualRingLock.unlock();

    int positionClock = leavePosition - myOldPosition;
    if(positionClock < 0) 
        positionClock += virtualRing.size() + 1;

    return positionClock;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rsi, -0xe0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x162f0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x4050
jmp 0x14b0a
leaq -0x68(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41e0
jmp 0x14b19
leaq -0x68(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x10600
movq -0xf8(%rbp), %rdi
movl %eax, -0x18(%rbp)
callq 0x42a0
movq -0xf0(%rbp), %rdi
addq $0x268, %rdi            # imm = 0x268
callq 0xb5f0
jmp 0x14b4d
movq -0xf0(%rbp), %rdi
movl 0x290(%rdi), %eax
movl %eax, -0x6c(%rbp)
addq $0x250, %rdi            # imm = 0x250
movq %rdi, -0x108(%rbp)
callq 0x169b0
movq -0x108(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x169e0
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x16a60
movq %rax, -0x100(%rbp)
jmp 0x14ba4
movq -0xf0(%rbp), %rdi
movq -0x100(%rbp), %rax
movq %rax, -0x78(%rbp)
addq $0x250, %rdi            # imm = 0x250
movq %rdi, -0x118(%rbp)
callq 0x169b0
movq %rax, -0x90(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x16a10
movq -0x118(%rbp), %rdi
movl %eax, -0x70(%rbp)
callq 0x169b0
movq %rax, -0xa8(%rbp)
movslq -0x70(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x16b20
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x16b60
movq -0x118(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x16ab0
movq %rax, -0x110(%rbp)
jmp 0x14c3c
movq -0x110(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x14c82
movq -0xf0(%rbp), %rax
movl $0xffffffff, 0x290(%rax) # imm = 0xFFFFFFFF
jmp 0x14d2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x163d0
jmp 0x14da3
movq -0xf0(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movq %rdi, -0x128(%rbp)
callq 0x169b0
movq -0x128(%rbp), %rdi
movq %rax, -0xc0(%rbp)
callq 0x169e0
movq -0xf0(%rbp), %rdx
movq %rax, -0xc8(%rbp)
addq $0x298, %rdx            # imm = 0x298
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x16a60
movq %rax, -0x120(%rbp)
jmp 0x14ce0
movq -0xf0(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0xb8(%rbp)
addq $0x250, %rdi            # imm = 0x250
callq 0x169b0
movq %rax, -0xd0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x16a10
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movl %ecx, 0x290(%rax)
movq -0xf0(%rbp), %rdi
addq $0x268, %rdi            # imm = 0x268
callq 0xb620
jmp 0x14d40
movl -0x70(%rbp), %eax
subl -0x6c(%rbp), %eax
movl %eax, -0xd4(%rbp)
cmpl $0x0, -0xd4(%rbp)
jge 0x14d7f
movq -0xf0(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
callq 0x16470
movq %rax, %rcx
addq $0x1, %rcx
movslq -0xd4(%rbp), %rax
addq %rcx, %rax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0x12c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x163d0
movl -0x12c(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x46a0
nopl (%rax)