// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbx
movl 0x88(%rdi), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x88(%rdi)
movl %eax, 0x14(%rsp)
pushq $0x58
popq %rdi
callq 0x3260
movq %rax, %r14
leaq 0x198(%rsp), %rdi
movq %r12, %rsi
callq 0x3340
leaq 0x178(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
movb $0x1, %r15b
leaq 0x198(%rsp), %rdx
leaq 0x178(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
callq 0xe682
leaq 0x90(%rbx), %rdi
leaq 0x58(%rsp), %rdx
movq %r14, (%rdx)
xorl %r15d, %r15d
leaq 0x14(%rsp), %rsi
callq 0xf4ba
leaq 0x178(%rsp), %rdi
callq 0x3110
leaq 0x198(%rsp), %rdi
callq 0x3110
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r15
movl 0x14(%rsp), %r14d
movq 0x50(%rbx), %rsi
addq $0x8, %rsi
leaq 0x32(%rsp), %rdi
callq 0x9f14
leaq 0x158(%rsp), %rdi
movq %r12, %rsi
callq 0x3340
leaq 0x138(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
andl $0x0, (%rsp)
leaq 0x32(%rsp), %rdx
leaq 0x158(%rsp), %r8
leaq 0x138(%rsp), %r9
movq %r15, %rdi
movl %r14d, %esi
movl %ebp, %ecx
callq 0x10ae6
leaq 0x138(%rsp), %rdi
callq 0x3110
leaq 0x158(%rsp), %rdi
callq 0x3110
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, 0x18(%rsp)
movl 0x14(%rsp), %r14d
movq 0x50(%rbx), %rsi
addq $0x8, %rsi
leaq 0x2c(%rsp), %rdi
callq 0x9f14
leaq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x3340
leaq 0xf8(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
movq %r15, 0x38(%rsp)
movl $0x1, (%rsp)
leaq 0x2c(%rsp), %rdx
leaq 0x118(%rsp), %r8
leaq 0xf8(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %ecx
callq 0x10ae6
leaq 0xf8(%rsp), %rdi
callq 0x3110
leaq 0x118(%rsp), %rdi
callq 0x3110
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r14
movl 0x14(%rsp), %r15d
movq 0x50(%rbx), %rsi
addq $0x8, %rsi
leaq 0x26(%rsp), %rdi
callq 0x9f14
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x3340
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
movl $0x2, (%rsp)
leaq 0x26(%rsp), %rdx
leaq 0xd8(%rsp), %r8
leaq 0xb8(%rsp), %r9
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %ecx
callq 0x10ae6
leaq 0xb8(%rsp), %rdi
callq 0x3110
leaq 0xd8(%rsp), %rdi
callq 0x3110
leaq 0x1b8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x3340
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0xca10
leaq 0x1b8(%rsp), %rdi
callq 0x3110
leaq 0x58(%rsp), %rdi
movq 0x38(%rsp), %r15
movq %r15, %rsi
callq 0x10fb8
movq 0x50(%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
movq 0x40(%rsp), %rdx
addq $0x8, %rdx
movq 0x58(%rsp), %rcx
movl 0x60(%rsp), %r8d
callq 0x56ee
leaq 0x98(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x10fb8
movq 0x50(%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
movq 0x40(%rsp), %rdx
addq $0x28, %rdx
movq 0x98(%rsp), %rcx
movl 0xa0(%rsp), %r8d
callq 0x56ee
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x10fb8
movq 0x50(%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
movq 0x40(%rsp), %rdx
addq $0x48, %rdx
movq 0x78(%rsp), %rcx
movl 0x80(%rsp), %r8d
callq 0x56ee
movq %r15, %rdi
callq 0xe704
pushq $0x78
popq %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3270
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0xe704
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3270
movq %r14, %rdi
callq 0xe704
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3270
leaq 0x78(%rsp), %rdi
callq 0x3110
leaq 0x98(%rsp), %rdi
callq 0x3110
leaq 0x58(%rsp), %rdi
callq 0x3110
leaq 0x40(%rsp), %rdi
callq 0x894c
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x3110
jmp 0xcf80
jmp 0xcf7d
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3110
jmp 0xcf94
jmp 0xcf91
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x3110
leaq 0x40(%rsp), %rdi
callq 0x894c
jmp 0xd08c
movq %rax, %rbx
jmp 0xcf9e
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x3110
jmp 0xd08c
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3110
jmp 0xcfdc
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3110
jmp 0xd043
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3110
jmp 0xd000
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x3110
jmp 0xd04a
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x3110
jmp 0xd024
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x3110
jmp 0xd057
movq %rax, %rbx
movb $0x1, %r15b
jmp 0xd06f
movq %rax, %rbx
jmp 0xd081
movq %rax, %rbx
pushq $0x78
jmp 0xd083
movq %rax, %rbx
pushq $0x78
popq %rsi
movq 0x18(%rsp), %rdi
jmp 0xd087
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r15, %rdi
jmp 0xd087
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x3110
leaq 0x198(%rsp), %rdi
callq 0x3110
testb %r15b, %r15b
je 0xd08c
pushq $0x58
popq %rsi
movq %r14, %rdi
callq 0x3270
movq %rbx, %rdi
callq 0x3420