// File: davidgfnet[P]tadns/tadns.cc
// Function: callback(dns_cb_data*)
static void callback(struct dns_cb_data *cbd) {
    inflight--;
    stillrunning.erase(cbd->name);

    switch (cbd->error) {
    case DNS_OK:
        printf("DNS response for [%s]\n", cbd->name.c_str());
        for (auto rec: cbd->replies) {
            const unsigned char *addr = (unsigned char*)rec.addr.data();
            const unsigned char *name = (unsigned char*)rec.name.data();

            switch (rec.rtype) {
            case DNS_A_RECORD:
                printf("%s A %u.%u.%u.%u\n", name,
                    addr[0], addr[1],
                    addr[2], addr[3]);
                break;
            case DNS_MX_RECORD:
                printf("%s MX %s\n", name, addr);
                break;
            case DNS_CNAME_RECORD:
                printf("%s CNAME %s\n", name, addr);
                break;
            case DNS_NS_RECORD:
                printf("%s NS %s\n", name, addr);
                break;
            default:
                printf("Other Record %s %d\n", name, rec.rtype);
                break;
            }
        }
        break;
    case DNS_TIMEOUT:
        printf("Query timeout for [%s]\n", cbd->name.c_str());
        break;
    case DNS_DOES_NOT_EXIST:
        printf("No such address: [%s]\n", cbd->name.c_str());
        break;
    case DNS_NET_ERROR:
        printf("Network error: [%s]\n", cbd->name.c_str());
        break;
    case DNS_ERROR:
        printf("System error occured\n");
        break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl 0x20ef7(%rip), %eax     # 0x2830c
decl %eax
movl %eax, 0x20eef(%rip)     # 0x2830c
movq -0x8(%rbp), %rsi
addq $0x10, %rsi
leaq 0x20ee4(%rip), %rdi     # 0x28310
callq 0xe340
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x98(%rbp)
subq $0x4, %rax
ja 0x7653
movq -0x98(%rbp), %rax
leaq 0x12bad(%rip), %rcx     # 0x1a004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
callq 0x3130
movq %rax, %rsi
leaq 0x12f34(%rip), %rdi     # 0x1a3ab
movb $0x0, %al
callq 0x3050
movq -0x8(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8510
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8540
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x8570
testb $0x1, %al
jne 0x74ba
jmp 0x75e3
leaq -0x18(%rbp), %rdi
callq 0x85b0
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0xe370
leaq -0x48(%rbp), %rdi
callq 0x31a0
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x31a0
movq %rax, -0x80(%rbp)
movl -0x70(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xa0(%rbp)
subl $0xe, %eax
ja 0x75b3
movq -0xa0(%rbp), %rax
leaq 0x12b0a(%rip), %rcx     # 0x1a018
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rax
movzbl (%rax), %edx
movzbl 0x1(%rax), %ecx
movzbl 0x2(%rax), %r8d
movzbl 0x3(%rax), %r9d
leaq 0x12e8b(%rip), %rdi     # 0x1a3c2
xorl %eax, %eax
callq 0x3050
jmp 0x7540
jmp 0x75cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xe3f0
jmp 0x765c
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq 0x12e60(%rip), %rdi     # 0x1a3d4
xorl %eax, %eax
callq 0x3050
jmp 0x757d
jmp 0x75cc
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq 0x12e50(%rip), %rdi     # 0x1a3de
xorl %eax, %eax
callq 0x3050
jmp 0x7597
jmp 0x75cc
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq 0x12e43(%rip), %rdi     # 0x1a3eb
xorl %eax, %eax
callq 0x3050
jmp 0x75b1
jmp 0x75cc
movq -0x80(%rbp), %rsi
movl -0x70(%rbp), %edx
leaq 0x12e34(%rip), %rdi     # 0x1a3f5
xorl %eax, %eax
callq 0x3050
jmp 0x75ca
jmp 0x75cc
leaq -0x70(%rbp), %rdi
callq 0xe3f0
leaq -0x18(%rbp), %rdi
callq 0x8610
jmp 0x74a4
jmp 0x7653
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
callq 0x3130
movq %rax, %rsi
leaq 0x12e0d(%rip), %rdi     # 0x1a409
movb $0x0, %al
callq 0x3050
jmp 0x7653
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
callq 0x3130
movq %rax, %rsi
leaq 0x12e05(%rip), %rdi     # 0x1a421
movb $0x0, %al
callq 0x3050
jmp 0x7653
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
callq 0x3130
movq %rax, %rsi
leaq 0x12dfc(%rip), %rdi     # 0x1a438
movb $0x0, %al
callq 0x3050
jmp 0x7653
leaq 0x12e01(%rip), %rdi     # 0x1a44d
movb $0x0, %al
callq 0x3050
addq $0xa0, %rsp
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x3510
nopl (%rax,%rax)