// File: 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 %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rcx, -0x1d8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1d0(%rbp)
callq 0x3ef20
movq -0x1d0(%rbp), %rsi
movq %rax, -0x28(%rbp)
addq $0x20, %rsi
leaq -0x38(%rbp), %rdi
callq 0x21420
movq -0x1d0(%rbp), %rdi
addq $0x48, %rdi
leaq -0x10(%rbp), %rsi
callq 0x21460
movq %rax, -0x1c8(%rbp)
jmp 0x1f207
movq -0x1d0(%rbp), %rdi
movq -0x1c8(%rbp), %rax
movq %rax, -0x40(%rbp)
addq $0x48, %rdi
callq 0x214c0
movq %rax, -0x58(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x21490
testb $0x1, %al
jne 0x1f23c
jmp 0x1f46e
leaq -0xa0(%rbp), %rdi
callq 0x214f0
jmp 0x1f24a
movq -0x1d8(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x21590
jmp 0x1f25f
movq -0x1d0(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x1e8(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x36a60
movq -0x1e0(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x21600
jmp 0x1f29d
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x21670
jmp 0x1f2b9
movq -0x1e8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x215c0
movb %dl, -0x1f1(%rbp)
movq %rax, -0x1f0(%rbp)
jmp 0x1f2db
movb -0x1f1(%rbp), %al
movq -0x1f0(%rbp), %rcx
movq %rcx, -0x150(%rbp)
movb %al, -0x148(%rbp)
movb -0x148(%rbp), %al
movb %al, -0xa8(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x216b0
leaq -0x138(%rbp), %rdi
callq 0xaf8e0
leaq -0x139(%rbp), %rdi
callq 0x36a80
leaq -0x38(%rbp), %rdi
callq 0x216e0
jmp 0x1f349
movq -0x1d0(%rbp), %rax
movq %rax, %rcx
addq $0x78, %rcx
movq %rcx, -0x208(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, -0x158(%rbp)
movq %rax, -0x188(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x178(%rbp), %rdi
movq %rdi, -0x200(%rbp)
leaq -0x188(%rbp), %rsi
callq 0x1f600
movq -0x208(%rbp), %rdi
movq -0x200(%rbp), %rdx
movq -0x158(%rbp), %rsi
callq 0x25380
jmp 0x1f3b1
leaq -0x178(%rbp), %rdi
callq 0x1af20
movl $0x1, -0x18c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x21730
jmp 0x1f5a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1f5e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1f45d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1f437
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1f42b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x216b0
leaq -0x138(%rbp), %rdi
callq 0xaf8e0
leaq -0x139(%rbp), %rdi
callq 0x36a80
jmp 0x1f45d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x1af20
leaq -0xa0(%rbp), %rdi
callq 0x21730
jmp 0x1f5e7
leaq -0x40(%rbp), %rdi
callq 0x21760
addq $0x20, %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rdi
callq 0x21780
testb $0x1, %al
jne 0x1f4b6
movq -0x1d8(%rbp), %rsi
movq -0x198(%rbp), %rdi
callq 0x21590
jmp 0x1f4a7
movl $0x1, -0x18c(%rbp)
jmp 0x1f5a3
movq -0x1d0(%rbp), %rsi
movq -0x198(%rbp), %rdi
addq $0x38, %rdi
addq $0x8, %rsi
callq 0x217f0
movq %rax, -0x210(%rbp)
jmp 0x1f4da
movq -0x210(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x217c0
movb %al, -0x211(%rbp)
jmp 0x1f500
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x1f50c
jmp 0x1f525
movq -0x198(%rbp), %rsi
addq $0x18, %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x21840
jmp 0x1f535
leaq -0x1a8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x21870
movq -0x198(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1f690
jmp 0x1f547
leaq -0x38(%rbp), %rdi
callq 0x216e0
jmp 0x1f552
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x220(%rbp)
leaq -0x1a8(%rbp), %rsi
callq 0x218d0
movq -0x1d8(%rbp), %rdi
movq -0x220(%rbp), %rsi
callq 0x21890
jmp 0x1f581
leaq -0x1c0(%rbp), %rdi
callq 0x21900
leaq -0x1a8(%rbp), %rdi
callq 0x21900
movl $0x0, -0x18c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x21920
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1f5db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x21900
leaq -0x1a8(%rbp), %rdi
callq 0x21900
leaq -0x38(%rbp), %rdi
callq 0x21920
movq -0x48(%rbp), %rdi
callq 0xe1080
nopl (%rax)