// File: /workspace/github_cpp_makefile_star2_O1/luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::detectLeave(Node)
bool FileSystem::detectLeave( Node leaveNode )
{    
    int positionClock = deleteFromVirtualRing( leaveNode );
    
    virtualRingLock.lock();
    int positionAntiClock = virtualRing.size() + 1 - positionClock;

    // cout<<"node "<< leaveNode.ip_str<<" leaving "<<positionAntiClock<<" before me."<<endl;
    bool success = false;

    int minKey, maxKey;
    if( positionAntiClock == 3 ){
        VirtualNode target = nNodeBefore(1, myPosition);
        minKey = nNodeBefore(3, myPosition).key;
        maxKey = hashString(leaveNode.ip_str);
        success = pullFileFromRange(  target.ip_str, minKey, maxKey, false);
        // cout<<success<<" pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;    
        logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;    
    }
    else if( positionAntiClock == 2 ){
        VirtualNode target = nNodeBefore(1, myPosition);
        minKey = nNodeBefore(3, myPosition).key;
        maxKey = nNodeBefore(2, myPosition).key;
        success = pullFileFromRange(  target.ip_str, minKey, maxKey, false);   
        // cout<<success<<" pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;
        logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;    
    }
    else if( positionAntiClock == 1 ){
        VirtualNode target = nNodeBefore(1, myPosition);
        minKey = nNodeBefore(3, myPosition).key;
        maxKey = nNodeBefore(2, myPosition).key;
        success = pullFileFromRange(  target.ip_str, minKey, maxKey, false);
        // cout<<success<<" pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;
        logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;    
    }

    if(!success){
        VirtualNode target = nNodeBefore(2, myPosition);
        success = pullFileFromRange(  target.ip_str, minKey, maxKey, false);
        // cout<<success<<" pull key second from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;
        logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl;    
    }

    virtualRingLock.unlock();

    return success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r12
movq %rdi, %r14
leaq -0x140(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rsi), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x150(%rbp), %rbx
movq %rbx, %rdi
callq 0x570a
movq 0x20(%r12), %rax
movq %rax, 0x20(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xec60
movl %eax, %r15d
movq -0x150(%rbp), %rdi
cmpq %r13, %rdi
je 0xf749
callq 0x4360
leaq 0x268(%r14), %rdi
movq %rdi, -0x88(%rbp)
callq 0x44d0
testl %eax, %eax
jne 0xfde6
movq 0x258(%r14), %rax
subq 0x250(%r14), %rax
shrq $0x3, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
subl %r15d, %eax
je 0xfadf
cmpl $0x1, %eax
je 0xf959
cmpl $0x2, %eax
jne 0xfc74
movl 0x290(%r14), %ecx
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf5d2
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0xf5d2
leaq -0x70(%rbp), %rax
movl 0x10(%rax), %r15d
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf7dd
callq 0x4360
leaq -0x118(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %rdi
callq 0x570a
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
callq 0x40c0
movq %rax, %r12
movq -0x128(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf82c
callq 0x4360
leaq -0xf8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %rdi
callq 0x570a
movl %r12d, %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x26, %rax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
subl %eax, %r12d
leaq -0x108(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0xe7ca
movl %eax, %r13d
movq -0x108(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf891
callq 0x4360
movzbl %r13b, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %rbx
leaq 0x448c(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x3eeb(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x4441(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x3a10(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x45f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
jmp 0xfc60
movl 0x290(%r14), %ecx
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf5d2
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0xf5d2
leaq -0x70(%rbp), %rbx
movl 0x10(%rbx), %r15d
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0xf99f
callq 0x4360
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0xf5d2
movl -0x60(%rbp), %r12d
movq -0x80(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf9c9
callq 0x4360
leaq -0xd8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x570a
leaq -0xe8(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0xe7ca
movl %eax, %r13d
movq -0xe8(%rbp), %rdi
cmpq %rbx, %rdi
je 0xfa17
callq 0x4360
movzbl %r13b, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %rbx
leaq 0x4306(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x3d65(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x42bb(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x388a(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x45f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
jmp 0xfc60
movl 0x290(%r14), %ecx
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf5d2
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0xf5d2
leaq -0x70(%rbp), %rbx
movl 0x10(%rbx), %r15d
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0xfb25
callq 0x4360
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0xf5d2
movl -0x60(%rbp), %r12d
movq -0x80(%rbp), %rdi
cmpq %rbx, %rdi
je 0xfb4f
callq 0x4360
leaq -0xb8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x570a
leaq -0xc8(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0xe7ca
movl %eax, %r13d
movq -0xc8(%rbp), %rdi
cmpq %rbx, %rdi
je 0xfb9d
callq 0x4360
movzbl %r13b, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %rbx
leaq 0x4180(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x3bdf(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x4135(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x3704(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x45f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfc77
callq 0x4360
jmp 0xfc77
xorl %r13d, %r13d
testb %r13b, %r13b
jne 0xfdc5
movq %r12, %r13
movl 0x290(%r14), %ecx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0xf5d2
leaq -0x98(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x570a
leaq -0xa8(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0xe7ca
movl %eax, -0x54(%rbp)
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0xfcec
callq 0x4360
movzbl -0x54(%rbp), %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %rbx
leaq 0x4031(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x3a90(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r13d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x3fe6(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x35b5(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x45f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfdc1
callq 0x4360
movl -0x54(%rbp), %r13d
movq -0x88(%rbp), %rdi
callq 0x42a0
movl %r13d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4240
movq %rax, %r14
movq -0x108(%rbp), %rdi
jmp 0xfe0f
movq %rax, %r14
movq -0xc8(%rbp), %rdi
jmp 0xfe0f
movq %rax, %r14
movq -0xe8(%rbp), %rdi
cmpq %rbx, %rdi
jne 0xfe37
jmp 0xfe58
movq %rax, %rdi
callq 0xa677
jmp 0xfe55
jmp 0xfe55
jmp 0xfe55
jmp 0xfe55
jmp 0xfe55
movq %rax, %r14
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0xfe58
callq 0x4360
jmp 0xfe58
movq %rax, %r14
movq -0x150(%rbp), %rdi
cmpq %r13, %rdi
jne 0xfe65
jmp 0xfe6a
jmp 0xfe55
jmp 0xfe55
jmp 0xfe55
movq %rax, %r14
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfe6a
callq 0x4360
movq %r14, %rdi
callq 0x4630