// File: /workspace/github_cpp_makefile_star2_O3/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 0x517e
movl %edi, %r14d
xorl %ebx, %ebx
movl $0x1, %r12d
movl $0x1, %ebp
movq (%r15,%r12,8), %r13
testq %r13, %r13
je 0x5179
cmpb $0x2d, (%r13)
jne 0x5179
movq %r13, %rdi
leaq 0x50c9(%rip), %rsi      # 0xa1e4
callq 0x2340
testl %eax, %eax
je 0x515b
cmpb $0x61, 0x1(%r13)
jne 0x5132
cmpb $0x0, 0x2(%r13)
je 0x5169
movq %r13, %rdi
leaq 0x50ac(%rip), %rsi      # 0xa1e8
callq 0x2340
testl %eax, %eax
je 0x5162
cmpb $0x72, 0x1(%r13)
jne 0x516e
cmpb $0x0, 0x2(%r13)
movl $0x1, %eax
cmovel %eax, %ebx
jmp 0x516e
movl $0xf, %ebp
jmp 0x516e
movl $0x1c, %ebp
jmp 0x516e
movl $0x1, %ebp
incq %r12
cmpq %r12, %r14
jne 0x5101
movl %r14d, %r12d
movl %r12d, %r12d
jmp 0x518b
xorl %ebx, %ebx
movl $0x1, %ebp
movl $0x1, %r12d
xorl %edi, %edi
movl $0xa, %esi
callq 0x2700
testq %rax, %rax
je 0x5366
movq %rax, %r14
leaq (%r15,%r12,8), %r12
leaq 0x30(%rsp), %r15
movq %rsp, %r13
movq (%r12), %rsi
testq %rsi, %rsi
je 0x526a
cmpl $0x63, 0xa089(%rip)     # 0xf24c
ja 0x526a
movq %r15, %rdi
leaq 0x20(%rsp), %rdx
callq 0x5b7c
leaq 0xa073(%rip), %rdi      # 0xf250
movq %r15, %rsi
callq 0x88a4
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5201
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2280
movq (%r12), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x5b7c
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
movl %ebp, %edx
leaq 0x1ae(%rip), %rcx       # 0x53d0
xorl %r8d, %r8d
movl %ebx, %r9d
callq *0x18(%rax)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5246
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2280
addq $0x8, %r12
movl 0x9ffc(%rip), %eax      # 0xf24c
incl %eax
movl %eax, 0x9ff4(%rip)      # 0xf24c
movq (%r12), %rsi
testq %rsi, %rsi
je 0x526a
cmpl $0x64, %eax
jb 0x51c9
movups 0x4ddf(%rip), %xmm0     # 0xa050
movaps %xmm0, 0x20(%rsp)
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq %rax, %rdi
shrq $0x20, %rdi
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)
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 0x51af
cmpq $0x0, (%r12)
jne 0x51af
cmpq $0x0, 0x9f31(%rip)      # 0xf278
jne 0x536b
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 0x4e95(%rip), %rdi      # 0xa207
leaq 0x4d0f(%rip), %rsi      # 0xa088
leaq 0x4ea0(%rip), %rcx      # 0xa220
movl $0x34e, %edx            # imm = 0x34E
callq 0x2180
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x53c8
movq 0x10(%rsp), %rsi
jmp 0x53b9
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x53c8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2280
jmp 0x53c8
jmp 0x53c5
movq %rax, %rbx
movq %rbx, %rdi
callq 0x23e0