// File: /workspace/github_cpp_makefile_star2_O1/tenup-coin[P]seeder/main.cpp
// Function: GetIPList
int GetIPList(void *data, char *requestedHostname, addr_t* addr, int max, int ipv4, int ipv6) {
  CDnsThread *thread = (CDnsThread*)data;

  uint64_t requestedFlags = 0;
  int hostlen = strlen(requestedHostname);
  if (hostlen > 1 && requestedHostname[0] == 'x' && requestedHostname[1] != '0') {
    char *pEnd;
    uint64_t flags = (uint64_t)strtoull(requestedHostname+1, &pEnd, 16);
    if (*pEnd == '.' && pEnd <= requestedHostname+17 && std::find(thread->filterWhitelist.begin(), thread->filterWhitelist.end(), flags) != thread->filterWhitelist.end())
      requestedFlags = flags;
    else
      return 0;
  }
  else if (strcasecmp(requestedHostname, thread->dns_opt.host))
    return 0;
  thread->cacheHit(requestedFlags);
  auto& thisflag = thread->perflag[requestedFlags];
  unsigned int size = thisflag.cache.size();
  unsigned int maxmax = (ipv4 ? thisflag.nIPv4 : 0) + (ipv6 ? thisflag.nIPv6 : 0);
  if (max > size)
    max = size;
  if (max > maxmax)
    max = maxmax;
  int i=0;
  while (i<max) {
    int j = i + (rand() % (size - i));
    do {
        bool ok = (ipv4 && thisflag.cache[j].v == 4) ||
                  (ipv6 && thisflag.cache[j].v == 6);
        if (ok) break;
        j++;
        if (j==size)
            j=i;
    } while(1);
    addr[i] = thisflag.cache[j];
    thisflag.cache[j] = thisflag.cache[i];
    thisflag.cache[i] = addr[i];
    i++;
  }
  return max;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movl %ecx, %r12d
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r15
movq $0x0, 0x18(%rsp)
movq %rsi, %rdi
callq 0x31c0
cmpl $0x2, %eax
jl 0xd70d
cmpb $0x78, (%r13)
jne 0xd70d
cmpb $0x30, 0x1(%r13)
jne 0xd864
movq 0x10(%r15), %rsi
movq %r13, %rdi
callq 0x3430
xorl %edx, %edx
testl %eax, %eax
jne 0xd8dc
movl %r12d, 0xc(%rsp)
leaq 0x18(%rsp), %r13
movq (%r13), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0xe9e2
addq $0x40, %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xec0a
movq %rax, %r15
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
shrq $0x2, %rcx
movl %ebp, %eax
testl %ebp, %ebp
je 0xd762
movl (%r15), %eax
imull $0xcccccccd, %ecx, %r12d # imm = 0xCCCCCCCD
movl %ebx, %ecx
testl %ebx, %ebx
je 0xd773
movl 0x4(%r15), %ecx
addl %eax, %ecx
movl 0xc(%rsp), %edx
cmpl %edx, %r12d
cmovbl %r12d, %edx
cmpl %ecx, %edx
cmovael %ecx, %edx
testl %edx, %edx
jle 0xd8dc
movl %edx, 0xc(%rsp)
movl %edx, %eax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
callq 0x30c0
movl %r12d, %ecx
subl %r13d, %ecx
xorl %edx, %edx
divl %ecx
addl %r13d, %edx
movq 0x8(%r15), %rax
movslq %edx, %rcx
testl %ebp, %ebp
je 0xd7d1
leaq (%rcx,%rcx,4), %rsi
movl (%rax,%rsi,4), %edi
cmpl $0x4, %edi
sete %sil
testl %ebx, %ebx
je 0xd7e1
cmpl $0x4, %edi
jne 0xd7d5
jmp 0xd7e1
testl %ebx, %ebx
je 0xd7ea
leaq (%rcx,%rcx,4), %rcx
cmpl $0x6, (%rax,%rcx,4)
sete %sil
testb %sil, %sil
je 0xd7ea
xorl %ecx, %ecx
jmp 0xd7f5
incl %edx
cmpl %r12d, %edx
cmovel %r13d, %edx
movb $0x1, %cl
testb %cl, %cl
jne 0xd7b1
movslq %edx, %rax
movq 0x8(%r15), %rcx
shlq $0x2, %rax
leaq (%rax,%rax,4), %rax
leaq (,%r13,4), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x10(%rcx,%rax), %esi
movl %esi, 0x10(%r14,%rdx)
movups (%rcx,%rax), %xmm0
movups %xmm0, (%r14,%rdx)
movq 0x8(%r15), %rcx
movl 0x10(%rcx,%rdx), %esi
movl %esi, 0x10(%rcx,%rax)
movups (%rcx,%rdx), %xmm0
movups %xmm0, (%rcx,%rax)
movq 0x8(%r15), %rax
movl 0x10(%r14,%rdx), %ecx
movl %ecx, 0x10(%rax,%rdx)
movups (%r14,%rdx), %xmm0
movups %xmm0, (%rax,%rdx)
incq %r13
cmpq 0x10(%rsp), %r13
jne 0xd79b
movl 0xc(%rsp), %edx
jmp 0xd8dc
leaq 0x1(%r13), %rdi
leaq 0x20(%rsp), %rsi
movl $0x10, %edx
callq 0x3500
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %rax
movq (%rax), %rax
cmpb $0x2e, (%rax)
setne %cl
addq $0x11, %r13
cmpq %r13, %rax
seta %al
orb %cl, %al
jne 0xd8da
movl %r12d, %r13d
movq 0x90(%r15), %rax
leaq 0x80(%r15), %r12
cmpq %r12, %rax
je 0xd8c3
movq 0x10(%rsp), %rcx
cmpq %rcx, 0x20(%rax)
je 0xd8c3
movq %rax, %rdi
callq 0x3450
jmp 0xd8a9
cmpq %r12, %rax
je 0xd8da
movl %r13d, %r12d
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0xd723
xorl %edx, %edx
movl %edx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq