// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdi, %r14
leaq -0x140(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rsi), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x150(%rbp), %r15
movq %r15, %rdi
callq 0x56fa
movq 0x20(%rbx), %rax
movq %rax, 0x20(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0xeb14
movl %eax, %r15d
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
je 0xf614
callq 0x4360
leaq 0x268(%r14), %r12
movq %r12, %rdi
callq 0x44d0
testl %eax, %eax
jne 0xfca7
movq 0x258(%r14), %rax
subq 0x250(%r14), %rax
shrq $0x3, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
subl %r15d, %eax
movq %r12, -0x88(%rbp)
je 0xf9a9
cmpl $0x1, %eax
je 0xf825
cmpl $0x2, %eax
jne 0xfb49
movl 0x290(%r14), %ecx
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf492
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0xf492
leaq -0x70(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, -0x2c(%rbp)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf6ad
callq 0x4360
leaq -0x118(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %rdi
callq 0x56fa
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movl $0xc70f6907, %edx       # imm = 0xC70F6907
callq 0x40c0
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r15, %rdi
je 0xf6fa
callq 0x4360
leaq -0xf8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %rdi
callq 0x56fa
movl %ebx, %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x26, %rax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
subl %eax, %ebx
leaq -0x108(%rbp), %rsi
movq %r14, %rdi
movl -0x2c(%rbp), %edx
movq %rbx, %r12
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0xe678
movl %eax, %ebx
movq -0x108(%rbp), %rdi
cmpq %r13, %rdi
je 0xf75e
callq 0x4360
movzbl %bl, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %r13
leaq 0x45c0(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %r13, %rdi
movl -0x2c(%rbp), %esi
callq 0x45f0
movq %rax, %r13
leaq 0x401f(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %r13, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %r13
leaq 0x4575(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %r13, %rdi
callq 0x43f0
movq %rax, %r13
leaq 0x3b44(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x38(%rbp), %esi
movq %r13, %rdi
callq 0x45f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
jmp 0xfb2c
movl 0x290(%r14), %ecx
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf492
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0xf492
leaq -0x70(%rbp), %rbx
movl 0x10(%rbx), %r15d
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0xf86b
callq 0x4360
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0xf492
movl -0x60(%rbp), %r12d
movq -0x80(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf895
callq 0x4360
leaq -0xd8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x56fa
leaq -0xe8(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0xe678
movl %eax, %ebx
movq -0xe8(%rbp), %rdi
cmpq %r13, %rdi
je 0xf8e2
callq 0x4360
movzbl %bl, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %r13
leaq 0x443c(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %r13, %rdi
movl %r15d, %esi
callq 0x45f0
movq %rax, %r13
leaq 0x3e9b(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %r13, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %r13
leaq 0x43f1(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %r13, %rdi
callq 0x43f0
movq %rax, %r13
leaq 0x39c0(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x38(%rbp), %esi
movq %r13, %rdi
callq 0x45f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
jmp 0xfb28
movl 0x290(%r14), %ecx
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf492
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0xf492
leaq -0x70(%rbp), %rbx
movl 0x10(%rbx), %r15d
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0xf9ef
callq 0x4360
movl 0x290(%r14), %ecx
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0xf492
movl -0x60(%rbp), %r12d
movq -0x80(%rbp), %rdi
cmpq %rbx, %rdi
je 0xfa19
callq 0x4360
leaq -0xb8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x56fa
leaq -0xc8(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0xe678
movl %eax, %ebx
movq -0xc8(%rbp), %rdi
cmpq %r13, %rdi
je 0xfa66
callq 0x4360
movzbl %bl, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %r13
leaq 0x42b8(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %r13, %rdi
movl %r15d, %esi
callq 0x45f0
movq %rax, %r13
leaq 0x3d17(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %r13, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %r13
leaq 0x426d(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %r13, %rdi
callq 0x43f0
movq %rax, %r13
leaq 0x383c(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x38(%rbp), %esi
movq %r13, %rdi
callq 0x45f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4380
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4260
movl %r15d, -0x2c(%rbp)
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfb3e
callq 0x4360
movb $0x1, %r13b
testb %bl, %bl
jne 0xfc86
movl 0x290(%r14), %ecx
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0xf492
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x56fa
leaq -0xa8(%rbp), %rsi
movq %r14, %rdi
movl -0x2c(%rbp), %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0xe678
movl %eax, %r13d
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xfbb1
callq 0x4360
movzbl %r13b, %esi
movq %r14, %rdi
callq 0x45a0
movq %rax, %rbx
leaq 0x416c(%rip), %rsi      # 0x13d33
movl $0x1b, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x3bcb(%rip), %rsi      # 0x137b4
movl $0x4, %edx
movq %rax, %rdi
callq 0x43f0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x45f0
movq %rax, %rbx
leaq 0x4121(%rip), %rsi      # 0x13d2c
movl $0x6, %edx
movq %rax, %rdi
callq 0x43f0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x43f0
movq %rax, %rbx
leaq 0x36f0(%rip), %rsi      # 0x13322
movl $0x1, %edx
movq %rax, %rdi
callq 0x43f0
movl -0x38(%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 -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfc86
callq 0x4360
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, %rbx
movq -0x108(%rbp), %rdi
jmp 0xfcd0
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
jmp 0xfcd0
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
cmpq %r13, %rdi
jne 0xfcf8
jmp 0xfd19
movq %rax, %rdi
callq 0xa583
jmp 0xfd16
jmp 0xfd16
jmp 0xfd16
jmp 0xfd16
jmp 0xfd16
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xfd19
callq 0x4360
jmp 0xfd19
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
jne 0xfd26
jmp 0xfd2b
jmp 0xfd16
jmp 0xfd16
jmp 0xfd16
movq %rax, %rbx
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfd2b
callq 0x4360
movq %rbx, %rdi
callq 0x4630
nop