// File: yasz24[P]eau2/src/network/./../application/../store/kvstore.h
// Function: KVStore::waitAndget(Key*)
Value* waitAndget(Key* key) {
        store_mtx_.lock();
        size_t node = key->node();
        Value* val = nullptr;
        if (node == this->this_node_) {
            std::cout << "waitAndget: trying to find key: " << key->serialize() << "\n"; 
            std::map<Key*, Value*, KeyCompare>::iterator iter;
            iter = local_store_.find(key);
            if (iter != local_store_.end()) {
                std::cout << "waitAndget: found key: " << key->serialize() << "\n"; 
                val = iter->second;
            } else {
                wait_for_key_ = key;
                store_mtx_.wait();
                iter = local_store_.find(key);
                val = iter->second;
                wait_for_key_ = nullptr;
            }
        } else {
            WaitAndGet get(key, this_node_, node, network_->msg_id);
            network_->send_msg(&get); // send get msg over the network to appropriate KVStore.
            store_mtx_.wait();
            Message* m = received_msg;
            //std::cout << "wait and get reply received\n";
            //expect Reply. 
            if (m->kind_ == MsgKind::Reply) {
                Reply* resp = dynamic_cast<Reply*>(m);
                char* serializedValue = resp->reply_msg_;
                val = new Value(serializedValue, this);
            } 
            received_msg = nullptr;
        }
        store_mtx_.unlock();
        return val;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
addq $0x58, %rdi
callq 0x11df0
movq -0x10(%rbp), %rdi
callq 0x11e10
movq -0xa8(%rbp), %rcx
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq 0x18(%rcx), %rax
jne 0x1ecae
movq 0x1d458(%rip), %rdi     # 0x3bfc0
leaq 0xde22(%rip), %rsi      # 0x2c991
callq 0x8280
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x8280
movq %rax, %rdi
leaq 0xd58f(%rip), %rsi      # 0x2c12d
callq 0x8280
leaq -0x28(%rbp), %rdi
callq 0x11e30
movq -0xa8(%rbp), %rdi
addq $0x20, %rdi
leaq -0x10(%rbp), %rsi
callq 0x11e50
movq -0xa8(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
addq $0x20, %rdi
callq 0x11eb0
movq %rax, -0x38(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x11e80
testb $0x1, %al
jne 0x1ebf3
jmp 0x1ec48
movq 0x1d3c6(%rip), %rdi     # 0x3bfc0
leaq 0xddb1(%rip), %rsi      # 0x2c9b2
callq 0x8280
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0x8280
movq %rax, %rdi
leaq 0xd4fd(%rip), %rsi      # 0x2c12d
callq 0x8280
leaq -0x28(%rbp), %rdi
callq 0x11ee0
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x1eca9
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, 0x100(%rdi)
addq $0x58, %rdi
callq 0x11f70
movq -0xa8(%rbp), %rdi
addq $0x20, %rdi
leaq -0x10(%rbp), %rsi
callq 0x11e50
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x11ee0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq 0x8(%rcx), %rcx
movq %rcx, -0x20(%rbp)
movq $0x0, 0x100(%rax)
jmp 0x1ee29
movq -0xa8(%rbp), %rax
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rcx
movq 0x18(%rax), %rdx
movq 0x50(%rax), %rax
movq 0x40(%rax), %r8
leaq -0x78(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x1e680
movq -0xa8(%rbp), %rax
movq -0xc0(%rbp), %rsi
movq 0x50(%rax), %rdi
movq (%rdi), %rax
movq 0x50(%rax), %rax
callq *%rax
jmp 0x1ecf6
movq -0xa8(%rbp), %rdi
addq $0x58, %rdi
callq 0x11f70
jmp 0x1ed08
movq -0xa8(%rbp), %rax
movq 0xd0(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jne 0x1ee01
movq -0x90(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, %rax
je 0x1ed7d
movq -0xc8(%rbp), %rdi
leaq 0x1b478(%rip), %rsi     # 0x3a1c8
leaq 0x1bf51(%rip), %rdx     # 0x3aca8
xorl %eax, %eax
movl %eax, %ecx
callq 0x82f0
movq %rax, -0xd0(%rbp)
jmp 0x1ed88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x1ee1e
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
jmp 0x1ed88
movq -0xd0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0xa0(%rbp)
movl $0x20, %edi
callq 0x8290
movq %rax, -0xd8(%rbp)
jmp 0x1edbb
movq -0xa8(%rbp), %rdx
movq -0xd8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x11fa0
jmp 0x1edd7
movq -0xd8(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x1ee01
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x8260
jmp 0x1ee1e
movq -0xa8(%rbp), %rax
movq $0x0, 0xd0(%rax)
leaq -0x78(%rbp), %rdi
callq 0x1e770
jmp 0x1ee29
leaq -0x78(%rbp), %rdi
callq 0x1e770
jmp 0x1ee46
movq -0xa8(%rbp), %rdi
addq $0x58, %rdi
callq 0x121e0
movq -0x20(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x8400
nop