// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movq %rsi, %r15
cmpl $0x2, %edi
jl 0x518f
movl %edi, %r14d
xorl %ebx, %ebx
movl $0x1, %r12d
movl $0x1, %ebp
movq (%r15,%r12,8), %r13
testq %r13, %r13
je 0x518a
cmpb $0x2d, (%r13)
jne 0x518a
movq %r13, %rdi
leaq 0x5138(%rip), %rsi      # 0xa25a
callq 0x2340
testl %eax, %eax
je 0x516c
movq %r13, %rdi
leaq 0x5129(%rip), %rsi      # 0xa25e
callq 0x2340
testl %eax, %eax
je 0x5173
movq %r13, %rdi
leaq 0x5119(%rip), %rsi      # 0xa261
callq 0x2340
testl %eax, %eax
je 0x517a
movq %r13, %rdi
leaq 0x510c(%rip), %rsi      # 0xa267
callq 0x2340
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %ebx
jmp 0x517f
movl $0xf, %ebp
jmp 0x517f
movl $0x1, %ebp
jmp 0x517f
movl $0x1c, %ebp
incq %r12
cmpq %r12, %r14
jne 0x5108
movl %r14d, %r12d
movl %r12d, %r12d
jmp 0x519c
xorl %ebx, %ebx
movl $0x1, %ebp
movl $0x1, %r12d
xorl %edi, %edi
movl $0xa, %esi
callq 0x2700
testq %rax, %rax
je 0x5377
movq %rax, %r14
leaq (%r15,%r12,8), %r12
leaq 0x30(%rsp), %r15
movq %rsp, %r13
cmpq $0x0, (%r12)
je 0x527b
cmpl $0x63, 0xa07a(%rip)     # 0xf24c
ja 0x527b
movq (%r12), %rsi
movq %r15, %rdi
leaq 0x20(%rsp), %rdx
callq 0x5b84
leaq 0xa060(%rip), %rdi      # 0xf250
movq %r15, %rsi
callq 0x8930
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5214
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2280
movq (%r12), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x5b84
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x1ac(%rip), %rcx       # 0x53e1
xorl %r8d, %r8d
movl %ebx, %r9d
callq *0x18(%rax)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5259
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2280
addq $0x8, %r12
movl 0x9fe9(%rip), %eax      # 0xf24c
incl %eax
movl %eax, 0x9fe1(%rip)      # 0xf24c
cmpq $0x0, (%r12)
je 0x527b
cmpl $0x64, %eax
jb 0x51d8
movups 0x4dce(%rip), %xmm0     # 0xa050
movaps %xmm0, 0x20(%rsp)
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq %rax, %rdi
shrq $0x20, %rdi
leal 0x3f(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
movl %edx, %esi
andl $-0x40, %esi
movl %eax, %ecx
subl %esi, %ecx
movl $0x1, %esi
shlq %cl, %rsi
sarl $0x6, %edx
movslq %edx, %rcx
orq %rsi, 0x30(%rsp,%rcx,8)
leal 0x3f(%rdi), %edx
testl %edi, %edi
cmovnsl %edi, %edx
movl %edx, %esi
andl $-0x40, %esi
movl %edi, %ecx
subl %esi, %ecx
movl $0x1, %esi
shlq %cl, %rsi
sarl $0x6, %edx
movslq %edx, %rcx
orq %rsi, 0x30(%rsp,%rcx,8)
cmpl %edi, %eax
cmovgl %eax, %edi
incl %edi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x20(%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 0x51c0
cmpq $0x0, (%r12)
jne 0x51c0
cmpq $0x0, 0x9f20(%rip)      # 0xf278
jne 0x537c
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2460
leaq 0x4f00(%rip), %rdi      # 0xa283
leaq 0x4cfe(%rip), %rsi      # 0xa088
leaq 0x4f0b(%rip), %rcx      # 0xa29c
movl $0x34e, %edx            # imm = 0x34E
callq 0x2180
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x53d9
movq 0x10(%rsp), %rsi
jmp 0x53ca
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x53d9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2280
jmp 0x53d9
jmp 0x53d6
movq %rax, %rbx
movq %rbx, %rdi
callq 0x23e0