// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4210
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
jle 0x22cdf
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x78, %eax
jne 0x22cdf
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x30, %eax
je 0x22cdf
movq -0x18(%rbp), %rdi
addq $0x1, %rdi
leaq -0x50(%rbp), %rsi
movl $0x10, %edx
callq 0x4650
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, -0x92(%rbp)
jne 0x22cbb
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rdx
addq $0x11, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x92(%rbp)
ja 0x22cbb
movq -0x38(%rbp), %rdi
addq $0x78, %rdi
callq 0x249d0
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
addq $0x78, %rdi
callq 0x24a00
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x24980
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rdi
addq $0x78, %rdi
callq 0x24a00
movq %rax, -0x78(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x24950
movb %al, -0x92(%rbp)
movb -0x92(%rbp), %al
testb $0x1, %al
jne 0x22cc7
jmp 0x22cd1
movq -0x58(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x22cdd
movl $0x0, -0x4(%rbp)
jmp 0x22fa4
jmp 0x22d03
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x4540
cmpl $0x0, %eax
je 0x22d01
movl $0x0, -0x4(%rbp)
jmp 0x22fa4
jmp 0x22d03
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0x24a30
movq -0x38(%rbp), %rdi
addq $0x40, %rdi
leaq -0x40(%rbp), %rsi
callq 0x24d40
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x24e20
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x22d4e
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x98(%rbp)
jmp 0x22d58
xorl %eax, %eax
movl %eax, -0x98(%rbp)
jmp 0x22d58
movl -0x98(%rbp), %eax
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x22d79
movq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xa0(%rbp)
jmp 0x22d83
xorl %eax, %eax
movl %eax, -0xa0(%rbp)
jmp 0x22d83
movl -0x9c(%rbp), %eax
movl -0xa0(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x84(%rbp), %eax
jbe 0x22dab
movl -0x84(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x88(%rbp), %eax
jbe 0x22dbf
movl -0x88(%rbp), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x22f9e
movl -0x8c(%rbp), %eax
movl %eax, -0xa4(%rbp)
callq 0x4110
movl -0x84(%rbp), %ecx
subl -0x8c(%rbp), %ecx
xorl %edx, %edx
divl %ecx
movl -0xa4(%rbp), %eax
addl %edx, %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x22e31
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movslq -0x90(%rbp), %rsi
callq 0x24e50
movq %rax, %rcx
movb $0x1, %al
cmpl $0x4, (%rcx)
movb %al, -0xa5(%rbp)
je 0x22e6b
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0xa6(%rbp)
je 0x22e5f
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movslq -0x90(%rbp), %rsi
callq 0x24e50
cmpl $0x6, (%rax)
sete %al
movb %al, -0xa6(%rbp)
movb -0xa6(%rbp), %al
movb %al, -0xa5(%rbp)
movb -0xa5(%rbp), %al
andb $0x1, %al
movb %al, -0x91(%rbp)
testb $0x1, -0x91(%rbp)
je 0x22e84
jmp 0x22ebb
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x84(%rbp), %eax
jne 0x22ead
movl -0x8c(%rbp), %eax
movl %eax, -0x90(%rbp)
jmp 0x22eaf
movb $0x1, %al
testb $0x1, %al
jne 0x22e07
jmp 0x22ebb
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movslq -0x90(%rbp), %rsi
callq 0x24e50
movq %rax, %rcx
movq -0x20(%rbp), %rax
movslq -0x8c(%rbp), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movslq -0x8c(%rbp), %rsi
callq 0x24e50
movq %rax, -0xb8(%rbp)
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movslq -0x90(%rbp), %rsi
callq 0x24e50
movq -0xb8(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movslq -0x8c(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movslq -0x8c(%rbp), %rsi
callq 0x24e50
movq -0xb0(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x22dc9
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq