// File: zkl94[P]distributed-key-value-store/MP2Node.cpp
// Function: MP2Node::clientReadDelete(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, MessageType)
void MP2Node::clientReadDelete(string key, MessageType t) {
    // construct message
    int transID = this->lowestTransID++;
    this->transID2Bundle.emplace(transID, new Bundle(t, key, ""));

    Message *primary_message = new Message(transID, this->memberNode->addr, t, key);
    Message *secondary_message = new Message(transID, this->memberNode->addr, t, key);
    Message *tertiary_message = new Message(transID, this->memberNode->addr, t, key);

    // 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 $0x2d0, %rsp            # imm = 0x2D0
movq %rsi, -0x1e0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movl 0x88(%rax), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x88(%rax)
movl %ecx, -0x18(%rbp)
addq $0x90, %rax
movq %rax, -0x1e8(%rbp)
movl $0x58, %edi
callq 0x4310
movq -0x1e0(%rbp), %rsi
movq %rax, -0x1d8(%rbp)
movb $0x1, -0x72(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1cc(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4150
jmp 0x1a928
leaq -0x71(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x4560
movq -0x1f8(%rbp), %rdx
leaq 0xc9f2(%rip), %rsi      # 0x27338
leaq -0x70(%rbp), %rdi
callq 0x10b40
jmp 0x1a951
movl -0x1cc(%rbp), %esi
movq -0x1d8(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x1e9b0
jmp 0x1a96d
movq -0x1e8(%rbp), %rdi
movq -0x1d8(%rbp), %rax
movb $0x0, -0x72(%rbp)
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0x1e960
movb %dl, -0x201(%rbp)
movq %rax, -0x200(%rbp)
jmp 0x1a99f
movb -0x201(%rbp), %al
movq -0x200(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movb %al, -0x80(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x41e0
leaq -0x71(%rbp), %rdi
callq 0x4370
leaq -0x40(%rbp), %rdi
callq 0x41e0
movl $0x78, %edi
callq 0x4310
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
movq %rcx, -0x210(%rbp)
movb $0x1, -0xb9(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, -0x208(%rbp)
movq 0x50(%rax), %rsi
addq $0x8, %rsi
leaq -0x96(%rbp), %rdi
callq 0x15070
jmp 0x1aa12
movq -0x1e0(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, -0x214(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4150
jmp 0x1aa30
movl -0x214(%rbp), %ecx
movl -0x208(%rbp), %esi
movq -0x210(%rbp), %rdi
leaq -0x96(%rbp), %rdx
leaq -0xb8(%rbp), %r8
callq 0x266b0
jmp 0x1aa58
movb $0x0, -0xb9(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x41e0
movq -0x210(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x78, %edi
callq 0x4310
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
movq %rcx, -0x220(%rbp)
movb $0x1, -0xf1(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, -0x218(%rbp)
movq 0x50(%rax), %rsi
addq $0x8, %rsi
leaq -0xce(%rbp), %rdi
callq 0x15070
jmp 0x1aaba
movq -0x1e0(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, -0x224(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x4150
jmp 0x1aad8
movl -0x224(%rbp), %ecx
movl -0x218(%rbp), %esi
movq -0x220(%rbp), %rdi
leaq -0xce(%rbp), %rdx
leaq -0xf0(%rbp), %r8
callq 0x266b0
jmp 0x1ab00
movb $0x0, -0xf1(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x41e0
movq -0x220(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl $0x78, %edi
callq 0x4310
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
movq %rcx, -0x230(%rbp)
movb $0x1, -0x129(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, -0x228(%rbp)
movq 0x50(%rax), %rsi
addq $0x8, %rsi
leaq -0x106(%rbp), %rdi
callq 0x15070
jmp 0x1ab62
movq -0x1e0(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, -0x234(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x4150
jmp 0x1ab80
movl -0x234(%rbp), %ecx
movl -0x228(%rbp), %esi
movq -0x230(%rbp), %rdi
leaq -0x106(%rbp), %rdx
leaq -0x128(%rbp), %r8
callq 0x266b0
jmp 0x1aba8
movb $0x0, -0x129(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x41e0
movq -0x230(%rbp), %rax
movq -0x1e0(%rbp), %rsi
movq %rax, -0x100(%rbp)
leaq -0x168(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x4150
movq -0x1f0(%rbp), %rsi
movq -0x240(%rbp), %rdx
leaq -0x148(%rbp), %rdi
callq 0x1b070
jmp 0x1abff
leaq -0x168(%rbp), %rdi
callq 0x41e0
movq -0x90(%rbp), %rsi
leaq -0x188(%rbp), %rdi
callq 0x26980
jmp 0x1ac20
movq -0x1f0(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x60(%rcx), %rcx
movq %rcx, -0x260(%rbp)
addq $0x8, %rax
movq %rax, -0x258(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x148(%rbp), %rdi
callq 0x13400
addq $0x8, %rax
movq %rax, -0x250(%rbp)
leaq -0x188(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x4140
movq -0x268(%rbp), %rdi
movq %rax, -0x248(%rbp)
callq 0x4220
movq -0x260(%rbp), %rdi
movq -0x258(%rbp), %rsi
movq -0x250(%rbp), %rdx
movq -0x248(%rbp), %rcx
movl %eax, %r8d
callq 0xac80
jmp 0x1aca8
movq -0xc8(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x26980
jmp 0x1acbd
movq -0x1f0(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x60(%rcx), %rcx
movq %rcx, -0x288(%rbp)
addq $0x8, %rax
movq %rax, -0x280(%rbp)
leaq -0x148(%rbp), %rdi
movl $0x1, %esi
callq 0x13400
addq $0x8, %rax
movq %rax, -0x278(%rbp)
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x4140
movq -0x290(%rbp), %rdi
movq %rax, -0x270(%rbp)
callq 0x4220
movq -0x288(%rbp), %rdi
movq -0x280(%rbp), %rsi
movq -0x278(%rbp), %rdx
movq -0x270(%rbp), %rcx
movl %eax, %r8d
callq 0xac80
jmp 0x1ad46
movq -0x100(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x26980
jmp 0x1ad5b
movq -0x1f0(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x60(%rcx), %rcx
movq %rcx, -0x2b0(%rbp)
addq $0x8, %rax
movq %rax, -0x2a8(%rbp)
leaq -0x148(%rbp), %rdi
movl $0x2, %esi
callq 0x13400
addq $0x8, %rax
movq %rax, -0x2a0(%rbp)
leaq -0x1c8(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x4140
movq -0x2b8(%rbp), %rdi
movq %rax, -0x298(%rbp)
callq 0x4220
movq -0x2b0(%rbp), %rdi
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
movq -0x298(%rbp), %rcx
movl %eax, %r8d
callq 0xac80
jmp 0x1ade4
movq -0x90(%rbp), %rax
movq %rax, -0x2c0(%rbp)
cmpq $0x0, %rax
je 0x1ae15
movq -0x2c0(%rbp), %rdi
callq 0x1ea70
movq -0x2c0(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
movq -0xc8(%rbp), %rax
movq %rax, -0x2c8(%rbp)
cmpq $0x0, %rax
je 0x1ae46
movq -0x2c8(%rbp), %rdi
callq 0x1ea70
movq -0x2c8(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
movq -0x100(%rbp), %rax
movq %rax, -0x2d0(%rbp)
cmpq $0x0, %rax
je 0x1ae77
movq -0x2d0(%rbp), %rdi
callq 0x1ea70
movq -0x2d0(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
leaq -0x1c8(%rbp), %rdi
callq 0x41e0
leaq -0x1a8(%rbp), %rdi
callq 0x41e0
leaq -0x188(%rbp), %rdi
callq 0x41e0
leaq -0x148(%rbp), %rdi
callq 0x10c60
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1aef3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1aee1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x41e0
leaq -0x71(%rbp), %rdi
callq 0x4370
leaq -0x40(%rbp), %rdi
callq 0x41e0
testb $0x1, -0x72(%rbp)
jne 0x1aefb
jmp 0x1af0c
movq -0x1d8(%rbp), %rdi
movl $0x58, %esi
callq 0x4320
jmp 0x1b066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1af37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x41e0
testb $0x1, -0xb9(%rbp)
jne 0x1af42
jmp 0x1af53
movq -0x210(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
jmp 0x1b066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1af7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x41e0
testb $0x1, -0xf1(%rbp)
jne 0x1af89
jmp 0x1af9a
movq -0x220(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
jmp 0x1b066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1afc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x41e0
testb $0x1, -0x129(%rbp)
jne 0x1afd0
jmp 0x1afe1
movq -0x230(%rbp), %rdi
movl $0x78, %esi
callq 0x4320
jmp 0x1b066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x41e0
jmp 0x1b066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1b05a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1b04e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1b042
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x41e0
leaq -0x1a8(%rbp), %rdi
callq 0x41e0
leaq -0x188(%rbp), %rdi
callq 0x41e0
leaq -0x148(%rbp), %rdi
callq 0x10c60
movq -0x48(%rbp), %rdi
callq 0x4550
nop