// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, -0x30(%rbp)
leaq 0x58(%rdi), %r15
leaq 0x68(%rdi), %rbx
movq %rbx, %rdi
callq 0xbc5c
movq 0x18(%r12), %rax
movq 0x18(%r14), %rcx
cmpq %rcx, %rax
jne 0x124eb
movq 0x12b6c(%rip), %rdi     # 0x24fc0
leaq 0x64b1(%rip), %rsi      # 0x1890c
callq 0x7240
movq %rax, %r13
movq (%r12), %rax
movq %r12, %rdi
callq *0x38(%rax)
movq %r13, %rdi
movq %rax, %rsi
callq 0x7240
leaq 0x5c6a(%rip), %rsi      # 0x180e9
movq %rax, %rdi
callq 0x7240
leaq 0x20(%r14), %r13
leaq -0x30(%rbp), %rsi
movq %r13, %rdi
callq 0xbc72
movq %rax, %r12
leaq 0x28(%r14), %rax
cmpq %rax, %r12
je 0x12579
movq 0x12b12(%rip), %rdi     # 0x24fc0
leaq 0x6478(%rip), %rsi      # 0x1892d
callq 0x7240
movq %rax, %r14
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x7240
leaq 0x5c10(%rip), %rsi      # 0x180e9
movq %rax, %rdi
callq 0x7240
movq 0x28(%r12), %r15
jmp 0x125a7
movq 0x50(%r14), %rdi
movq 0x40(%rdi), %rdx
leaq -0x68(%rbp), %rsi
andq $0x0, 0x8(%rsi)
leaq 0x125cd(%rip), %r8      # 0x24ad0
movq %r8, (%rsi)
movl $0x5, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %rax, 0x20(%rsi)
movq %rdx, 0x28(%rsi)
movq %r12, 0x30(%rsi)
movq (%rdi), %rax
callq *0x50(%rax)
movq %r15, %rdi
callq 0xbb4a
movq 0xd0(%r14), %rdi
cmpl $0x3, 0x10(%rdi)
jne 0x1256c
leaq 0x10db1(%rip), %rsi     # 0x232f0
leaq 0x1171a(%rip), %rdx     # 0x23c60
xorl %ecx, %ecx
callq 0x72a0
movq 0x30(%rax), %r12
pushq $0x20
popq %rdi
callq 0x7250
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xbb60
jmp 0x1256f
xorl %r15d, %r15d
andq $0x0, 0xd0(%r14)
jmp 0x125a7
leaq -0x30(%rbp), %r12
movq (%r12), %rax
movq %rax, 0x100(%r14)
movq %r15, %rdi
callq 0xbb4a
movq %r13, %rdi
movq %r12, %rsi
callq 0xbc72
movq 0x28(%rax), %r15
andq $0x0, 0x100(%r14)
movq %rbx, %rdi
callq 0x71a0
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
callq 0x7220
movq %rbx, %rdi
callq 0x7390