// File: devanshdalal[P]cloud-computing-concepts-part-2/MP1Node.cpp
// Function: MP1Node::nodeLoopOps()
void MP1Node::nodeLoopOps()
{
    // std::cout << "Start nodeLoopOps " << this_node_ << " " << last_detection_ << "\n";
    if (!memberNode->memberList.size())
        return;
    const auto current_time = par->getcurrtime();
    if (last_detection_ + DETECTION_INTERVAL > current_time)
    {
        last_detection_ = current_time;
        int x = rand() % memberNode->memberList.size();
        auto &e = memberNode->memberList[x];
        const int &id = e.getid();
        const int &port = e.getport();

        MessageHdr *msg = CreateMessage(PING, this_node_, id);
        Address target_address = std::to_string(id) + ":" + std::to_string(port);

        if (!emulNet->ENsend(&memberNode->addr, &target_address, (char *)msg, MSGSIZE))
        {
            // local_state_[id] = {TIMEOUTWAITING, current_time, -1};
            // failed, so send.
        }
        else
        {
        }
        local_state_[id] = {TIMEOUTWAITING, current_time + WAITING_TIMEOUT, -1};
    }

    ModifyLocalState();

    // std::cout << "End nodeLoopOps\n";
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq 0x20(%rax), %rdi
addq $0x28, %rdi
callq 0x6ad0
cmpq $0x0, %rax
jne 0x5212
jmp 0x54a1
movq -0xf8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x17080
movl %eax, %ecx
movq -0xf8(%rbp), %rax
movl %ecx, -0xc(%rbp)
movl 0xa0(%rax), %eax
addl $0x1e, %eax
cmpl -0xc(%rbp), %eax
jle 0x5495
movq -0xf8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, 0xa0(%rax)
callq 0x40e0
movl %eax, %ecx
movq -0xf8(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, -0x108(%rbp)
movq 0x20(%rax), %rdi
addq $0x28, %rdi
callq 0x6ad0
movq %rax, %rcx
movq -0x108(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq -0xf8(%rbp), %rax
movl %edx, %ecx
movl %ecx, -0x10(%rbp)
movq 0x20(%rax), %rdi
addq $0x28, %rdi
movslq -0x10(%rbp), %rsi
callq 0x6b00
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x172a0
movl %eax, -0x24(%rbp)
leaq -0x24(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x172b0
movw %ax, %cx
movq -0xf8(%rbp), %rax
movswl %cx, %ecx
movl %ecx, -0x34(%rbp)
leaq -0x34(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movl 0xa4(%rax), %esi
movq -0x20(%rbp), %rax
movl (%rax), %edx
movl $0x3, %edi
callq 0x6010
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %esi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x67e0
movq -0x100(%rbp), %rsi
leaq 0x25ac6(%rip), %rdx     # 0x2ade1
leaq -0x88(%rbp), %rdi
callq 0x6790
jmp 0x5329
movq -0x30(%rbp), %rax
movl (%rax), %esi
leaq -0xd8(%rbp), %rdi
callq 0x67e0
jmp 0x533d
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x6e20
jmp 0x5356
leaq -0x46(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6900
jmp 0x5365
leaq -0x68(%rbp), %rdi
callq 0x41e0
leaq -0xd8(%rbp), %rdi
callq 0x41e0
leaq -0x88(%rbp), %rdi
callq 0x41e0
leaq -0xa8(%rbp), %rdi
callq 0x41e0
movq -0xf8(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x20(%rax), %rsi
addq $0x8, %rsi
movq -0x40(%rbp), %rcx
leaq -0x46(%rbp), %rdx
movl $0xc, %r8d
callq 0xcad0
cmpl $0x0, %eax
jne 0x543c
jmp 0x543e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x542e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x5422
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x5416
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x41e0
leaq -0xd8(%rbp), %rdi
callq 0x41e0
leaq -0x88(%rbp), %rdi
callq 0x41e0
leaq -0xa8(%rbp), %rdi
callq 0x41e0
jmp 0x54aa
jmp 0x543e
movq -0xf8(%rbp), %rdi
movl $0x0, -0xf0(%rbp)
movl -0xc(%rbp), %eax
addl $0xa, %eax
cltq
movq %rax, -0xe8(%rbp)
movl $0xffffffff, -0xe0(%rbp) # imm = 0xFFFFFFFF
addq $0x68, %rdi
movq -0x20(%rbp), %rsi
callq 0x6b20
movq -0xf0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xe8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xe0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0xf8(%rbp), %rdi
callq 0x6060
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x4570
nopw %cs:(%rax,%rax)