// File: /workspace/github_cpp_makefile_star2_O2/davidgfnet[P]tadns/tadns_common.cc
// Function: parse_udp_packet(unsigned char const*, int)
struct dns_packet parse_udp_packet(const uint8_t *pkt, int len) {
    const uint8_t *e = pkt + len;
    struct header *h = (struct header*)pkt;

    struct dns_packet ret;
    ret.header.tid      = ntohs(h->tid);
    ret.header.flags    = ntohs(h->flags);
    ret.header.nqueries = ntohs(h->nqueries);
    ret.header.nanswers = ntohs(h->nanswers);
    ret.header.nauth    = ntohs(h->nauth);
    ret.header.nother   = ntohs(h->nother);

    const uint8_t *p = &h->data[0];

    for (unsigned i = 0; i < ret.header.nqueries; i++) {
        char name[1025];
        p += fetch(pkt, p, len, name, sizeof(name) - 1);

        if (p + 4 > e) return ret;

        struct dns_question q;
        q.qtype  = ntohs(((uint16_t*)p)[0]);
        q.qclass = ntohs(((uint16_t*)p)[1]);
        q.name = std::string(name);
        std::transform(q.name.begin(), q.name.end(), q.name.begin(), ::tolower);
        p += 4;

        ret.questions.push_back(q);
    }

    p = parse_answer(pkt, len, p, ret.header.nanswers, ret.answers, RESPONSE_ANSWER);
    p = parse_answer(pkt, len, p, ret.header.nauth,    ret.answers, RESPONSE_AUTHORITATIVE);
    p = parse_answer(pkt, len, p, ret.header.nother,   ret.answers, RESPONSE_ADDITIONAL);

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movl %edx, %ebx
movq %rsi, %r13
movslq %edx, %rax
addq %rsi, %rax
movq %rax, 0x58(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq (%rsi), %xmm0
movdqa %xmm0, %xmm1
psrlw $0x8, %xmm1
psllw $0x8, %xmm0
por %xmm1, %xmm0
movq %xmm0, (%rdi)
movzwl 0x8(%rsi), %eax
rolw $0x8, %ax
movw %ax, 0x8(%rdi)
movzwl 0xa(%rsi), %eax
rolw $0x8, %ax
leaq 0x10(%rdi), %rcx
movq %rcx, 0x50(%rsp)
movw %ax, 0xa(%rdi)
leaq 0xc(%rsi), %r15
leaq 0x28(%rsp), %r12
pextrw $0x2, %xmm0, %eax
xorl %r14d, %r14d
leaq 0x80(%rsp), %rbp
movq %rdi, 0x10(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x1c(%rsp)
movzwl %ax, %eax
cmpl %eax, %r14d
jae 0x8e7a
movq %r13, %rdi
movq %r15, %rsi
movl %ebx, %edx
movq %rbp, %r13
movq %rbp, %rcx
movl $0x400, %r8d            # imm = 0x400
callq 0x896c
movl %eax, %eax
leaq (%r15,%rax), %rbx
addq $0x4, %rbx
cmpq 0x58(%rsp), %rbx
ja 0x8ecf
addq %rax, %r15
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movzwl (%r15), %eax
rolw $0x8, %ax
movw %ax, 0x20(%rsp)
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x22(%rsp)
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r13, %rbp
movq %r13, %rsi
leaq 0xf(%rsp), %rdx
callq 0x61b8
movq %r12, %rdi
movq %r15, %rsi
callq 0x3320
movq %r15, %rdi
callq 0x3140
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r12
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x8e41
movsbl (%r15,%r13), %edi
callq 0x3390
movb %al, (%r15,%r13)
incq %r13
jmp 0x8e29
movq 0x50(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3a1a
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x3140
incl %r14d
movq 0x10(%rsp), %rax
movzwl 0x4(%rax), %eax
movq %rbx, %r15
movl 0x1c(%rsp), %ebx
movq 0x48(%rsp), %r13
jmp 0x8d84
movq 0x10(%rsp), %r14
movzwl 0x6(%r14), %ecx
leaq 0x28(%r14), %r12
movq %r13, %rdi
movl %ebx, %esi
movq %r15, %rdx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x8a38
movzwl 0x8(%r14), %ecx
pushq $0x1
popq %r9
movq %r13, %rdi
movl %ebx, %esi
movq %rax, %rdx
movq %r12, %r8
callq 0x8a38
movzwl 0xa(%r14), %ecx
pushq $0x2
popq %r9
movq %r13, %rdi
movl %ebx, %esi
movq %rax, %rdx
movq %r12, %r8
callq 0x8a38
jmp 0x8ed4
movq 0x10(%rsp), %r14
movq %r14, %rax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x8efd
jmp 0x8ef0
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x3140
movq 0x10(%rsp), %rdi
callq 0x3a46
movq %r14, %rdi
callq 0x33f0