// File: zkl94[P]distributed-key-value-store/MP1Node.cpp
// Function: MP1Node::updateEntry(Member*, int, short, long)
void MP1Node::updateEntry(Member *memberNode, int id, short port, long heartbeat) {
    // if this node (with id) is already in to be deleted map, just ignore it
    auto alreadyintobedeletedlist = this->tobedeleted->count(id);
    if (alreadyintobedeletedlist != 0) {
        // already in to be deleted map
        // cout << "already in tobedeleted map, ignore the update" <<endl;
        return;
    }

    // if it is not to be deleted, then update/insert normally
    bool found = false;
    for (MemberListEntry memberListEntry: memberNode->memberList) {
        if (memberListEntry.getid() == id && memberListEntry.getport() == port) {
            found = true;
            // the incoming heartbeat is more latest
            if (memberListEntry.getheartbeat() < heartbeat) {
                // cout << "doing heartbeat update for " << id <<endl;
                memberListEntry.setheartbeat(heartbeat);
                memberListEntry.settimestamp(par->getcurrtime());
            }
            break;
        }
    }

    if (!found) {
        MemberListEntry *newEntry = new MemberListEntry(id, port, heartbeat, par->getcurrtime());
        memberNode->memberList.push_back(*newEntry);

        logNodeAddWrapper(memberNode, id, port);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movw %cx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movw %ax, -0x16(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x38(%rax), %rdi
leaq -0x14(%rbp), %rsi
callq 0x7310
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6656
jmp 0x67e7
movb $0x0, -0x29(%rbp)
movq -0x10(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x7250
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x7280
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x72b0
testb $0x1, %al
jne 0x6696
jmp 0x6716
leaq -0x40(%rbp), %rdi
callq 0x72f0
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x15180
leaq -0x60(%rbp), %rdi
callq 0x15240
cmpl -0x14(%rbp), %eax
jne 0x6706
leaq -0x60(%rbp), %rdi
callq 0x15250
cwtl
movswl -0x16(%rbp), %ecx
cmpl %ecx, %eax
jne 0x6706
movb $0x1, -0x29(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x15270
cmpq -0x20(%rbp), %rax
jge 0x6704
movq -0x20(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x152f0
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15020
movslq %eax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x15310
jmp 0x6716
jmp 0x6708
leaq -0x40(%rbp), %rdi
callq 0x7370
jmp 0x6680
testb $0x1, -0x29(%rbp)
jne 0x67e7
movl $0x18, %edi
callq 0x4310
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, -0xa0(%rbp)
movl -0x14(%rbp), %ecx
movl %ecx, -0x98(%rbp)
movw -0x16(%rbp), %cx
movw %cx, -0x92(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movq 0x18(%rax), %rdi
callq 0x15020
movl %eax, -0x84(%rbp)
jmp 0x6768
movq -0x90(%rbp), %rcx
movl -0x98(%rbp), %esi
movq -0xa0(%rbp), %rdi
movw -0x92(%rbp), %ax
movl -0x84(%rbp), %edx
movslq %edx, %r8
movswl %ax, %edx
callq 0x15110
jmp 0x6796
movq -0xa0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
movq -0x68(%rbp), %rsi
callq 0x6da0
movq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movswl -0x16(%rbp), %ecx
callq 0x5d00
jmp 0x67e7
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x18, %esi
callq 0x4320
jmp 0x67f0
addq $0xa0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x4550
nopl (%rax)