// File: 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
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rsi, -0x248(%rbp)
movq %rdx, -0x260(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x258(%rbp)
movl 0x88(%rax), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x88(%rax)
movl %ecx, -0x20(%rbp)
addq $0x90, %rax
movq %rax, -0x250(%rbp)
movl $0x58, %edi
callq 0x4310
movq -0x248(%rbp), %rsi
movq %rax, -0x240(%rbp)
movb $0x1, -0x79(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x234(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4150
jmp 0x1b503
movq -0x260(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x4150
jmp 0x1b515
movl -0x234(%rbp), %esi
movq -0x240(%rbp), %rdi
leaq -0x48(%rbp), %rdx
leaq -0x78(%rbp), %rcx
callq 0x1e9b0
jmp 0x1b531
movq -0x250(%rbp), %rdi
movq -0x240(%rbp), %rax
movb $0x0, -0x79(%rbp)
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0x1e960
movb %dl, -0x269(%rbp)
movq %rax, -0x268(%rbp)
jmp 0x1b563
movb -0x269(%rbp), %al
movq -0x268(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movb %al, -0x88(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x41e0
leaq -0x48(%rbp), %rdi
callq 0x41e0
movl $0x78, %edi
callq 0x4310
movq %rax, %rcx
movq -0x258(%rbp), %rax
movq %rcx, -0x278(%rbp)
movb $0x1, -0xe1(%rbp)
movl -0x20(%rbp), %ecx
movl %ecx, -0x270(%rbp)
movq 0x50(%rax), %rsi
addq $0x8, %rsi
leaq -0x9e(%rbp), %rdi
callq 0x15070
jmp 0x1b5d0
movq -0x248(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, -0x27c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x4150
jmp 0x1b5ee
movq -0x260(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x4150
jmp 0x1b603
movl -0x27c(%rbp), %ecx
movl -0x270(%rbp), %esi
movq -0x278(%rbp), %rdi
movq %rsp, %rax
movl $0x0, (%rax)
leaq -0x9e(%rbp), %rdx
leaq -0xc0(%rbp), %r8
leaq -0xe0(%rbp), %r9
callq 0x26360
jmp 0x1b63b
movb $0x0, -0xe1(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x41e0
leaq -0xc0(%rbp), %rdi
callq 0x41e0
movq -0x278(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x78, %edi
callq 0x4310
movq %rax, %rcx
movq -0x258(%rbp), %rax
movq %rcx, -0x288(%rbp)
movb $0x1, -0x139(%rbp)
movl -0x20(%rbp), %ecx
movl %ecx, -0x280(%rbp)
movq 0x50(%rax), %rsi
addq $0x8, %rsi
leaq -0xf6(%rbp), %rdi
callq 0x15070
jmp 0x1b6a9
movq -0x248(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, -0x28c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x4150
jmp 0x1b6c7
movq -0x260(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x4150
jmp 0x1b6dc
movl -0x28c(%rbp), %ecx
movl -0x280(%rbp), %esi
movq -0x288(%rbp), %rdi
movq %rsp, %rax
movl $0x1, (%rax)
leaq -0xf6(%rbp), %rdx
leaq -0x118(%rbp), %r8
leaq -0x138(%rbp), %r9
callq 0x26360
jmp 0x1b714
movb $0x0, -0x139(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x41e0
leaq -0x118(%rbp), %rdi
callq 0x41e0
movq -0x288(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x78, %edi
callq 0x4310
movq %rax, %rcx
movq -0x258(%rbp), %rax
movq %rcx, -0x298(%rbp)
movb $0x1, -0x191(%rbp)
movl -0x20(%rbp), %ecx
movl %ecx, -0x290(%rbp)
movq 0x50(%rax), %rsi
addq $0x8, %rsi
leaq -0x14e(%rbp), %rdi
callq 0x15070
jmp 0x1b782
movq -0x248(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, -0x29c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x4150
jmp 0x1b7a0
movq -0x260(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x4150
jmp 0x1b7b5
movl -0x29c(%rbp), %ecx
movl -0x290(%rbp), %esi
movq -0x298(%rbp), %rdi
movq %rsp, %rax
movl $0x2, (%rax)
leaq -0x14e(%rbp), %rdx
leaq -0x170(%rbp), %r8
leaq -0x190(%rbp), %r9
callq 0x26360
jmp 0x1b7ed
movb $0x0, -0x191(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x41e0
leaq -0x170(%rbp), %rdi
callq 0x41e0
movq -0x298(%rbp), %rax
movq -0x248(%rbp), %rsi
movq %rax, -0x148(%rbp)
leaq -0x1d0(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x4150
movq -0x258(%rbp), %rsi
movq -0x2a8(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
callq 0x1b070
jmp 0x1b850
leaq -0x1d0(%rbp), %rdi
callq 0x41e0
movq -0x98(%rbp), %rsi
leaq -0x1f0(%rbp), %rdi
callq 0x26980
jmp 0x1b871
movq -0x258(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x60(%rcx), %rcx
movq %rcx, -0x2c8(%rbp)
addq $0x8, %rax
movq %rax, -0x2c0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b0(%rbp), %rdi
callq 0x13400
addq $0x8, %rax
movq %rax, -0x2b8(%rbp)
leaq -0x1f0(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x4140
movq -0x2d0(%rbp), %rdi
movq %rax, -0x2b0(%rbp)
callq 0x4220
movq -0x2c8(%rbp), %rdi
movq -0x2c0(%rbp), %rsi
movq -0x2b8(%rbp), %rdx
movq -0x2b0(%rbp), %rcx
movl %eax, %r8d
callq 0xac80
jmp 0x1b8f9
movq -0xf0(%rbp), %rsi
leaq -0x210(%rbp), %rdi
callq 0x26980
jmp 0x1b90e
movq -0x258(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x60(%rcx), %rcx
movq %rcx, -0x2f0(%rbp)
addq $0x8, %rax
movq %rax, -0x2e8(%rbp)
leaq -0x1b0(%rbp), %rdi
movl $0x1, %esi
callq 0x13400
addq $0x8, %rax
movq %rax, -0x2e0(%rbp)
leaq -0x210(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x4140
movq -0x2f8(%rbp), %rdi
movq %rax, -0x2d8(%rbp)
callq 0x4220
movq -0x2f0(%rbp), %rdi
movq -0x2e8(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
movq -0x2d8(%rbp), %rcx
movl %eax, %r8d
callq 0xac80
jmp 0x1b997
movq -0x148(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x26980
jmp 0x1b9ac
movq -0x258(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x60(%rcx), %rcx
movq %rcx, -0x318(%rbp)
addq $0x8, %rax
movq %rax, -0x310(%rbp)
leaq -0x1b0(%rbp), %rdi
movl $0x2, %esi
callq 0x13400
addq $0x8, %rax
movq %rax, -0x308(%rbp)
leaq -0x230(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x4140
movq -0x320(%rbp), %rdi
movq %rax, -0x300(%rbp)
callq 0x4220
movq -0x318(%rbp), %rdi
movq -0x310(%rbp), %rsi
movq -0x308(%rbp), %rdx
movq -0x300(%rbp), %rcx
movl %eax, %r8d
callq 0xac80
jmp 0x1ba35
movq -0x98(%rbp), %rax
movq %rax, -0x328(%rbp)
cmpq $0x0, %rax
je 0x1ba66
movq -0x328(%rbp), %rdi
callq 0x1ea70
movq -0x328(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
movq -0xf0(%rbp), %rax
movq %rax, -0x330(%rbp)
cmpq $0x0, %rax
je 0x1ba97
movq -0x330(%rbp), %rdi
callq 0x1ea70
movq -0x330(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
movq -0x148(%rbp), %rax
movq %rax, -0x338(%rbp)
cmpq $0x0, %rax
je 0x1bac8
movq -0x338(%rbp), %rdi
callq 0x1ea70
movq -0x338(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
leaq -0x230(%rbp), %rdi
callq 0x41e0
leaq -0x210(%rbp), %rdi
callq 0x41e0
leaq -0x1f0(%rbp), %rdi
callq 0x41e0
leaq -0x1b0(%rbp), %rdi
callq 0x10c60
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bb3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bb32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x41e0
leaq -0x48(%rbp), %rdi
callq 0x41e0
testb $0x1, -0x79(%rbp)
jne 0x1bb43
jmp 0x1bb54
movq -0x240(%rbp), %rdi
movl $0x58, %esi
callq 0x4320
jmp 0x1bcfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bb99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bb8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x41e0
leaq -0xc0(%rbp), %rdi
callq 0x41e0
testb $0x1, -0xe1(%rbp)
jne 0x1bba4
jmp 0x1bbb5
movq -0x278(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
jmp 0x1bcfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bbfa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bbee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x41e0
leaq -0x118(%rbp), %rdi
callq 0x41e0
testb $0x1, -0x139(%rbp)
jne 0x1bc05
jmp 0x1bc16
movq -0x288(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
jmp 0x1bcfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bc5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bc4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x41e0
leaq -0x170(%rbp), %rdi
callq 0x41e0
testb $0x1, -0x191(%rbp)
jne 0x1bc66
jmp 0x1bc77
movq -0x298(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
jmp 0x1bcfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x41e0
jmp 0x1bcfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bcf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bce4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1bcd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x41e0
leaq -0x210(%rbp), %rdi
callq 0x41e0
leaq -0x1f0(%rbp), %rdi
callq 0x41e0
leaq -0x1b0(%rbp), %rdi
callq 0x10c60
movq -0x50(%rbp), %rdi
callq 0x4550
nopw %cs:(%rax,%rax)