// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movzwl (%rsi), %eax
rolw $0x8, %ax
movw %ax, (%rdi)
movzwl 0x2(%rsi), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rdi)
movzwl 0x4(%rsi), %eax
rolw $0x8, %ax
movw %ax, 0x4(%rdi)
movzwl 0x6(%rsi), %ecx
rolw $0x8, %cx
movw %cx, 0x6(%rdi)
movzwl 0x8(%rsi), %ecx
rolw $0x8, %cx
movw %cx, 0x8(%rdi)
movzwl 0xa(%rsi), %ecx
rolw $0x8, %cx
movw %cx, 0xa(%rdi)
leaq 0xc(%rsi), %rdx
xorl %ebp, %ebp
testw %ax, %ax
setne %sil
movq %rdi, 0x48(%rsp)
je 0x9bf9
movslq %r15d, %rax
addq %r13, %rax
movq %rax, 0x58(%rsp)
leaq 0x80(%rsp), %rcx
leaq 0x60(%rsp), %r12
movq $0x0, 0x10(%rsp)
movl %r15d, 0x1c(%rsp)
movq %r13, 0x50(%rsp)
movb %sil, 0x7(%rsp)
movq %rdx, %r14
movq %r13, %rdi
movq %rdx, %rsi
movl %r15d, %r13d
movl %r15d, %edx
movl $0x400, %r8d            # imm = 0x400
movq %rcx, %r15
callq 0x956c
movl %eax, %eax
leaq (%r14,%rax), %rdx
addq %rax, %r14
addq $0x4, %r14
cmpq 0x58(%rsp), %r14
jbe 0x9aef
movb $0x1, %al
movq %rax, 0x10(%rsp)
movl %r13d, %r15d
movq 0x50(%rsp), %r13
jmp 0x9bd6
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movzwl (%rdx), %eax
rolw $0x8, %ax
movw %ax, 0x20(%rsp)
movzwl 0x2(%rdx), %eax
rolw $0x8, %ax
movw %ax, 0x22(%rsp)
leaq 0x70(%rsp), %rbx
movq %rbx, 0x60(%rsp)
movq %r15, %rdi
callq 0x3140
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x85b8
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x3340
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x9b71
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x30(%rsp), %rbx
testq %rbx, %rbx
je 0x9b99
movq 0x28(%rsp), %r15
xorl %r13d, %r13d
movsbl (%r15,%r13), %edi
callq 0x3390
movb %al, (%r15,%r13)
incq %r13
cmpq %r13, %rbx
jne 0x9b83
movq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3b40
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
movq 0x48(%rsp), %rbx
movl 0x1c(%rsp), %r15d
movq 0x50(%rsp), %r13
je 0x9bd3
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %r14, %rdx
cmpq 0x58(%rsp), %r14
ja 0x9c04
incl %ebp
movzwl 0x4(%rbx), %eax
cmpl %eax, %ebp
setb %sil
leaq 0x80(%rsp), %rcx
jb 0x9aa5
jmp 0x9c09
movq $0x0, 0x10(%rsp)
jmp 0x9c09
movb 0x7(%rsp), %sil
testb $0x1, %sil
je 0x9c2b
testb $0x1, 0x10(%rsp)
jne 0x9c7a
leaq 0x28(%rbx), %rdi
callq 0x3b82
movq 0x8(%rsp), %rdi
callq 0x3bb2
jmp 0x9c7a
movzwl 0x6(%rbx), %ecx
leaq 0x28(%rbx), %r12
movq %r13, %rdi
movl %r15d, %esi
movq %r12, %r8
xorl %r9d, %r9d
callq 0x9674
movzwl 0x8(%rbx), %ecx
movq %r13, %rdi
movl %r15d, %esi
movq %rax, %rdx
movq %r12, %r8
movl $0x1, %r9d
callq 0x9674
movzwl 0xa(%rbx), %ecx
movq %r13, %rdi
movl %r15d, %esi
movq %rax, %rdx
movq %r12, %r8
movl $0x2, %r9d
callq 0x9674
movq %rbx, %rax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x9cb5
jmp 0x9c96
movq %rax, %r15
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x9cb5
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x48(%rsp), %rdi
addq $0x28, %rdi
callq 0x3b82
movq 0x8(%rsp), %rdi
callq 0x3bb2
movq %r15, %rdi
callq 0x3400