// File: davidgfnet[P]tadns/tadns.cc
// Function: main
int main(int argc, char *argv[]) {
    enum dns_record_type qtype = DNS_A_RECORD;

    unsigned options = 0;
    int off = 1;
    while (off < argc) {
        if (!argv[off] || argv[off][0] != '-')
            break;

        if (!strcmp(argv[off], "-mx"))
            qtype = DNS_MX_RECORD;
        else if (!strcmp(argv[off], "-a"))
            qtype = DNS_A_RECORD;
        else if (!strcmp(argv[off], "-aaaa"))
            qtype = DNS_AAAA_RECORD;
        else if (!strcmp(argv[off], "-r"))
            options |= DNS_OPT_RECURSIVE_SOLVE;

        off++;
    }

    char ** domains = &argv[off];
    if (domains == 0)
        usage(argv[0]);

    DNSResolverIface *dns;
    if ((dns = createResolver(NULL, 10)) == NULL) {
        (void) fprintf(stderr, "failed to init resolver\n");
        exit(EXIT_FAILURE);
    }

    /* Select on resolver socket */
    do {
        while (*domains != 0 && inflight < 100) {
            stillrunning.insert(*domains);
            dns->resolve(*domains++, qtype, callback, NULL, options);
            inflight++;
        }

        fd_set set;
        struct timeval tv = {1, 0};
        auto sockets = dns->getFds();
        FD_ZERO(&set);
        FD_SET(sockets.first, &set);
        FD_SET(sockets.second, &set);
        select(std::max(sockets.first, sockets.second) + 1, &set, NULL, NULL, &tv);

        dns->poll();
    } while (dns->ongoingReqs() || *domains != 0);

    assert(stillrunning.size() == 0);

    delete dns;

    return (EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x6fbe
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x6f0d
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x6f12
jmp 0x6fbe
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x13375(%rip), %rsi     # 0x1a29a
callq 0x3480
cmpl $0x0, %eax
jne 0x6f38
movl $0xf, -0x14(%rbp)
jmp 0x6fb0
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x13353(%rip), %rsi     # 0x1a29e
callq 0x3480
cmpl $0x0, %eax
jne 0x6f5e
movl $0x1, -0x14(%rbp)
jmp 0x6fae
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x13330(%rip), %rsi     # 0x1a2a1
callq 0x3480
cmpl $0x0, %eax
jne 0x6f84
movl $0x1c, -0x14(%rbp)
jmp 0x6fac
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x13310(%rip), %rsi     # 0x1a2a7
callq 0x3480
cmpl $0x0, %eax
jne 0x6faa
movl -0x18(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x6fac
jmp 0x6fae
jmp 0x6fb0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6ede
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6fe4
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x73c0
xorl %eax, %eax
movl %eax, %edi
movl $0xa, %esi
callq 0x3820
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x701e
movq 0x20fcd(%rip), %rax     # 0x27fd0
movq (%rax), %rdi
leaq 0x1329d(%rip), %rsi     # 0x1a2aa
movb $0x0, %al
callq 0x3490
movl $0x1, %edi
callq 0x33f0
jmp 0x7020
jmp 0x7022
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x149(%rbp)
je 0x7044
cmpl $0x64, 0x212d1(%rip)    # 0x2830c
setb %al
movb %al, -0x149(%rbp)
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x7053
jmp 0x71e2
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x160(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x3520
movq -0x160(%rbp), %rsi
movq -0x158(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x8f00
jmp 0x708a
leaq 0x2127f(%rip), %rdi     # 0x28310
leaq -0x50(%rbp), %rsi
callq 0x98d0
movb %dl, -0x169(%rbp)
movq %rax, -0x168(%rbp)
jmp 0x70a9
movb -0x169(%rbp), %al
movq -0x168(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movb %al, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31e0
leaq -0x51(%rbp), %rdi
callq 0x3390
movq -0x30(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x28(%rbp)
movq (%rax), %rax
movq %rax, -0x180(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x3520
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x8f00
jmp 0x7122
movq -0x188(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %r9d
movq (%rdi), %rax
movq 0x18(%rax), %rax
leaq 0x2c2(%rip), %rcx       # 0x7400
xorl %esi, %esi
movl %esi, %r8d
leaq -0x98(%rbp), %rsi
callq *%rax
jmp 0x714e
leaq -0x98(%rbp), %rdi
callq 0x31e0
leaq -0x99(%rbp), %rdi
callq 0x3390
movl 0x211a0(%rip), %eax     # 0x2830c
addl $0x1, %eax
movl %eax, 0x21197(%rip)     # 0x2830c
jmp 0x7022
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x719d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31e0
leaq -0x51(%rbp), %rdi
callq 0x3390
jmp 0x73a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x71d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x31e0
leaq -0x99(%rbp), %rdi
callq 0x3390
jmp 0x73a9
movq 0x12ea7(%rip), %rax     # 0x1a090
movq %rax, -0x130(%rbp)
movq 0x12ea1(%rip), %rax     # 0x1a098
movq %rax, -0x128(%rbp)
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, -0x138(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0x148(%rbp)
movl $0x0, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
cmpq $0x10, %rax
jae 0x7259
movq -0x148(%rbp), %rax
movl -0x13c(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x13c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x7227
jmp 0x725b
movl -0x138(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x138(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x120(%rbp,%rax,8), %rcx
movq %rcx, -0x120(%rbp,%rax,8)
movl -0x134(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x134(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x120(%rbp,%rax,8), %rcx
movq %rcx, -0x120(%rbp,%rax,8)
leaq -0x138(%rbp), %rdi
leaq -0x138(%rbp), %rsi
addq $0x4, %rsi
callq 0x9920
movl (%rax), %edi
addl $0x1, %edi
leaq -0x120(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x130(%rbp), %r8
movq %rcx, %rdx
callq 0x32f0
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x189(%rbp)
jne 0x733f
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
setne %al
movb %al, -0x189(%rbp)
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x7020
leaq 0x20fbc(%rip), %rdi     # 0x28310
callq 0x9960
cmpq $0x0, %rax
jne 0x7361
jmp 0x7380
leaq 0x12f5b(%rip), %rdi     # 0x1a2c3
leaq 0x12d59(%rip), %rsi     # 0x1a0c8
movl $0x34e, %edx            # imm = 0x34E
leaq 0x12f61(%rip), %rcx     # 0x1a2dc
callq 0x31f0
movq -0x30(%rbp), %rax
movq %rax, -0x198(%rbp)
cmpq $0x0, %rax
je 0x739e
movq -0x198(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
xorl %eax, %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x3510
nopw %cs:(%rax,%rax)