// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movslq %edi, %r12
cmpl $0x2, %r12d
pushq $0x1
popq %rbp
movl %ebp, %eax
cmovgel %r12d, %eax
movl %eax, 0xc(%rsp)
movq %rsi, %r15
xorl %ebx, %ebx
pushq $0x1
popq %r14
cmpq %r12, %r14
jge 0x4375
movq (%r15,%r14,8), %r13
testq %r13, %r13
je 0x4370
cmpb $0x2d, (%r13)
jne 0x4370
movq %r13, %rdi
leaq 0x4f38(%rip), %rsi      # 0x925a
callq 0x2340
testl %eax, %eax
je 0x4360
cmpb $0x61, 0x1(%r13)
jne 0x4339
cmpb $0x0, 0x2(%r13)
je 0x4368
movq %r13, %rdi
leaq 0x4f1b(%rip), %rsi      # 0x925e
callq 0x2340
testl %eax, %eax
je 0x4364
cmpb $0x72, 0x1(%r13)
jne 0x436b
cmpb $0x0, 0x2(%r13)
pushq $0x1
popq %rax
cmovel %eax, %ebx
jmp 0x436b
pushq $0xf
jmp 0x436a
pushq $0x1c
jmp 0x436a
pushq $0x1
popq %rbp
incq %r14
jmp 0x4303
movl %r14d, %r12d
jmp 0x437a
movl 0xc(%rsp), %r12d
pushq $0xa
popq %rsi
xorl %edi, %edi
callq 0x2644
testq %rax, %rax
je 0x44f3
movq %rax, %r14
movl %r12d, %eax
leaq (%r15,%rax,8), %r12
leaq 0x48(%rsp), %r15
leaq 0x28(%rsp), %r13
movl 0xaead(%rip), %eax      # 0xf254
movq (%r12), %rsi
testq %rsi, %rsi
je 0x441f
cmpl $0x63, %eax
ja 0x441f
movq %r15, %rdi
leaq 0x10(%rsp), %rdx
callq 0x4bfe
leaq 0xae8f(%rip), %rdi      # 0xf258
movq %r15, %rsi
callq 0x7c6a
movq %r15, %rdi
callq 0x2120
movq (%r12), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x4bfe
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x162(%rip), %rcx       # 0x455c
xorl %r8d, %r8d
movl %ebx, %r9d
callq *0x18(%rax)
addq $0x8, %r12
movq %r13, %rdi
callq 0x2120
movl 0xae3f(%rip), %eax      # 0xf254
incl %eax
movl %eax, 0xae37(%rip)      # 0xf254
jmp 0x43a7
movups 0x4c2a(%rip), %xmm0     # 0x9050
movaps %xmm0, 0x10(%rsp)
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq %rax, %rsi
movq %rax, %rdi
shrq $0x20, %rdi
xorl %eax, %eax
cmpq $0x10, %rax
je 0x4451
andq $0x0, 0x48(%rsp,%rax,8)
incq %rax
jmp 0x4440
movl %esi, %eax
cltd
pushq $0x40
popq %r8
idivl %r8d
movslq %eax, %rdx
shll $0x6, %eax
movl %esi, %ecx
subl %eax, %ecx
pushq $0x1
popq %r9
movq %r9, %rax
shlq %cl, %rax
orq %rax, 0x48(%rsp,%rdx,8)
movl %edi, %eax
cltd
idivl %r8d
movslq %eax, %rdx
shll $0x6, %eax
movl %edi, %ecx
subl %eax, %ecx
movq %r9, %rax
shlq %cl, %rax
orq %rax, 0x48(%rsp,%rdx,8)
cmpl %edi, %esi
cmovgl %esi, %edi
incl %edi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x2230
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
testl %eax, %eax
jne 0x43a1
cmpq $0x0, (%r12)
jne 0x43a1
cmpq $0x0, 0xadac(%rip)      # 0xf280
jne 0x4517
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xaade(%rip), %rax      # 0xefd8
movq (%rax), %rcx
leaq 0x4d60(%rip), %rdi      # 0x9264
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x2420
pushq $0x1
popq %rdi
callq 0x22d0
leaq 0x4d5f(%rip), %rdi      # 0x927d
leaq 0x4b63(%rip), %rsi      # 0x9088
leaq 0x4d6a(%rip), %rcx      # 0x9296
movl $0x34e, %edx            # imm = 0x34E
callq 0x2190
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x454f
jmp 0x4542
movq %rax, %rbx
jmp 0x4554
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x23d0