// File: tenup-coin[P]seeder/main.cpp
// Function: main
int main(int argc, char **argv) {
  signal(SIGPIPE, SIG_IGN);
  setbuf(stdout, NULL);
  CDnsSeedOpts opts;
  opts.ParseCommandLine(argc, argv);
  printf("Supporting whitelisted filters: ");
  for (std::set<uint64_t>::const_iterator it = opts.filter_whitelist.begin(); it != opts.filter_whitelist.end(); it++) {
      if (it != opts.filter_whitelist.begin()) {
          printf(",");
      }
      printf("0x%lx", (unsigned long)*it);
  }
  printf("\n");
  if (opts.tor) {
    CService service(opts.tor, 9050);
    if (service.IsValid()) {
      printf("Using Tor proxy at %s\n", service.ToStringIPPort().c_str());
      SetProxy(NET_TOR, service);
    }
  }
  if (opts.ipv4_proxy) {
    CService service(opts.ipv4_proxy, 9050);
    if (service.IsValid()) {
      printf("Using IPv4 proxy at %s\n", service.ToStringIPPort().c_str());
      SetProxy(NET_IPV4, service);
    }
  }
  if (opts.ipv6_proxy) {
    CService service(opts.ipv6_proxy, 9050);
    if (service.IsValid()) {
      printf("Using IPv6 proxy at %s\n", service.ToStringIPPort().c_str());
      SetProxy(NET_IPV6, service);
    }
  }
  bool fDNS = true;
  if (opts.fUseTestNet) {
      printf("Using testnet.\n");
      pchMessageStart[0] = 0x90;
      pchMessageStart[1] = 0xc4;
      pchMessageStart[2] = 0xfd;
      pchMessageStart[3] = 0xe9;
      seeds = testnet_seeds;
      fTestNet = true;
  }
  if (!opts.ns) {
    printf("No nameserver set. Not starting DNS server.\n");
    fDNS = false;
  }
  if (fDNS && !opts.host) {
    fprintf(stderr, "No hostname set. Please use -h.\n");
    exit(1);
  }
  if (fDNS && !opts.mbox) {
    fprintf(stderr, "No e-mail address set. Please use -m.\n");
    exit(1);
  }
  FILE *f = fopen("dnsseed.dat","r");
  if (f) {
    printf("Loading dnsseed.dat...");
    CAutoFile cf(f);
    cf >> db;
    if (opts.fWipeBan)
        db.banned.clear();
    if (opts.fWipeIgnore)
        db.ResetIgnores();
    printf("done\n");
  }
  pthread_t threadDns, threadSeed, threadDump, threadStats;
  if (fDNS) {
    printf("Starting %i DNS threads for %s on %s (port %i)...", opts.nDnsThreads, opts.host, opts.ns, opts.nPort);
    dnsThread.clear();
    for (int i=0; i<opts.nDnsThreads; i++) {
      dnsThread.push_back(new CDnsThread(&opts, i));
      pthread_create(&threadDns, NULL, ThreadDNS, dnsThread[i]);
      printf(".");
      Sleep(20);
    }
    printf("done\n");
  }
  printf("Starting seeder...");
  pthread_create(&threadSeed, NULL, ThreadSeeder, NULL);
  printf("done\n");
  printf("Starting %i crawler threads...", opts.nThreads);
  pthread_attr_t attr_crawler;
  pthread_attr_init(&attr_crawler);
  pthread_attr_setstacksize(&attr_crawler, 0x20000);
  for (int i=0; i<opts.nThreads; i++) {
    pthread_t thread;
    pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads);
  }
  pthread_attr_destroy(&attr_crawler);
  printf("done\n");
  pthread_create(&threadStats, NULL, ThreadStats, NULL);
  pthread_create(&threadDump, NULL, ThreadDumper, NULL);
  void* res;
  pthread_join(threadDump, &res);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xd, %edi
