// File: /workspace/github_cpp_makefile_star2_O1/zkl94[P]distributed-key-value-store/MP2Node.cpp
// Function: MP2Node::clientCreateUpdate(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::clientCreateUpdate(string key, string value, MessageType t) {
    // construct message
    int transID = this->lowestTransID++;
    this->transID2Bundle.emplace(transID, new Bundle(t, key, value));

    // one transaction involves three servers
    Message *primary_message = new Message(transID, this->memberNode->addr, t, key, value, PRIMARY);
    Message *secondary_message = new Message(transID, this->memberNode->addr, t, key, value, SECONDARY);
    Message *tertiary_message = new Message(transID, this->memberNode->addr, t, key, value, TERTIARY);

    // find primary replica position
    // size_t position = this->hashFunction(key);

    vector<Node> v = findNodes(key);
    // cout << "there are " << v.size() << " nodes for this key" << endl;

    // Address _toAddr = this->ring[position].nodeAddress;
    string primary_string = primary_message->toString();
    emulNet->ENsend(&(this->memberNode->addr), &(v[0].nodeAddress), (char *)primary_string.c_str(), primary_string.size());

    // _toAddr = this->ring[position+1].nodeAddress;
    string secondary_string = secondary_message->toString();
    emulNet->ENsend(&(this->memberNode->addr), &(v[1].nodeAddress), (char *)secondary_string.c_str(), secondary_string.size());

    // _toAddr = this->ring[position+2].nodeAddress;
    string tertiary_string = tertiary_message->toString();
    emulNet->ENsend(&(this->memberNode->addr), &(v[2].nodeAddress), (char *)tertiary_string.c_str(), tertiary_string.size());

    delete primary_message;
    delete secondary_message;
    delete tertiary_message;

    // these messages go to the three replicas and the coordinator waits for responses
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movl %ecx, 0x10(%rsp)
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %r14
movl 0x88(%rdi), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x88(%rdi)
movl %eax, 0x14(%rsp)
movl $0x58, %edi
callq 0x3270
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x6810
leaq 0x1a8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x198(%rsp), %rdi
callq 0x6810
movb $0x1, %r12b
leaq 0x78(%rsp), %rdx
leaq 0x198(%rsp), %rcx
movq %rbx, %rdi
movl 0x10(%rsp), %esi
callq 0x12f8a
leaq 0x90(%r14), %rdi
leaq 0xa0(%rsp), %rdx
movq %rbx, (%rdx)
xorl %r12d, %r12d
leaq 0x14(%rsp), %rsi
callq 0x13d6a
movq 0x198(%rsp), %rdi
cmpq %r15, %rdi
je 0x102e9
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x1030b
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3280
movl $0x78, %edi
callq 0x3270
movq %rax, 0x18(%rsp)
movl 0x14(%rsp), %r15d
movq 0x50(%r14), %rsi
addq $0x8, %rsi
leaq 0x32(%rsp), %rdi
callq 0xd170
leaq 0x188(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x178(%rsp), %rdi
callq 0x6810
leaq 0x168(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x158(%rsp), %rdi
callq 0x6810
movl $0x0, (%rsp)
leaq 0x32(%rsp), %rdx
leaq 0x178(%rsp), %r8
leaq 0x158(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %r15d, %esi
movl 0x10(%rsp), %ecx
callq 0x15db2
movq 0x158(%rsp), %rdi
cmpq %r12, %rdi
je 0x103c4
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x178(%rsp), %rdi
cmpq %rbx, %rdi
je 0x103e1
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x3280
movl $0x78, %edi
callq 0x3270
movq %rax, %r15
movl 0x14(%rsp), %r12d
movq 0x50(%r14), %rsi
addq $0x8, %rsi
leaq 0x2c(%rsp), %rdi
callq 0xd170
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x6810
leaq 0x148(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x138(%rsp), %rdi
callq 0x6810
movl $0x1, (%rsp)
leaq 0x2c(%rsp), %rdx
leaq 0x58(%rsp), %r8
leaq 0x138(%rsp), %r9
movq %r15, %rdi
movl %r12d, %esi
movl 0x10(%rsp), %ecx
callq 0x15db2
movq 0x138(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1048c
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x104a8
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3280
movq %r15, 0x98(%rsp)
movl $0x78, %edi
callq 0x3270
movq %rax, %r12
movl 0x14(%rsp), %ebx
movq 0x50(%r14), %rsi
addq $0x8, %rsi
leaq 0x26(%rsp), %rdi
callq 0xd170
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0x6810
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x118(%rsp), %rdi
callq 0x6810
movl $0x2, (%rsp)
leaq 0x26(%rsp), %rdx
leaq 0x38(%rsp), %r8
leaq 0x118(%rsp), %r9
movq %r12, %rdi
movl %ebx, %esi
movl 0x10(%rsp), %ecx
callq 0x15db2
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x10559
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x10575
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x1c8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x1b8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6810
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xffbc
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
movq 0x18(%rsp), %rbx
je 0x105d1
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x16384
movq 0x98(%rsp), %r15
movq 0x50(%r14), %rsi
movq 0x60(%r14), %rdi
addq $0x8, %rsi
movq 0xc0(%rsp), %rdx
addq $0x8, %rdx
movq 0xa0(%rsp), %rcx
movl 0xa8(%rsp), %r8d
callq 0x6ed0
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x16384
movq 0x50(%r14), %rsi
movq 0x60(%r14), %rdi
addq $0x8, %rsi
movq 0xc0(%rsp), %rdx
addq $0x28, %rdx
movq 0xf8(%rsp), %rcx
movl 0x100(%rsp), %r8d
callq 0x6ed0
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x16384
movq 0x50(%r14), %rsi
movq 0x60(%r14), %rdi
addq $0x8, %rsi
movq 0xc0(%rsp), %rdx
addq $0x48, %rdx
movq 0xd8(%rsp), %rcx
movl 0xe0(%rsp), %r8d
callq 0x6ed0
movq 0x58(%rbx), %rdi
leaq 0x68(%rbx), %rax
cmpq %rax, %rdi
je 0x106a8
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0x106c0
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x8(%rbx), %rdi
movq %rbx, %rax
addq $0x18, %rax
cmpq %rax, %rdi
je 0x106db
movq (%rax), %rsi
incq %rsi
callq 0x3280
movl $0x78, %esi
movq %rbx, %rdi
callq 0x3280
movq 0x58(%r15), %rdi
leaq 0x68(%r15), %rax
cmpq %rax, %rdi
je 0x10700
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x28(%r15), %rdi
leaq 0x38(%r15), %rax
cmpq %rax, %rdi
je 0x10718
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
cmpq %rax, %rdi
je 0x10733
movq (%rax), %rsi
incq %rsi
callq 0x3280
movl $0x78, %esi
movq %r15, %rdi
callq 0x3280
movq 0x58(%r12), %rdi
leaq 0x68(%r12), %rax
cmpq %rax, %rdi
je 0x1075a
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x28(%r12), %rdi
leaq 0x38(%r12), %rax
cmpq %rax, %rdi
je 0x10774
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
cmpq %rax, %rdi
je 0x10790
movq (%rax), %rsi
incq %rsi
callq 0x3280
movl $0x78, %esi
movq %r12, %rdi
callq 0x3280
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x107be
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x107df
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10800
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xc0(%rsp), %rdi
callq 0xbc10
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1084a
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x1084a
jmp 0x10847
movq %rax, %r14
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10872
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10872
jmp 0x1086f
movq %rax, %r14
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10898
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10898
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0xbc10
jmp 0x10a2c
movq %rax, %r14
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
je 0x10a2c
movq 0x1c8(%rsp), %rsi
incq %rsi
jmp 0x10a27
movq %rax, %r14
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x108f3
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x108f3
movq %rax, %r14
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x109b2
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x109b2
movq %rax, %r14
movq 0x138(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1093d
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x1093d
movq %rax, %r14
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x109bf
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x109bf
movq %rax, %r14
movq 0x158(%rsp), %rdi
cmpq %r12, %rdi
je 0x10980
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10980
movq %rax, %r14
movq 0x178(%rsp), %rdi
cmpq %rbx, %rdi
je 0x109cc
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x109cc
movq %rax, %r14
movb $0x1, %r12b
jmp 0x109f8
movq %rax, %r14
movb $0x1, %r12b
jmp 0x10a1a
movq %rax, %r14
movl $0x78, %esi
movq %r12, %rdi
jmp 0x10a27
movq %rax, %r14
movl $0x78, %esi
movq %r15, %rdi
jmp 0x10a27
movq %rax, %r14
movl $0x78, %esi
movq 0x18(%rsp), %rdi
jmp 0x10a27
movq %rax, %r14
movq 0x198(%rsp), %rdi
cmpq %r15, %rdi
je 0x109f8
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x10a1a
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3280
testb %r12b, %r12b
je 0x10a2c
movl $0x58, %esi
movq %rbx, %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3450