// File: davidgfnet[P]tadns/tadns.cc
// Function: DNSResolver::poll()
int DNSResolver::poll() {
    struct sockaddr_in sa;
    socklen_t len = sizeof(sa);
    int n, num_packets = 0;
    unsigned char pkt[DNS_PACKET_LEN];
    time_t now;

    now = time(NULL);

    /* Check our sockets for new stuff */
    while ((n = recvfrom(sock4, pkt, sizeof(pkt), 0,
        (struct sockaddr *) &sa, &len)) > 0 &&
        n > (int) sizeof(struct header)) {
        this->parse_udp(pkt, n);
        num_packets++;
    }
    while ((n = recvfrom(sock6, pkt, sizeof(pkt), 0,
        (struct sockaddr *) &sa, &len)) > 0 &&
        n > (int) sizeof(struct header)) {
        this->parse_udp(pkt, n);
        num_packets++;
    }

    /* Cleanup expired active queries */
    auto ita = active.begin();
    while (ita != active.end()) {
        if (ita->second->atimeout < now) {
            call_user_rec(ita->second, DNS_TIMEOUT);

            ongoing.erase(std::make_pair(ita->second->name, ita->second->qtype));
            delete ita->second;
            ita = active.erase(ita);
            assert(active.size() == ongoing.size());
        }
        else ita++;
    }

    return (num_packets);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8e0, %rsp            # imm = 0x8E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x8a0(%rbp)
movl $0x10, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3310
movq %rax, -0x838(%rbp)
movq -0x8a0(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x830(%rbp), %rsi
movl $0x800, %edx            # imm = 0x800
xorl %ecx, %ecx
leaq -0x18(%rbp), %r8
leaq -0x1c(%rbp), %r9
callq 0x3290
movl %eax, %ecx
movl %ecx, -0x20(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x8a1(%rbp)
jle 0x7a3c
cmpl $0xc, -0x20(%rbp)
setg %al
movb %al, -0x8a1(%rbp)
movb -0x8a1(%rbp), %al
testb $0x1, %al
jne 0x7a48
jmp 0x7a69
movq -0x8a0(%rbp), %rdi
leaq -0x830(%rbp), %rsi
movl -0x20(%rbp), %edx
callq 0x6880
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x79f8
jmp 0x7a6b
movq -0x8a0(%rbp), %rax
movl 0xc(%rax), %edi
leaq -0x830(%rbp), %rsi
movl $0x800, %edx            # imm = 0x800
xorl %ecx, %ecx
leaq -0x18(%rbp), %r8
leaq -0x1c(%rbp), %r9
callq 0x3290
movl %eax, %ecx
movl %ecx, -0x20(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x8a2(%rbp)
jle 0x7aaf
cmpl $0xc, -0x20(%rbp)
setg %al
movb %al, -0x8a2(%rbp)
movb -0x8a2(%rbp), %al
testb $0x1, %al
jne 0x7abb
jmp 0x7adc
movq -0x8a0(%rbp), %rdi
leaq -0x830(%rbp), %rsi
movl -0x20(%rbp), %edx
callq 0x6880
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7a6b
movq -0x8a0(%rbp), %rdi
addq $0x38, %rdi
callq 0x9b90
movq %rax, -0x840(%rbp)
movq -0x8a0(%rbp), %rdi
addq $0x38, %rdi
callq 0x9bc0
movq %rax, -0x848(%rbp)
leaq -0x840(%rbp), %rdi
leaq -0x848(%rbp), %rsi
callq 0x9bf0
testb $0x1, %al
jne 0x7b26
jmp 0x7cf1
leaq -0x840(%rbp), %rdi
callq 0xa670
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpq -0x838(%rbp), %rax
jge 0x7cd7
leaq -0x840(%rbp), %rdi
movq %rdi, -0x8c8(%rbp)
callq 0xa670
movq -0x8a0(%rbp), %rdi
movq 0x8(%rax), %rsi
movl $0x2, %edx
callq 0x7090
movq -0x8a0(%rbp), %rax
movq -0x8c8(%rbp), %rdi
addq $0x70, %rax
movq %rax, -0x8b8(%rbp)
callq 0xa670
movq -0x8c8(%rbp), %rdi
movq 0x8(%rax), %rax
addq $0x10, %rax
movq %rax, -0x8c0(%rbp)
callq 0xa670
movq -0x8c0(%rbp), %rsi
movq 0x8(%rax), %rdx
addq $0xc, %rdx
leaq -0x870(%rbp), %rdi
movq %rdi, -0x8b0(%rbp)
callq 0x9c80
movq -0x8b8(%rbp), %rdi
movq -0x8b0(%rbp), %rsi
callq 0x9c50
jmp 0x7bde
leaq -0x870(%rbp), %rdi
callq 0x9ab0
leaq -0x840(%rbp), %rdi
callq 0xa670
movq 0x8(%rax), %rax
movq %rax, -0x8d0(%rbp)
cmpq $0x0, %rax
je 0x7c24
movq -0x8d0(%rbp), %rdi
callq 0x9cc0
movq -0x8d0(%rbp), %rdi
movl $0x78, %esi
callq 0x3360
movq -0x8a0(%rbp), %rdi
addq $0x38, %rdi
movq -0x840(%rbp), %rax
movq %rax, -0x890(%rbp)
movq -0x890(%rbp), %rsi
callq 0xa6a0
movq -0x8a0(%rbp), %rdi
movq %rax, -0x888(%rbp)
movq -0x888(%rbp), %rax
movq %rax, -0x840(%rbp)
addq $0x38, %rdi
callq 0x9e40
movq -0x8a0(%rbp), %rdi
movq %rax, -0x8d8(%rbp)
addq $0x70, %rdi
callq 0x9e60
movq %rax, %rcx
movq -0x8d8(%rbp), %rax
cmpq %rcx, %rax
jne 0x7c96
jmp 0x7cd5
leaq 0x113eb(%rip), %rdi     # 0x19088
leaq 0x11404(%rip), %rsi     # 0x190a8
movl $0x1ba, %edx            # imm = 0x1BA
leaq 0x11468(%rip), %rcx     # 0x19118
callq 0x3210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x878(%rbp)
movl %eax, -0x87c(%rbp)
leaq -0x870(%rbp), %rdi
callq 0x9ab0
jmp 0x7cfd
jmp 0x7cec
leaq -0x840(%rbp), %rdi
xorl %esi, %esi
callq 0xa6e0
movq %rax, -0x898(%rbp)
jmp 0x7af3
movl -0x24(%rbp), %eax
addq $0x8e0, %rsp            # imm = 0x8E0
popq %rbp
retq
movq -0x878(%rbp), %rdi
callq 0x3530
nopl (%rax)