movl $0x1, %esi
callq 0x45a0
movq 0x264b9(%rip), %rax     # 0x49f78
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x46e0
leaq -0x88(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x25800
movq -0x260(%rbp), %rdi
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
callq 0x25880
jmp 0x23af3
leaq 0x10269(%rip), %rdi     # 0x33d63
xorl %eax, %eax
callq 0x4070
jmp 0x23b03
leaq -0x88(%rbp), %rdi
addq $0x48, %rdi
callq 0x249d0
movq %rax, -0xa0(%rbp)
leaq -0x88(%rbp), %rdi
addq $0x48, %rdi
callq 0x24a00
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x24950
testb $0x1, %al
jne 0x23b4d
jmp 0x23be1
leaq -0x88(%rbp), %rdi
addq $0x48, %rdi
callq 0x249d0
movq %rax, -0xb0(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x24950
testb $0x1, %al
jne 0x23b7d
jmp 0x23ba6
leaq 0x10200(%rip), %rdi     # 0x33d84
xorl %eax, %eax
callq 0x4070
jmp 0x23b8d
jmp 0x23ba6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x24327
leaq -0xa0(%rbp), %rdi
callq 0x25eb0
movq (%rax), %rsi
leaq 0x101ca(%rip), %rdi     # 0x33d86
xorl %eax, %eax
callq 0x4070
jmp 0x23bc5
jmp 0x23bc7
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x25ed0
movq %rax, -0xb8(%rbp)
jmp 0x23b1a
leaq 0x105d4(%rip), %rdi     # 0x341bc
xorl %eax, %eax
callq 0x4070
jmp 0x23bf1
cmpq $0x0, -0x58(%rbp)
je 0x23ce4
movq -0x58(%rbp), %rsi
leaq -0xca(%rbp), %rdi
movl $0x235a, %edx           # imm = 0x235A
xorl %ecx, %ecx
callq 0x14900
jmp 0x23c15
leaq -0xca(%rbp), %rdi
callq 0x10150
movb %al, -0x261(%rbp)
jmp 0x23c29
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0x23c38
jmp 0x23ce2
leaq -0xf0(%rbp), %rdi
leaq -0xca(%rbp), %rsi
callq 0x14de0
jmp 0x23c4d
leaq -0xf0(%rbp), %rdi
callq 0x41e0
movq %rax, %rsi
leaq 0x10129(%rip), %rdi     # 0x33d8c
xorl %eax, %eax
callq 0x4070
jmp 0x23c6c
leaq -0xf0(%rbp), %rdi
callq 0x42f0
movw -0xba(%rbp), %ax
movw %ax, -0x100(%rbp)
movups -0xca(%rbp), %xmm0
movaps %xmm0, -0x110(%rbp)
movw -0x100(%rbp), %cx
movq %rsp, %rax
movw %cx, 0x10(%rax)
movaps -0x110(%rbp), %xmm0
movups %xmm0, (%rax)
movl $0x3, %edi
movl $0x5, %esi
callq 0x10090
jmp 0x23cbd
jmp 0x23ce2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x42f0
jmp 0x24327
jmp 0x23ce4
cmpq $0x0, -0x50(%rbp)
je 0x23dd7
movq -0x50(%rbp), %rsi
leaq -0x122(%rbp), %rdi
movl $0x235a, %edx           # imm = 0x235A
xorl %ecx, %ecx
callq 0x14900
jmp 0x23d08
leaq -0x122(%rbp), %rdi
callq 0x10150
movb %al, -0x262(%rbp)
jmp 0x23d1c
movb -0x262(%rbp), %al
testb $0x1, %al
jne 0x23d2b
jmp 0x23dd5
leaq -0x148(%rbp), %rdi
leaq -0x122(%rbp), %rsi
callq 0x14de0
jmp 0x23d40
leaq -0x148(%rbp), %rdi
callq 0x41e0
movq %rax, %rsi
leaq 0x1004d(%rip), %rdi     # 0x33da3
xorl %eax, %eax
callq 0x4070
jmp 0x23d5f
leaq -0x148(%rbp), %rdi
callq 0x42f0
movw -0x112(%rbp), %ax
movw %ax, -0x150(%rbp)
movups -0x122(%rbp), %xmm0
movaps %xmm0, -0x160(%rbp)
movw -0x150(%rbp), %cx
movq %rsp, %rax
movw %cx, 0x10(%rax)
movaps -0x160(%rbp), %xmm0
movups %xmm0, (%rax)
movl $0x1, %edi
movl $0x5, %esi
callq 0x10090
jmp 0x23db0
jmp 0x23dd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x42f0
jmp 0x24327
jmp 0x23dd7
cmpq $0x0, -0x48(%rbp)
je 0x23eca
movq -0x48(%rbp), %rsi
leaq -0x172(%rbp), %rdi
movl $0x235a, %edx           # imm = 0x235A
xorl %ecx, %ecx
callq 0x14900
jmp 0x23dfb
leaq -0x172(%rbp), %rdi
callq 0x10150
movb %al, -0x263(%rbp)
jmp 0x23e0f
movb -0x263(%rbp), %al
testb $0x1, %al
jne 0x23e1e
jmp 0x23ec8
leaq -0x198(%rbp), %rdi
leaq -0x172(%rbp), %rsi
callq 0x14de0
jmp 0x23e33
leaq -0x198(%rbp), %rdi
callq 0x41e0
movq %rax, %rsi
leaq 0xff72(%rip), %rdi      # 0x33dbb
xorl %eax, %eax
callq 0x4070
jmp 0x23e52
leaq -0x198(%rbp), %rdi
callq 0x42f0
movw -0x162(%rbp), %ax
movw %ax, -0x1a0(%rbp)
movups -0x172(%rbp), %xmm0
movaps %xmm0, -0x1b0(%rbp)
movw -0x1a0(%rbp), %cx
movq %rsp, %rax
movw %cx, 0x10(%rax)
movaps -0x1b0(%rbp), %xmm0
movups %xmm0, (%rax)
movl $0x2, %edi
movl $0x5, %esi
callq 0x10090
jmp 0x23ea3
jmp 0x23ec8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x42f0
jmp 0x24327
jmp 0x23eca
movb $0x1, -0x1b1(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x23f27
leaq 0xfef5(%rip), %rdi      # 0x33dd3
xorl %eax, %eax
callq 0x4070
jmp 0x23ee7
leaq 0x265c2(%rip), %rax     # 0x4a4b0
movb $-0x70, (%rax)
leaq 0x265b8(%rip), %rax     # 0x4a4b0
movb $-0x3c, 0x1(%rax)
leaq 0x265ad(%rip), %rax     # 0x4a4b0
movb $-0x3, 0x2(%rax)
leaq 0x265a2(%rip), %rax     # 0x4a4b0
movb $-0x17, 0x3(%rax)
leaq 0x26897(%rip), %rax     # 0x4a7b0
movq %rax, 0x265b8(%rip)     # 0x4a4d8
movb $0x1, 0x26679(%rip)     # 0x4a5a0
cmpq $0x0, -0x68(%rbp)
jne 0x23f45
leaq 0xfeae(%rip), %rdi      # 0x33de3
xorl %eax, %eax
callq 0x4070
jmp 0x23f3e
movb $0x0, -0x1b1(%rbp)
testb $0x1, -0x1b1(%rbp)
je 0x23f77
cmpq $0x0, -0x60(%rbp)
jne 0x23f77
movq 0x2606c(%rip), %rax     # 0x49fc8
movq (%rax), %rdi
leaq 0xfeaa(%rip), %rsi      # 0x33e10
movb $0x0, %al
callq 0x4700
movl $0x1, %edi
callq 0x45b0
testb $0x1, -0x1b1(%rbp)
je 0x23fa9
cmpq $0x0, -0x70(%rbp)
jne 0x23fa9
movq 0x2603a(%rip), %rax     # 0x49fc8
movq (%rax), %rdi
leaq 0xfe99(%rip), %rsi      # 0x33e31
movb $0x0, %al
callq 0x4700
movl $0x1, %edi
callq 0x45b0
leaq 0xfbcb(%rip), %rdi      # 0x33b7b
leaq 0xf282(%rip), %rsi      # 0x33239
callq 0x4590
movq %rax, -0x270(%rbp)
jmp 0x23fc5
movq -0x270(%rbp), %rax
movq %rax, -0x1c0(%rbp)
cmpq $0x0, -0x1c0(%rbp)
je 0x24095
leaq 0xfe70(%rip), %rdi      # 0x33e58
xorl %eax, %eax
callq 0x4070
jmp 0x23ff1
movq -0x1c0(%rbp), %rsi
leaq -0x1d8(%rbp), %rdi
movl $0x2, %edx
movl $0x11500, %ecx          # imm = 0x11500
callq 0x251b0
jmp 0x24010
leaq 0x26591(%rip), %rsi     # 0x4a5a8
leaq -0x1d8(%rbp), %rdi
callq 0x25f10
jmp 0x24025
cmpl $0x0, -0x78(%rbp)
je 0x24063
leaq 0x26576(%rip), %rdi     # 0x4a5a8
addq $0x158, %rdi            # imm = 0x158
callq 0x25fc0
jmp 0x24063
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x252c0
jmp 0x24327
cmpl $0x0, -0x74(%rbp)
je 0x24079
leaq 0x26538(%rip), %rdi     # 0x4a5a8
callq 0x25fe0
jmp 0x24077
jmp 0x24079
leaq 0xfdef(%rip), %rdi      # 0x33e6f
xorl %eax, %eax
callq 0x4070
jmp 0x24089
leaq -0x1d8(%rbp), %rdi
callq 0x252c0
testb $0x1, -0x1b1(%rbp)
je 0x241d8
movl -0x84(%rbp), %r8d
movl -0x80(%rbp), %esi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
leaq 0xfdba(%rip), %rdi      # 0x33e75
xorl %eax, %eax
callq 0x4070
jmp 0x240c4
leaq 0x26665(%rip), %rdi     # 0x4a730
callq 0x26050
movl $0x0, -0x1fc(%rbp)
movl -0x1fc(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0x241c6
movl $0xa8, %edi
callq 0x44e0
movq %rax, -0x278(%rbp)
jmp 0x240fc
movq -0x278(%rbp), %rdi
movl -0x1fc(%rbp), %edx
leaq -0x88(%rbp), %rsi
callq 0x260a0
jmp 0x24117
movq -0x278(%rbp), %rax
movq %rax, -0x208(%rbp)
leaq 0x26604(%rip), %rdi     # 0x4a730
leaq -0x208(%rbp), %rsi
callq 0x26070
jmp 0x2413a
movslq -0x1fc(%rbp), %rsi
leaq 0x265e8(%rip), %rdi     # 0x4a730
callq 0x25610
movq (%rax), %rcx
leaq -0x11a7(%rip), %rdx     # 0x22fb0
xorl %eax, %eax
movl %eax, -0x27c(%rbp)
movl %eax, %esi
leaq -0x1e0(%rbp), %rdi
callq 0x4850
movl -0x27c(%rbp), %eax
leaq 0xfd2b(%rip), %rdi      # 0x33ea5
callq 0x4070
jmp 0x24181
movl $0x14, %edi
callq 0x22b60
jmp 0x2418d
jmp 0x2418f
movl -0x1fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1fc(%rbp)
jmp 0x240da
movq -0x278(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
callq 0x44b0
jmp 0x24327
leaq 0xfca2(%rip), %rdi      # 0x33e6f
xorl %eax, %eax
callq 0x4070
jmp 0x241d6
jmp 0x241d8
leaq 0xfcc8(%rip), %rdi      # 0x33ea7
xorl %eax, %eax
callq 0x4070
jmp 0x241e8
leaq -0xa9f(%rip), %rdx      # 0x23750
xorl %eax, %eax
movl %eax, -0x280(%rbp)
movl %eax, %ecx
leaq -0x1e8(%rbp), %rdi
movq %rcx, %rsi
callq 0x4850
movl -0x280(%rbp), %eax
leaq 0xfc5a(%rip), %rdi      # 0x33e6f
callq 0x4070
jmp 0x2421c
movl -0x88(%rbp), %esi
leaq 0xfc91(%rip), %rdi      # 0x33eba
xorl %eax, %eax
callq 0x4070
jmp 0x24232
leaq -0x240(%rbp), %rdi
callq 0x45c0
leaq -0x240(%rbp), %rdi
movl $0x20000, %esi          # imm = 0x20000
callq 0x4680
movl $0x0, -0x244(%rbp)
movl -0x244(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0x24299
leaq -0x88(%rbp), %rcx
leaq -0x250(%rbp), %rdi
leaq -0x240(%rbp), %rsi
leaq -0x19c3(%rip), %rdx     # 0x228c0
callq 0x4850
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x24259
leaq -0x240(%rbp), %rdi
callq 0x47b0
leaq 0xfbc3(%rip), %rdi      # 0x33e6f
xorl %eax, %eax
callq 0x4070
jmp 0x242b5
leaq -0xd5c(%rip), %rdx      # 0x23560
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, -0x288(%rbp)
leaq -0x1f8(%rbp), %rdi
movq %rcx, %rsi
callq 0x4850
movq -0x288(%rbp), %rcx
leaq -0x1264(%rip), %rdx     # 0x23080
leaq -0x1f0(%rbp), %rdi
movq %rcx, %rsi
callq 0x4850
movq -0x1f0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4470
jmp 0x24308
movl $0x0, -0x4(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x261a0
movl -0x4(%rbp), %eax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x261a0
movq -0x90(%rbp), %rdi
callq 0x47f0
nop