// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rsi, %r14
movq %rdi, %rbp
callq 0x2a710
movq %rax, %r15
movq %rax, 0x38(%rsp)
leaq 0x20(%rbp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x1ae8c
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
cmpq %rcx, %rax
jne 0x1a6b2
movq 0x18(%rbp), %rdx
addq 0x68(%r14), %rdx
cmpq %rdx, %r15
jge 0x1a7db
movq 0x10(%rbp), %rdx
addq 0x70(%r14), %rdx
cmpq %rdx, %r15
movq %rbp, 0x18(%rsp)
jl 0x1aa61
leaq 0x20(%rsp), %rdi
callq 0x1aef8
leaq 0x20(%r14), %r15
movq (%r15), %r13
pushq $0x3a
popq %rsi
movq %r13, %rdi
callq 0x155c0
testq %rax, %rax
je 0x1a7ef
movq %rax, %r12
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1b102
incq %r12
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdx
movups %xmm0, 0x8(%rdx)
movups %xmm0, 0x18(%rdx)
andq $0x0, 0x28(%rdx)
movl $0x1, 0x8(%rdx)
movabsq $0x200000400, %rax      # imm = 0x200000400
movq %rax, (%rdx)
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rcx
movq %r12, %rsi
callq 0x151e0
movl %eax, %ebp
testl %eax, %eax
je 0x1a846
leaq 0xb4fe7(%rip), %rsi     # 0xcf742
leaq 0x120(%rsp), %rdi
pushq $0x3f
popq %rdx
pushq $0x1
popq %rcx
callq 0x1f4c8
movq 0x138(%rsp), %rdi
leaq 0xb4fe6(%rip), %rsi     # 0xcf763
callq 0x8b1d0
movq 0x138(%rsp), %rdi
movq %r15, %rsi
callq 0x9db00
movq 0x138(%rsp), %rdi
leaq 0xb4fd2(%rip), %rsi     # 0xcf773
callq 0x8b1d0
movl %ebp, %edi
callq 0x15860
movq 0x138(%rsp), %rdi
movq %rax, %rsi
callq 0x8b1d0
leaq 0x120(%rsp), %rdi
callq 0x193e6
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq 0x18(%rsp), %rbp
jmp 0x1a9b2
addq $0x48, %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1b856
jmp 0x1abcc
leaq 0xb4f4c(%rip), %rsi     # 0xcf742
leaq 0x120(%rsp), %rdi
pushq $0x33
popq %rdx
pushq $0x1
popq %rcx
callq 0x1f4c8
movq 0x138(%rsp), %rdi
leaq 0xb4f35(%rip), %rsi     # 0xcf74d
callq 0x8b1d0
movq 0x138(%rsp), %rdi
movq %r15, %rsi
callq 0x9db00
leaq 0x120(%rsp), %rdi
callq 0x193e6
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
jmp 0x1a9bc
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
cmpw $0x2, (%rax)
jne 0x1abe8
leaq 0xb4ee2(%rip), %rsi     # 0xcf742
leaq 0x40(%rsp), %rdi
pushq $0x43
popq %rdx
xorl %ecx, %ecx
callq 0x1f4c8
movq 0x58(%rsp), %rdi
leaq 0xb4efc(%rip), %rsi     # 0xcf777
callq 0x8b1d0
movq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x9db00
movq 0x58(%rsp), %rdi
leaq 0xb4ee8(%rip), %rsi     # 0xcf781
callq 0x8b1d0
movq 0x30(%rsp), %rbx
leaq 0x120(%rsp), %rdi
callq 0x933f0
leaq 0xf8(%rsp), %r15
leaq 0x120(%rsp), %r12
leaq 0xb4ee9(%rip), %r13     # 0xcf7b0
movq %rbx, %rbp
testq %rbp, %rbp
je 0x1a8fb
cmpq %rbx, %rbp
je 0x1a8df
movq %r12, %rdi
movq %r13, %rsi
callq 0x8b1d0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1b9b0
movq %r12, %rdi
movq %r15, %rsi
callq 0x1ba1d
movq 0x28(%rbp), %rbp
jmp 0x1a8ca
leaq 0x128(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x90de0
leaq 0x120(%rsp), %rdi
callq 0x8fcf0
movq 0x58(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x9db00
movq 0x18(%rsp), %rbp
leaq 0xd8(%rsp), %rdi
callq 0x9b0d0
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x19502
movq 0x30(%rsp), %r15
movq %r15, %rax
movq %rax, %rbx
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x1a956
movq %r15, 0x28(%rbx)
movq %r15, (%rsp)
andq $0x0, 0x8(%rsp)
pushq $0x20
popq %rdi
callq 0x21400
leaq 0x120(%rsp), %rdi
movq %r12, (%rdi)
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0xf0c90(%rip), %rcx     # 0x10b628
movq %rcx, (%rax)
movq %rbx, 0x10(%rax)
movq %r15, 0x18(%rax)
movq %rax, 0x8(%rsp)
andq $0x0, 0x8(%rdi)
callq 0x1ad9e
leaq 0x60(%rsp), %rdi
callq 0x9b0d0
callq 0x2a710
movq %rax, %r12
movq %rax, 0x38(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x1af5e
movq %r12, 0x70(%r14)
cmpq $0x0, (%rsp)
je 0x1aa4f
leaq 0x58(%r14), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x1b1c2
movq %r12, 0x78(%r14)
pushq $0x1
popq %rbx
leaq 0xd0(%rsp), %r12
leaq 0xc8(%rsp), %r13
movq 0x80(%r14), %rax
testq %rax, %rax
je 0x1aa4f
decq %rax
movq %rax, 0x80(%r14)
movq %r13, %rdi
movq %r15, %rsi
callq 0x1ad47
movq %r12, %rdi
callq 0x1b086
movq 0x58(%r14), %rax
cmpq (%rsp), %rax
jne 0x1aa4a
movq 0x80(%r14), %rax
cqto
idivq %rbx
movq %rdx, 0x80(%r14)
incq %rbx
jmp 0x1aa04
leaq 0x8(%rsp), %rdi
callq 0x1b086
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
cmpq %rcx, %rax
je 0x1ab64
leaq 0x40(%r14), %r15
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %r12
movaps %xmm0, (%r12)
andq $0x0, 0x10(%r12)
leaq 0x120(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1b8b7
movq %r12, %rdi
callq 0x1af88
leaq 0x58(%r14), %rsi
leaq 0x80(%rsp), %rdi
callq 0x1b052
xorl %ebx, %ebx
leaq 0x38(%rsp), %r12
movq 0x128(%rsp), %rax
subq 0x120(%rsp), %rax
sarq $0x5, %rax
cmpq %rax, %rbx
je 0x1aae0
movq %r15, %rdi
movq %r12, %rsi
callq 0x1a61e
incq %rbx
jmp 0x1aab7
leaq 0x20(%rsp), %rdi
callq 0x1aef8
movq 0x120(%rsp), %r12
movq 0x128(%rsp), %rbx
leaq 0xc0(%rsp), %r15
leaq 0xb8(%rsp), %r13
leaq 0x80(%rsp), %rbp
cmpq %rbx, %r12
je 0x1ab3b
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1ad47
movq %r12, %rdi
movq %r13, %rsi
callq 0x1af34
movq %r15, %rdi
callq 0x1b086
addq $0x20, %r12
jmp 0x1ab12
leaq 0x20(%rsp), %rdi
callq 0x1af5e
leaq 0x88(%rsp), %rdi
callq 0x1b086
leaq 0x120(%rsp), %rdi
callq 0x1af88
movq 0x18(%rsp), %rbp
movq 0x68(%r14), %r13
movq 0x70(%r14), %r12
movq 0x10(%rbp), %r15
movq 0x18(%rbp), %rbx
leaq 0x20(%rsp), %rdi
callq 0x1aef8
addq %r13, %rbx
addq %r12, %r15
cmpq %r15, %rbx
cmovlq %rbx, %r15
leaq 0x100(%rsp), %rdx
movq %rbp, (%rdx)
addq $0x78, %rbp
movq %r14, 0x8(%rdx)
leaq 0x2af(%rip), %rax       # 0x1ae54
movq %rax, 0x18(%rdx)
leaq 0x2b4(%rip), %rax       # 0x1ae64
movq %rax, 0x10(%rdx)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1bd2c
leaq 0x100(%rsp), %rdi
callq 0x19180
leaq 0x20(%rsp), %rdi
callq 0x1af48
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb4b53(%rip), %rsi     # 0xcf742
leaq 0x120(%rsp), %rdi
pushq $0x42
popq %rdx
pushq $0x3
popq %rcx
callq 0x1f4c8
movq 0x138(%rsp), %rdi
leaq 0xb48ca(%rip), %rsi     # 0xcf4db
callq 0x8b1d0
movq 0x138(%rsp), %rdi
leaq 0xb96a6(%rip), %rsi     # 0xd42cb
callq 0x8b1d0
jmp 0x1ac2c
leaq 0x120(%rsp), %rdi
callq 0x189a6
jmp 0x1ac88
movq %rax, %rdi
callq 0x20490
andq $0x0, 0x28(%rbx)
movq %r15, %rdi
callq 0x15380
callq 0x212a0
movq %rax, %rbx
callq 0x20500
jmp 0x1ad04
movq %rax, %rdi
callq 0x189b9
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x9b0d0
jmp 0x1acfa
jmp 0x1acea
jmp 0x1ac8f
jmp 0x1ac88
jmp 0x1acde
jmp 0x1acb8
jmp 0x1ac88
movq %rax, %rbx
jmp 0x1ad04
jmp 0x1acde
movq %rax, %rbx
jmp 0x1acfa
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x193e6
jmp 0x1ad35
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1b086
jmp 0x1ad35
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x193e6
jmp 0x1ad04
jmp 0x1acde
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x19180
jmp 0x1ad35
movq %rax, %rbx
jmp 0x1ad35
movq %rax, %rbx
jmp 0x1ad1b
jmp 0x1acea
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x8fcf0
leaq 0x40(%rsp), %rdi
callq 0x19502
leaq 0x60(%rsp), %rdi
callq 0x9b0d0
jmp 0x1ad35
movq %rax, %rbx
movq %r15, %rdi
callq 0x1b086
leaq 0x88(%rsp), %rdi
callq 0x1b086
leaq 0x120(%rsp), %rdi
callq 0x1af88
leaq 0x20(%rsp), %rdi
callq 0x1af48
movq %rbx, %rdi
callq 0xcc660