// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %r14
movq %rsi, -0x28(%rbp)
leaq 0x68(%rdi), %rbx
movq %rbx, %rdi
callq 0x7330
testl %eax, %eax
jne 0x1413f
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movq 0x18(%r14), %rdx
cmpq %rdx, %rcx
jne 0x13f85
movq 0x16094(%rip), %r15     # 0x29fd0
leaq 0x99c4(%rip), %rsi      # 0x1d907
movl $0x20, %edx
movq %r15, %rdi
callq 0x7290
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
testq %rax, %rax
je 0x14025
movq %rax, %r12
movq %rax, %rdi
callq 0x7100
movq 0x1605b(%rip), %rdi     # 0x29fd0
movq %r12, %rsi
movq %rax, %rdx
callq 0x7290
jmp 0x1403d
movq 0x50(%r14), %rdi
movq 0x40(%rdi), %r8
leaq -0x60(%rbp), %rsi
movq $0x0, 0x8(%rsi)
leaq 0x15b48(%rip), %r9      # 0x29ae8
movq %r9, (%rsi)
movl $0x5, 0x10(%rsi)
movq %rdx, 0x18(%rsi)
movq %rcx, 0x20(%rsi)
movq %r8, 0x28(%rsi)
movq %rax, 0x30(%rsi)
movq (%rdi), %rax
callq *0x50(%rax)
leaq 0x90(%r14), %rdi
movq %rbx, %rsi
callq 0xc810
movq 0xd0(%r14), %rdi
cmpl $0x3, 0x10(%rdi)
jne 0x14012
leaq 0x142fd(%rip), %rsi     # 0x282e0
leaq 0x14c8e(%rip), %rdx     # 0x28c78
xorl %ecx, %ecx
callq 0x7280
movq 0x30(%rax), %r12
movl $0x20, %edi
callq 0x7230
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xc4c8
jmp 0x14015
xorl %r15d, %r15d
movq $0x0, 0xd0(%r14)
jmp 0x14127
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x7380
movq 0x15f8c(%rip), %rdi     # 0x29fd0
leaq 0x909e(%rip), %rsi      # 0x1d0e9
movl $0x1, %edx
callq 0x7290
leaq 0x20(%r14), %r12
leaq -0x28(%rbp), %rsi
movq %r12, %rdi
callq 0xc634
movq %rax, %r15
leaq 0x28(%r14), %rax
cmpq %rax, %r15
je 0x140ba
movq 0x15f58(%rip), %r14     # 0x29fd0
leaq 0x98a9(%rip), %rsi      # 0x1d928
movl $0x17, %edx
movq %r14, %rdi
callq 0x7290
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
testq %rax, %rax
je 0x140f3
movq %rax, %r12
movq %rax, %rdi
callq 0x7100
movq 0x15f23(%rip), %rdi     # 0x29fd0
movq %r12, %rsi
movq %rax, %rdx
callq 0x7290
jmp 0x1410b
leaq -0x28(%rbp), %r15
movq (%r15), %rax
movq %rax, 0x100(%r14)
leaq 0x90(%r14), %rdi
movq %rbx, %rsi
callq 0xc810
movq %r12, %rdi
movq %r15, %rsi
callq 0xc634
movq 0x28(%rax), %r15
movq $0x0, 0x100(%r14)
jmp 0x14127
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x7380
movq 0x15ebe(%rip), %rdi     # 0x29fd0
leaq 0x8fd0(%rip), %rsi      # 0x1d0e9
movl $0x1, %edx
callq 0x7290
movq 0x28(%r15), %r15
movq %rbx, %rdi
callq 0x7180
movq %r15, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x7160
movq %rax, %rbx
movq %r15, %rdi
callq 0x7200
movq %rbx, %rdi
callq 0x73b0
nop