// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x4e96
movq %r14, 0x20(%rsp)
movq 0x18(%r14), %rdi
callq 0xc87e
movl %eax, %ecx
movslq %ebp, %rax
addq $-0x4, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rdx # imm = 0x2E8BA2E8BA2E8BA3
mulq %rdx
shrq $0x2, %rdx
movq %rdx, 0x28(%rsp)
testl %edx, %edx
jle 0x4cda
movslq %ecx, %rax
movq %rax, 0x18(%rsp)
movl $0x4, %r12d
xorl %r15d, %r15d
movq %r12, %rax
shlq $0x20, %r12
cltq
movl (%rbx,%rax), %esi
movl %esi, 0xc(%rsp)
movabsq $0x400000000, %rax      # imm = 0x400000000
addq %r12, %rax
sarq $0x20, %rax
movzwl (%rbx,%rax), %r13d
movabsq $0x600000000, %rax      # imm = 0x600000000
addq %r12, %rax
sarq $0x20, %rax
movq (%rbx,%rax), %rbp
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x4c0a
leaq 0x38(%rsp), %r8
movq %r8, %rax
movq %rdi, %rcx
movl 0x20(%rdi), %edx
xorl %edi, %edi
cmpl %esi, %edx
setl %dil
movq %rcx, %r8
cmovlq %rax, %r8
movq 0x10(%rcx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x4bd3
leaq 0x38(%rsp), %rdi
cmpq %rdi, %r8
je 0x4c0a
cmpl %esi, %edx
cmovlq %rax, %rcx
cmpl 0x20(%rcx), %esi
jge 0x4c81
movswl %r13w, %edx
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rcx
movq 0x18(%rsp), %r8
callq 0xc90e
movq 0x20(%rsp), %rbp
movq 0x20(%rbp), %rdi
addq $0x28, %rdi
movq %r14, %rsi
callq 0x5010
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
movw %r13w, 0x14(%rsp)
movq 0x10(%rbp), %rdi
movq 0x20(%rbp), %rsi
addq $0x8, %rsi
leaq 0x10(%rsp), %rdx
callq 0xbe6c
movabsq $0xe00000000, %rax      # imm = 0xE00000000
addq %rax, %r12
sarq $0x20, %r12
addq $0x8, %r12
incl %r15d
cmpl 0x28(%rsp), %r15d
jne 0x4b89
jmp 0x4cda
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x503c
movq (%rax), %r13
cmpq %rbp, 0x8(%r13)
jge 0x4c5c
leaq 0x1b650(%rip), %rdi     # 0x202f0
leaq 0xc(%rsp), %rsi
callq 0x5e8a
testq %rax, %rax
je 0x4cc0
leaq 0x1b63a(%rip), %rdi     # 0x202f0
leaq 0xc(%rsp), %rsi
callq 0x61ea
movq %r13, %rdi
movq %rbp, %rsi
callq 0xc97c
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0xc982
jmp 0x4c5c
leaq 0x30(%rsp), %rdi
callq 0x5642
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4cf9
jmp 0x4cf9
jmp 0x4cf9
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5642
movq %rbx, %rdi
callq 0x34b0