// File: devanshdalal[P]cloud-computing-concepts-part-2/MP1Node.cpp
// Function: MP1Node::ModifyLocalState()
void MP1Node::ModifyLocalState()
{
    // std::cout << "Start ModifyLocalState\n";
    const auto current_time = par->getcurrtime();
    for (auto it = local_state_.begin(); it != local_state_.end();)
    {
        const auto &node_status = it->second;
        // std::cout << "node_status.state: " << node_status.state << " " << this_node_ << " " << it->first << "\n";
        // std::cout << "node_status: " << node_status.timeout << " " << current_time << "\n";
        if (node_status.timeout <= current_time)
        {
            switch (node_status.state)
            {
            case FINALWAITING:
            {
                it = local_state_.erase(it);
            }
            break;
            case SWIMWAITING:
            {
                // remove
                auto *message = CreateMessage(FAILED, it->first, this_node_);
                PublishToAll(*message, MSGSIZE);
                free(message);
                it = local_state_.erase(it);
            }
            break;
            case TIMEOUTWAITING:
            {
                PingK(it->first);
                local_state_[it->first] = {SWIMWAITING, current_time + WAITING_TIMEOUT, -1};
            }
            break;
            default:
                break;
            }
            // it = local_state_.erase(it);
        }
        else
        {
            ++it;
        }
    }
    // std::cout << "End ModifyLocalState\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq 0x18(%rax), %rdi
callq 0x17080
movq -0x70(%rbp), %rdi
movl %eax, -0xc(%rbp)
addq $0x68, %rdi
callq 0x6c40
movq %rax, -0x18(%rbp)
movq -0x70(%rbp), %rdi
addq $0x68, %rdi
callq 0x6bb0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x6b80
testb $0x1, %al
jne 0x60bb
jmp 0x6219
leaq -0x18(%rbp), %rdi
callq 0x6be0
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jg 0x620b
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
testl %eax, %eax
je 0x619e
jmp 0x60f4
movl -0x74(%rbp), %eax
subl $0x1, %eax
je 0x6136
jmp 0x60fe
movl -0x74(%rbp), %eax
subl $0x2, %eax
jne 0x6207
jmp 0x610c
movq -0x70(%rbp), %rdi
addq $0x68, %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
callq 0x6ef0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x6209
leaq -0x18(%rbp), %rdi
callq 0x6be0
movq %rax, %rcx
movq -0x70(%rbp), %rax
movl (%rcx), %esi
movl 0xa4(%rax), %edx
movl $0x2, %edi
callq 0x6010
movq -0x70(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
movl $0xc, %edx
callq 0x5df0
movq -0x40(%rbp), %rdi
callq 0x43e0
movq -0x70(%rbp), %rdi
addq $0x68, %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
callq 0x6ef0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x6209
leaq -0x18(%rbp), %rdi
callq 0x6be0
movq -0x70(%rbp), %rdi
movl (%rax), %esi
callq 0x6230
movq -0x70(%rbp), %rax
movl $0x1, -0x68(%rbp)
movl -0xc(%rbp), %ecx
addl $0xa, %ecx
movslq %ecx, %rcx
movq %rcx, -0x60(%rbp)
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
addq $0x68, %rax
movq %rax, -0x80(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x6be0
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x6b20
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x6209
jmp 0x6209
jmp 0x6214
leaq -0x18(%rbp), %rdi
callq 0x6c70
jmp 0x6094
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)