// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, %r15
movq %rdi, %r14
movq %rsi, -0x28(%rbp)
leaq 0x68(%rdi), %rbx
movq %rbx, %rdi
callq 0x7330
testl %eax, %eax
jne 0x13cfa
movq 0x18(%r15), %rax
movq 0x18(%r14), %rcx
cmpq %rcx, %rax
jne 0x13b3f
movq 0x154d9(%rip), %r12     # 0x28fd0
leaq 0x9e09(%rip), %rsi      # 0x1d907
movl $0x20, %edx
movq %r12, %rdi
callq 0x7290
movq (%r15), %rax
movq %r15, %rdi
callq *0x38(%rax)
testq %rax, %rax
je 0x13bdf
movq %rax, %r15
movq %rax, %rdi
callq 0x7100
movq 0x154a1(%rip), %rdi     # 0x28fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x7290
jmp 0x13bf8
movq 0x50(%r14), %rdi
movq 0x40(%rdi), %rdx
leaq -0x60(%rbp), %rsi
movq $0x0, 0x8(%rsi)
leaq 0x14f8e(%rip), %r8      # 0x28ae8
movq %r8, (%rsi)
movl $0x5, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %rax, 0x20(%rsi)
movq %rdx, 0x28(%rsi)
movq %r15, 0x30(%rsi)
movq (%rdi), %rax
callq *0x50(%rax)
leaq 0x90(%r14), %rdi
movq %rbx, %rsi
callq 0xc64c
movq 0xd0(%r14), %rdi
cmpl $0x3, 0x10(%rdi)
jne 0x13bcc
leaq 0x1377b(%rip), %rsi     # 0x27318
leaq 0x140d4(%rip), %rdx     # 0x27c78
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 0xc306
jmp 0x13bcf
xorl %r15d, %r15d
movq $0x0, 0xd0(%r14)
jmp 0x13ce2
movq (%r12), %rax
movq -0x18(%rax), %rax
leaq (%r12,%rax), %rdi
movl 0x20(%r12,%rax), %esi
orl $0x1, %esi
callq 0x7380
movq 0x153d1(%rip), %rdi     # 0x28fd0
leaq 0x94e3(%rip), %rsi      # 0x1d0e9
movl $0x1, %edx
callq 0x7290
leaq 0x20(%r14), %r12
leaq -0x28(%rbp), %rsi
movq %r12, %rdi
callq 0xc470
movq %rax, %r15
leaq 0x28(%r14), %rax
cmpq %rax, %r15
je 0x13c75
movq 0x1539d(%rip), %r14     # 0x28fd0
leaq 0x9cee(%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 0x13cae
movq %rax, %r12
movq %rax, %rdi
callq 0x7100
movq 0x15368(%rip), %rdi     # 0x28fd0
movq %r12, %rsi
movq %rax, %rdx
callq 0x7290
jmp 0x13cc6
leaq -0x28(%rbp), %r15
movq (%r15), %rax
movq %rax, 0x100(%r14)
leaq 0x90(%r14), %rdi
movq %rbx, %rsi
callq 0xc64c
movq %r12, %rdi
movq %r15, %rsi
callq 0xc470
movq 0x28(%rax), %r15
movq $0x0, 0x100(%r14)
jmp 0x13ce2
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x7380
movq 0x15303(%rip), %rdi     # 0x28fd0
leaq 0x9415(%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