// File: /workspace/github_cpp_makefile_star2_O3/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, %r15d
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r13
movq $0x0, 0x10(%rsp)
movq %rsi, %rdi
callq 0x31c0
cmpl $0x2, %eax
jl 0xd512
cmpb $0x78, (%r12)
jne 0xd512
cmpb $0x30, 0x1(%r12)
jne 0xd656
movq 0x10(%r13), %rsi
movq %r12, %rdi
callq 0x3430
xorl %r12d, %r12d
testl %eax, %eax
jne 0xd6cb
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xe7ee
addq $0x40, %r13
leaq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0xea16
movq %rax, %r13
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
shrq $0x2, %rcx
movl %ebp, %eax
testl %ebp, %ebp
je 0xd560
movl (%r13), %eax
imull $0xcccccccd, %ecx, %r12d # imm = 0xCCCCCCCD
movl %ebx, %ecx
testl %ebx, %ebx
je 0xd571
movl 0x4(%r13), %ecx
addl %eax, %ecx
cmpl %r15d, %r12d
cmovbl %r12d, %r15d
cmpl %ecx, %r15d
movl %r15d, %eax
cmovael %ecx, %eax
testl %eax, %eax
jle 0xd651
movq %rax, 0x18(%rsp)
movl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
callq 0x30c0
movl %r12d, %ecx
subl %r15d, %ecx
xorl %edx, %edx
divl %ecx
addl %r15d, %edx
movq 0x8(%r13), %rax
testl %ebp, %ebp
je 0xd5ce
movslq %edx, %rcx
leaq (%rcx,%rcx,4), %rsi
movl (%rax,%rsi,4), %esi
testl %ebx, %ebx
je 0xd5c7
cmpl $0x4, %esi
jne 0xd5dc
cmpl $0x4, %esi
jne 0xd5e1
jmp 0xd5ec
testl %ebx, %ebx
je 0xd5e1
movslq %edx, %rcx
leaq (%rcx,%rcx,4), %rsi
movl (%rax,%rsi,4), %esi
cmpl $0x6, %esi
je 0xd5ec
incl %edx
cmpl %r12d, %edx
cmovel %r15d, %edx
jmp 0xd5b0
shlq $0x2, %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (,%r15,4), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x10(%rax,%rcx), %esi
movl %esi, 0x10(%r14,%rdx)
movups (%rax,%rcx), %xmm0
movups %xmm0, (%r14,%rdx)
movq 0x8(%r13), %rax
movl 0x10(%rax,%rdx), %esi
movl %esi, 0x10(%rax,%rcx)
movups (%rax,%rdx), %xmm0
movups %xmm0, (%rax,%rcx)
movq 0x8(%r13), %rax
movl 0x10(%r14,%rdx), %ecx
movl %ecx, 0x10(%rax,%rdx)
movups (%r14,%rdx), %xmm0
movups %xmm0, (%rax,%rdx)
incq %r15
cmpq 0x8(%rsp), %r15
jne 0xd59a
movq 0x18(%rsp), %r12
jmp 0xd6cb
movq %rax, %r12
jmp 0xd6cb
movl %r15d, 0x8(%rsp)
leaq 0x1(%r12), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0x3500
movq (%r15), %rdx
cmpb $0x2e, (%rdx)
setne %cl
addq $0x11, %r12
cmpq %r12, %rdx
movq %rax, %r12
seta %al
orb %cl, %al
jne 0xd6c8
movq 0x90(%r13), %rax
leaq 0x80(%r13), %r15
cmpq %r15, %rax
je 0xd6b4
cmpq %r12, 0x20(%rax)
je 0xd6b4
movq %rax, %rdi
callq 0x3450
cmpq %r15, %rax
jne 0xd69f
jmp 0xd6c8
cmpq %r15, %rax
je 0xd6c8
movq %r12, 0x10(%rsp)
movl 0x8(%rsp), %r15d
jmp 0xd529
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq