// File: devanshdalal[P]cloud-computing-concepts-part-2/MP2Node.cpp
// Function: MP2Node::clientCreateOrUpdate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, MessageType)
void MP2Node::clientCreateOrUpdate(string key, string value, MessageType type)
{
	/*
	 * Implement this
	 */
	int current = g_transID++;
	auto nodes = findNodes(key);
	// std::cout << "Start clientCreate " << key << " " << nodes.size() << "\n";
	for (auto node_id = 0; node_id < nodes.size(); ++node_id)
	{
		auto req = Message(current, memberNode->addr, type, key, value,
						   static_cast<ReplicaType>(node_id));
		emulNet->ENsend(&(memberNode->addr), nodes[node_id].getAddress(), req.toString());
	}
	local_state_[current] = {type, key, value, par->getcurrtime() + WRITE_TIMEOUT, 0};
	// std::cout << "End clientCreate\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rsi, -0x1c0(%rbp)
movq %rdx, -0x1b8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl 0x25473(%rip), %eax     # 0x4295c
movl %eax, %ecx
incl %ecx
movl %ecx, 0x25469(%rip)     # 0x4295c
movl %eax, -0x20(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x4150
movq -0x1b0(%rbp), %rsi
movq -0x1a8(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x1d870
jmp 0x1d51f
leaq -0x58(%rbp), %rdi
callq 0x41e0
movl $0x0, -0x68(%rbp)
movslq -0x68(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x12c90
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d734
movq -0x1b0(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, -0x1cc(%rbp)
movq 0x60(%rax), %rsi
addq $0x8, %rsi
leaq -0xe6(%rbp), %rdi
callq 0x170d0
jmp 0x1d57c
movq -0x1c0(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, -0x1d0(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x4150
jmp 0x1d59a
movq -0x1b8(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0x4150
jmp 0x1d5af
movl -0x1d0(%rbp), %ecx
movl -0x1cc(%rbp), %esi
movl -0x68(%rbp), %edx
movq %rsp, %rax
movl %edx, (%rax)
leaq -0xe0(%rbp), %rdi
leaq -0xe6(%rbp), %rdx
leaq -0x108(%rbp), %r8
leaq -0x128(%rbp), %r9
callq 0x28590
jmp 0x1d5e6
leaq -0x128(%rbp), %rdi
callq 0x41e0
leaq -0x108(%rbp), %rdi
callq 0x41e0
movq -0x1b0(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x70(%rcx), %rcx
movq %rcx, -0x1e8(%rbp)
addq $0x8, %rax
movq %rax, -0x1e0(%rbp)
movslq -0x68(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x15460
movq %rax, %rdi
callq 0x25a90
movq %rax, -0x1d8(%rbp)
jmp 0x1d63d
leaq -0x148(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x28bb0
jmp 0x1d652
movq -0x1d8(%rbp), %rdx
movq -0x1e0(%rbp), %rsi
movq -0x1e8(%rbp), %rdi
leaq -0x148(%rbp), %rcx
callq 0xcce0
jmp 0x1d675
leaq -0x148(%rbp), %rdi
callq 0x41e0
leaq -0xe0(%rbp), %rdi
callq 0x21280
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1d52f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x41e0
jmp 0x1d85b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1d852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1d6ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x41e0
leaq -0x108(%rbp), %rdi
callq 0x41e0
jmp 0x1d852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1d723
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x41e0
leaq -0xe0(%rbp), %rdi
callq 0x21280
jmp 0x1d852
movq -0x1c0(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, -0x1a0(%rbp)
leaq -0x198(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x4150
jmp 0x1d759
movq -0x1b8(%rbp), %rsi
leaq -0x178(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x4150
jmp 0x1d775
movq -0x1b0(%rbp), %rax
leaq -0x158(%rbp), %rcx
movq %rcx, -0x208(%rbp)
movq 0x68(%rax), %rdi
callq 0x17080
movl %eax, -0x1fc(%rbp)
jmp 0x1d79b
movq -0x1b0(%rbp), %rdi
movq -0x208(%rbp), %rax
movl -0x1fc(%rbp), %ecx
addl $0xf, %ecx
movl %ecx, (%rax)
movq $0x0, -0x150(%rbp)
subq $-0x80, %rdi
leaq -0x20(%rbp), %rsi
callq 0x212c0
movq %rax, -0x210(%rbp)
jmp 0x1d7d5
movq -0x210(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x213a0
leaq -0x1a0(%rbp), %rdi
callq 0x21410
leaq -0x38(%rbp), %rdi
callq 0x12c30
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1d82c
movq -0x1f8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x41e0
movq -0x1f0(%rbp), %rdi
callq 0x41e0
jmp 0x1d852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x21410
leaq -0x38(%rbp), %rdi
callq 0x12c30
movq -0x60(%rbp), %rdi
callq 0x4570
nopw %cs:(%rax,%rax)