// File: /workspace/github_cpp_makefile_star2_O2/tonymuu[P]distributed-kv-store/MP1Node.cpp
// Function: MP1Node::deserializeAndUpdateMemberList(char*, int)
void MP1Node::deserializeAndUpdateMemberList(char *data, int size) {
    // map of port, heartbeat, timestamp
    auto map = createMemberlistMap();

    auto currTime = par->getcurrtime();

    int mleSize = sizeof(int) + sizeof(short) + sizeof(long) + sizeof(long);
    int numEntries = (size - sizeof(MessageHdr)) / mleSize;
    int offset = sizeof(MessageHdr);

    for (int i = 0; i < numEntries; i++) {
        // get the member list
        int id = 0;
        short port = 0;
        long heartbeat = 0;
        long timestamp = 0;

        memcpy(&id, data + offset, sizeof(int));
        offset += sizeof(int);

        memcpy(&port, data + offset, sizeof(short));
        offset += sizeof(short);

        memcpy(&heartbeat, data + offset, sizeof(long));
        offset += sizeof(long);

        memcpy(&timestamp, data + offset, sizeof(long));
        offset += sizeof(long);

        // if member doesn't exist in current member list, we add it there
//        MemberListEntry* old = getNodeFromMemberListTable(id);
        if (map.count(id) == 0) {
//        if (old == nullptr) {
            MemberListEntry entry = MemberListEntry(id, port, heartbeat, currTime);
            memberNode->memberList.push_back(entry);

            // log the new mle join
            Address addr = createAddressFromIdAndPort(id, port);
            log->logNodeAdd(&memberNode->addr, &addr);
        } else {
            // update the existing member entry
            auto old = map[id];
            if (old->heartbeat < heartbeat) {
                if (failed.count(id) > 0) {
                    failed.erase(id);
                }
                old->setheartbeat(heartbeat);
                old->settimestamp(currTime);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x4972
movq 0x18(%r13), %rdi
callq 0xabe4
movl %eax, %ecx
movslq %ebp, %rax
addq $-0x4, %rax
xorl %r12d, %r12d
pushq $0x16
popq %rsi
xorl %edx, %edx
divq %rsi
movslq %ecx, %rcx
movq %rcx, 0x10(%rsp)
testl %eax, %eax
cmovgl %eax, %r12d
pushq $0x4
popq %rax
movq %rbx, 0x18(%rsp)
subl $0x1, %r12d
jb 0x47bc
movq %rax, %r14
shlq $0x20, %r14
cltq
movl (%rbx,%rax), %eax
movl %eax, 0x4(%rsp)
movabsq $0x400000000, %rax      # imm = 0x400000000
addq %r14, %rax
sarq $0x20, %rax
movzwl (%rbx,%rax), %r15d
movabsq $0x600000000, %rax      # imm = 0x600000000
addq %r14, %rax
sarq $0x20, %rax
movq (%rbx,%rax), %rbp
leaq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4b5a
testq %rax, %rax
je 0x4746
leaq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4b74
movq (%rax), %r15
cmpq %rbp, 0x8(%r15)
jge 0x479f
leaq 0x18bf4(%rip), %rdi     # 0x1d300
leaq 0x4(%rsp), %rsi
callq 0x5b18
testq %rax, %rax
je 0x472c
leaq 0x18bde(%rip), %rdi     # 0x1d300
leaq 0x4(%rsp), %rsi
callq 0x5f10
movq %r15, %rdi
movq %rbp, %rsi
callq 0xaccc
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0xacd2
jmp 0x479f
movl 0x4(%rsp), %esi
movswl %r15w, %edx
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rcx
movq 0x10(%rsp), %r8
callq 0xac5e
movq %r13, %rbp
movq 0x20(%r13), %rdi
addq $0x28, %rdi
movq %rbx, %rsi
callq 0x4b28
movl 0x4(%rsp), %eax
movl %eax, 0x8(%rsp)
movw %r15w, 0xc(%rsp)
movq 0x10(%rbp), %rdi
movq 0x20(%rbp), %rsi
addq $0x8, %rsi
leaq 0x8(%rsp), %rdx
callq 0xa3aa
movq 0x18(%rsp), %rbx
movabsq $0xe00000000, %rax      # imm = 0xE00000000
addq %rax, %r14
sarq $0x20, %r14
addq $0x8, %r14
movq %r14, %rax
jmp 0x4690
leaq 0x20(%rsp), %rdi
callq 0x5340
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x47dd
jmp 0x47dd
jmp 0x47dd
jmp 0x47dd
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5340
movq %rbx, %rdi
callq 0x3490