// File: /workspace/github_cpp_makefile_star2_O2/romkatv[P]hcproxy/src/dns.cc
// Function: hcproxy::DnsResolver::Resolve(std::basic_string_view<char, std::char_traits<char>>, std::function<void (std::shared_ptr<addrinfo const>)>)
void DnsResolver::Resolve(std::string_view host_port, Callback cb) {
  const Time now = Clock::now();
  std::unique_lock<std::mutex> lock(mutex_);
  auto it = cache_.find(host_port);
  if (it == cache_.end()) {
    CacheData c;
    c.callbacks.push_back(std::move(cb));
    it = cache_.insert({std::string(host_port), std::move(c)}).first;
    lock.unlock();
    threads_.Schedule(now, [=] { ProcessCacheEntry(it); });
    return;
  }
  CacheData& c = it->second;
  if (!c.callbacks.empty()) {
    c.callbacks.push_back(std::move(cb));
    return;
  }
  std::shared_ptr<const addrinfo> addr =
      c.successfully_resolved_at + opt_.dns_cache_ttl > now ? c.addr : nullptr;
  c.Use(now);
  lock.unlock();
  cb(std::move(addr));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rcx, %r15
movq %rdi, %rbx
leaq 0x50(%rsp), %r13
movq %rsi, (%r13)
movq %rdx, 0x8(%r13)
callq 0x2a710
movq %rax, %r14
movq %rax, 0x18(%rsp)
leaq 0x20(%rbx), %rsi
leaq 0x8(%rsp), %rdi
callq 0x1ae8c
leaq 0x48(%rbx), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x1b278
leaq 0x50(%rbx), %rcx
cmpq %rcx, %rax
je 0x1a432
leaq 0x40(%rax), %r12
movq 0x40(%rax), %rcx
cmpq 0x48(%rax), %rcx
je 0x1a506
movq %r12, %rdi
movq %r15, %rsi
callq 0x1b432
jmp 0x1a58d
xorps %xmm0, %xmm0
leaq 0xf0(%rsp), %rdi
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
andq $0x0, 0x40(%rdi)
movq %r15, %rsi
callq 0x1b432
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x7(%rsp), %rdx
callq 0x1aea2
leaq 0x80(%rsp), %r15
leaq 0x30(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
movq %r15, %rdi
callq 0x1aebc
movq %r12, %rdi
movq %r15, %rsi
callq 0x1b62a
movq %rax, %r15
leaq 0x80(%rsp), %rdi
callq 0x1aee2
leaq 0x30(%rsp), %rdi
callq 0x9b0d0
leaq 0x8(%rsp), %rdi
callq 0x1aef8
leaq 0x60(%rsp), %rdx
movq %rbx, (%rdx)
addq $0x78, %rbx
movq %r15, 0x8(%rdx)
leaq 0x94c(%rip), %rax       # 0x1ae1c
movq %rax, 0x18(%rdx)
leaq 0x951(%rip), %rax       # 0x1ae2c
movq %rax, 0x10(%rdx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1bd2c
leaq 0x60(%rsp), %rdi
callq 0x19180
leaq 0xf0(%rsp), %rdi
callq 0x1af1e
jmp 0x1a58d
movq 0x8(%rbx), %rcx
addq 0x78(%rax), %rcx
cmpq %rcx, %r14
jge 0x1a529
addq $0x58, %rax
leaq 0x80(%rsp), %rdi
movq %rax, %rsi
callq 0x1b052
jmp 0x1a534
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
leaq 0x18(%rsp), %rsi
movq %r12, %rdi
callq 0x1a61e
leaq 0x8(%rsp), %rdi
callq 0x1aef8
leaq 0x28(%rsp), %r14
movaps 0x80(%rsp), %xmm0
movaps %xmm0, -0x8(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x1af34
leaq 0x88(%rsp), %rbx
movq %r14, %rdi
callq 0x1b086
movq %rbx, %rdi
callq 0x1b086
leaq 0x8(%rsp), %rdi
callq 0x1af48
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %r14, %rdi
callq 0x1b086
jmp 0x1a5b8
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x1b086
jmp 0x1a60b
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x19180
jmp 0x1a5f9
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x1aee2
leaq 0x30(%rsp), %rdi
callq 0x9b0d0
jmp 0x1a5f9
jmp 0x1a5f6
jmp 0x1a608
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x1af1e
jmp 0x1a60b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1af48
movq %rbx, %rdi
callq 0xcc660
nop