// File: romkatv[P]hcproxy/src/dns.cc
// Function: hcproxy::DnsResolver::ProcessCacheEntry(std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, hcproxy::DnsResolver::CacheData>>)
void DnsResolver::ProcessCacheEntry(Cache::iterator it) {
  CacheData& c = it->second;
  Time now = Clock::now();
  std::unique_lock<std::mutex> lock(mutex_);
  if (c.callbacks.empty() && c.used_at + opt_.dns_cache_refresh_duration <= now) {
    cache_.erase(it);
    return;
  }
  if (c.resolved_at + opt_.dns_cache_refresh_period <= now) {
    lock.unlock();
    std::shared_ptr<const addrinfo> addr = ResolveSync(it->first);
    now = Clock::now();
    lock.lock();
    c.resolved_at = now;
    if (addr) {
      c.addr = addr;
      c.successfully_resolved_at = now;
      for (int64_t i = 0; c.use_count; ++i) {
        --c.use_count;
        Advance(c.addr);
        if (c.addr == addr) c.use_count %= i + 1;
      }
    }
  }
  if (!c.callbacks.empty()) {
    std::vector<Callback> callbacks = std::exchange(c.callbacks, {});
    std::shared_ptr<const addrinfo> addr = c.addr;
    for (size_t i = 0; i != callbacks.size(); ++i) c.Use(now);
    lock.unlock();
    for (const auto& f : callbacks) f(Advance(addr));
    lock.lock();
  }
  Time next = std::min(c.resolved_at + opt_.dns_cache_refresh_period,
                       c.used_at + opt_.dns_cache_refresh_duration);
  lock.unlock();
  threads_.Schedule(next, [=] { ProcessCacheEntry(it); });
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rsi, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x21760
addq $0x20, %rax
movq %rax, -0x18(%rbp)
callq 0x3ef20
movq -0x178(%rbp), %rsi
movq %rax, -0x20(%rbp)
addq $0x20, %rsi
leaq -0x30(%rbp), %rdi
callq 0x21420
movq -0x18(%rbp), %rdi
callq 0x21780
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x169(%rbp)
jne 0x1f756
jmp 0x1f7a5
movq -0x178(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
addq $0x18, %rsi
callq 0x217f0
movq %rax, -0x180(%rbp)
jmp 0x1f777
movq -0x180(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x21960
movb %al, -0x181(%rbp)
jmp 0x1f797
movb -0x181(%rbp), %al
movb %al, -0x169(%rbp)
jmp 0x1f7a5
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x1f7b1
jmp 0x1f7fe
movq -0x178(%rbp), %rdi
addq $0x48, %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
callq 0x21990
movq %rax, -0x190(%rbp)
jmp 0x1f7d6
movq -0x190(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0x1fcc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1fcf1
movq -0x178(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
addq $0x10, %rsi
callq 0x217f0
movq %rax, -0x198(%rbp)
jmp 0x1f81f
movq -0x198(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x21960
movb %al, -0x199(%rbp)
jmp 0x1f83f
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0x1f84e
jmp 0x1f993
leaq -0x30(%rbp), %rdi
callq 0x216e0
jmp 0x1f859
leaq -0x8(%rbp), %rdi
callq 0x21760
movq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x1fd10
jmp 0x1f870
callq 0x3ef20
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x219d0
jmp 0x1f88c
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x30(%rax)
leaq -0x78(%rbp), %rdi
callq 0x21a30
testb $0x1, %al
jne 0x1f8aa
jmp 0x1f98a
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
leaq -0x78(%rbp), %rsi
callq 0x21a50
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq $0x0, -0x88(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x1f988
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
decq %rcx
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
leaq -0x98(%rbp), %rdi
callq 0x202d0
jmp 0x1f906
leaq -0x98(%rbp), %rdi
callq 0x21900
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
leaq -0x78(%rbp), %rsi
callq 0x21a80
testb $0x1, %al
jne 0x1f929
jmp 0x1f96f
movq -0x88(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq 0x40(%rax), %rax
cqto
idivq %rcx
movq -0x1a8(%rbp), %rax
movq %rdx, 0x40(%rax)
jmp 0x1f96f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x21900
jmp 0x1fcf1
jmp 0x1f971
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1f8d2
jmp 0x1f98a
leaq -0x78(%rbp), %rdi
callq 0x21900
movq -0x18(%rbp), %rdi
callq 0x21780
testb $0x1, %al
jne 0x1fbb3
movq -0x18(%rbp), %rax
movq %rax, -0x1b8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
movq $0x0, -0xc0(%rbp)
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x21b00
movq -0x1b8(%rbp), %rsi
movq -0x1b0(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x21ac0
jmp 0x1f9f3
leaq -0xd0(%rbp), %rdi
callq 0x21b20
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x21840
movq $0x0, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x21b80
movq %rax, %rcx
movq -0x1c0(%rbp), %rax
cmpq %rcx, %rax
je 0x1fa9a
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1f690
jmp 0x1fa56
jmp 0x1fa58
movq -0xe8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe8(%rbp)
jmp 0x1fa1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x21b20
jmp 0x1fcf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1fb96
leaq -0x30(%rbp), %rdi
callq 0x216e0
jmp 0x1faa5
leaq -0xb0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x21ba0
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x21bd0
movq %rax, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x21c00
testb $0x1, %al
jne 0x1faf2
jmp 0x1fb71
leaq -0xf8(%rbp), %rdi
callq 0x21c40
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x202d0
jmp 0x1fb28
movq -0x1c8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x21890
jmp 0x1fb3d
leaq -0x118(%rbp), %rdi
callq 0x21900
leaq -0xf8(%rbp), %rdi
callq 0x21c60
jmp 0x1fad9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x21900
jmp 0x1fb96
leaq -0x30(%rbp), %rdi
callq 0x219d0
jmp 0x1fb7c
leaq -0xe0(%rbp), %rdi
callq 0x21900
leaq -0xb0(%rbp), %rdi
callq 0x21b20
jmp 0x1fbb3
leaq -0xe0(%rbp), %rdi
callq 0x21900
leaq -0xb0(%rbp), %rdi
callq 0x21b20
jmp 0x1fcf1
movq -0x178(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
addq $0x10, %rsi
callq 0x217f0
movq %rax, -0x1d0(%rbp)
jmp 0x1fbd4
movq -0x178(%rbp), %rsi
movq -0x1d0(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
addq $0x18, %rsi
callq 0x217f0
movq %rax, -0x1d8(%rbp)
jmp 0x1fc03
movq -0x1d8(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x21c80
movq %rax, -0x1e0(%rbp)
jmp 0x1fc2d
movq -0x1e0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x120(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x216e0
jmp 0x1fc49
movq -0x178(%rbp), %rax
movq %rax, %rcx
addq $0x78, %rcx
movq %rcx, -0x1f0(%rbp)
movq -0x120(%rbp), %rcx
movq %rcx, -0x138(%rbp)
movq %rax, -0x168(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq -0x168(%rbp), %rsi
callq 0x20380
movq -0x1f0(%rbp), %rdi
movq -0x1e8(%rbp), %rdx
movq -0x138(%rbp), %rsi
callq 0x25380
jmp 0x1fcb4
leaq -0x158(%rbp), %rdi
callq 0x1af20
movl $0x0, -0x5c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x21920
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x1af20
leaq -0x30(%rbp), %rdi
callq 0x21920
movq -0x40(%rbp), %rdi
callq 0xe1080
nopw %cs:(%rax,%rax)