// File: devanshdalal[P]cloud-computing-concepts-part-2/MP2Node.cpp
// Function: MP2Node::deleteExpired()
void MP2Node::deleteExpired()
{
	if (par->getcurrtime() > local_time)
	{
		local_time = par->getcurrtime();
		for (auto it = local_state_.begin(); it != local_state_.end();)
		{
			int trans_id = it->first;
			const auto &state = it->second;
			if (state.expiry < local_time)
			{
				switch (state.type)
				{
				case MessageType::READ:
				{
					log->logReadFail(&(memberNode->addr), true /*is_coordinator*/, trans_id, state.key);
					break;
				}
				case MessageType::CREATE:
				{
					log->logCreateFail(&(memberNode->addr), true /*is_coordinator*/, trans_id, state.key, state.value);
					break;
				}
				case MessageType::UPDATE:
				{
					log->logUpdateFail(&(memberNode->addr), true /*is_coordinator*/, trans_id, state.key, state.value);
					break;
				}
				case MessageType::DELETE:
				{
					log->logDeleteFail(&(memberNode->addr), true /*is_coordinator*/, trans_id, state.key);
					break;
				}
				default:
					break;
				}
				it = local_state_.erase(it);
			}
			else
			{
				++it;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq 0x68(%rax), %rdi
callq 0x17080
movq -0x110(%rbp), %rcx
cmpl 0xb0(%rcx), %eax
jle 0x20d37
movq -0x110(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x17080
movq -0x110(%rbp), %rdi
movl %eax, 0xb0(%rdi)
addq $0x80, %rdi
callq 0x21710
movq %rax, -0x10(%rbp)
movq -0x110(%rbp), %rdi
addq $0x80, %rdi
callq 0x21600
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x215d0
testb $0x1, %al
jne 0x209c0
jmp 0x20d35
leaq -0x10(%rbp), %rdi
callq 0x21630
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x21630
movq -0x110(%rbp), %rcx
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x48(%rax), %eax
cmpl 0xb0(%rcx), %eax
jge 0x20d27
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x118(%rbp)
subq $0x3, %rax
ja 0x20cec
movq -0x118(%rbp), %rax
leaq 0xa28e(%rip), %rcx      # 0x2acac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x110(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x78(%rcx), %rcx
movq %rcx, -0x138(%rbp)
addq $0x8, %rax
movq %rax, -0x130(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x124(%rbp)
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x4150
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
movl -0x124(%rbp), %ecx
movq -0x120(%rbp), %r8
movl $0x1, %edx
callq 0x16b40
jmp 0x20a90
leaq -0x48(%rbp), %rdi
callq 0x41e0
jmp 0x20cee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x41e0
jmp 0x20d40
movq -0x110(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x78(%rcx), %rcx
movq %rcx, -0x150(%rbp)
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x13c(%rbp)
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
leaq -0x78(%rbp), %rdi
callq 0x4150
movq -0x28(%rbp), %rsi
addq $0x28, %rsi
leaq -0x98(%rbp), %rdi
callq 0x4150
jmp 0x20b09
movl -0x13c(%rbp), %ecx
movq -0x148(%rbp), %rsi
movq -0x150(%rbp), %rdi
movl $0x1, %edx
leaq -0x78(%rbp), %r8
leaq -0x98(%rbp), %r9
callq 0x169f0
jmp 0x20b34
leaq -0x98(%rbp), %rdi
callq 0x41e0
leaq -0x78(%rbp), %rdi
callq 0x41e0
jmp 0x20cee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x20b74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x41e0
leaq -0x78(%rbp), %rdi
callq 0x41e0
jmp 0x20d40
movq -0x110(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x78(%rcx), %rcx
movq %rcx, -0x168(%rbp)
addq $0x8, %rax
movq %rax, -0x160(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x154(%rbp)
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x4150
movq -0x28(%rbp), %rsi
addq $0x28, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x4150
jmp 0x20bd6
movl -0x154(%rbp), %ecx
movq -0x160(%rbp), %rsi
movq -0x168(%rbp), %rdi
movl $0x1, %edx
leaq -0xb8(%rbp), %r8
leaq -0xd8(%rbp), %r9
callq 0x16c50
jmp 0x20c04
leaq -0xd8(%rbp), %rdi
callq 0x41e0
leaq -0xb8(%rbp), %rdi
callq 0x41e0
jmp 0x20cee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x20c47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x41e0
leaq -0xb8(%rbp), %rdi
callq 0x41e0
jmp 0x20d40
movq -0x110(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x78(%rcx), %rcx
movq %rcx, -0x188(%rbp)
addq $0x8, %rax
movq %rax, -0x180(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x174(%rbp)
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x4150
movq -0x188(%rbp), %rdi
movq -0x180(%rbp), %rsi
movl -0x174(%rbp), %ecx
movq -0x170(%rbp), %r8
movl $0x1, %edx
callq 0x16da0
jmp 0x20cc4
leaq -0xf8(%rbp), %rdi
callq 0x41e0
jmp 0x20cee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x41e0
jmp 0x20d40
jmp 0x20cee
movq -0x110(%rbp), %rdi
addq $0x80, %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rsi
callq 0x21650
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x20d30
leaq -0x10(%rbp), %rdi
callq 0x21740
jmp 0x20993
jmp 0x20d37
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x4570
nopl (%rax)