// File: /workspace/github_cpp_makefile_star2_O3/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 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x6790
leaq 0x1a8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x198(%rsp), %rdi
callq 0x6790
movb $0x1, %r12b
leaq 0x20(%rsp), %rdx
leaq 0x198(%rsp), %rcx
movq %rbx, %rdi
movl 0x10(%rsp), %esi
callq 0x12ce2
leaq 0x90(%r14), %rdi
leaq 0xa0(%rsp), %rdx
movq %rbx, (%rdx)
xorl %r12d, %r12d
leaq 0x14(%rsp), %rsi
callq 0x13ace
movq 0x198(%rsp), %rdi
cmpq %r15, %rdi
je 0xff80
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xff9c
movq 0x30(%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 0x52(%rsp), %rdi
callq 0xd01c
leaq 0x188(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x178(%rsp), %rdi
callq 0x6790
leaq 0x168(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x158(%rsp), %rdi
callq 0x6790
movl $0x0, (%rsp)
leaq 0x52(%rsp), %rdx
leaq 0x178(%rsp), %r8
leaq 0x158(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %r15d, %esi
movl 0x10(%rsp), %ecx
callq 0x15b0a
movq 0x158(%rsp), %rdi
cmpq %r12, %rdi
je 0x10055
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x178(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10072
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 0x4c(%rsp), %rdi
callq 0xd01c
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x6790
leaq 0x148(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x138(%rsp), %rdi
callq 0x6790
movl $0x1, (%rsp)
leaq 0x4c(%rsp), %rdx
leaq 0x78(%rsp), %r8
leaq 0x138(%rsp), %r9
movq %r15, %rdi
movl %r12d, %esi
movl 0x10(%rsp), %ecx
callq 0x15b0a
movq 0x138(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10120
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x10142
movq 0x88(%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 0x46(%rsp), %rdi
callq 0xd01c
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x6790
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x118(%rsp), %rdi
callq 0x6790
movl $0x2, (%rsp)
leaq 0x46(%rsp), %rdx
leaq 0x58(%rsp), %r8
leaq 0x118(%rsp), %r9
movq %r12, %rdi
movl %ebx, %esi
movl 0x10(%rsp), %ecx
callq 0x15b0a
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x101f3
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1020f
movq 0x68(%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 0x6790
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xfc56
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
movq 0x18(%rsp), %rbx
je 0x1026b
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x160dc
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 0x6e4c
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x160dc
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 0x6e4c
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x160dc
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 0x6e4c
movq 0x58(%rbx), %rdi
leaq 0x68(%rbx), %rax
cmpq %rax, %rdi
je 0x10342
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0x1035a
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x8(%rbx), %rdi
movq %rbx, %rax
addq $0x18, %rax
cmpq %rax, %rdi
je 0x10375
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 0x1039a
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x28(%r15), %rdi
leaq 0x38(%r15), %rax
cmpq %rax, %rdi
je 0x103b2
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
cmpq %rax, %rdi
je 0x103cd
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 0x103f4
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x28(%r12), %rdi
leaq 0x38(%r12), %rax
cmpq %rax, %rdi
je 0x1040e
movq (%rax), %rsi
incq %rsi
callq 0x3280
movq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
cmpq %rax, %rdi
je 0x1042a
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 0x10458
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10479
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1049a
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xc0(%rsp), %rdi
callq 0xbaf6
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 0x104e4
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x104e4
jmp 0x104e1
movq %rax, %r14
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1050c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x1050c
jmp 0x10509
movq %rax, %r14
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10532
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10532
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0xbaf6
jmp 0x106e0
movq %rax, %r14
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
je 0x106e0
movq 0x1c8(%rsp), %rsi
incq %rsi
jmp 0x106db
movq %rax, %r14
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x1058d
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x1058d
movq %rax, %r14
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1066c
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x1066c
movq %rax, %r14
movq 0x138(%rsp), %rdi
cmpq %rbx, %rdi
je 0x105d7
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x105d7
movq %rax, %r14
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x10679
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10679
movq %rax, %r14
movq 0x158(%rsp), %rdi
cmpq %r12, %rdi
je 0x10624
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10624
movq %rax, %r14
movq 0x178(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10686
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x10686
movq %rax, %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x106d3
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x106d3
movq %rax, %r14
jmp 0x106d3
movq %rax, %r14
movl $0x78, %esi
movq %r12, %rdi
jmp 0x106db
movq %rax, %r14
movl $0x78, %esi
movq %r15, %rdi
jmp 0x106db
movq %rax, %r14
movl $0x78, %esi
movq 0x18(%rsp), %rdi
jmp 0x106db
movq %rax, %r14
movq 0x198(%rsp), %rdi
cmpq %r15, %rdi
je 0x106b2
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x106ce
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3280
testb %r12b, %r12b
je 0x106e0
movl $0x58, %esi
movq %rbx, %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3450