// File: davidgfnet[P]tadns/tadns_common.cc
// Function: fetch(unsigned char const*, unsigned char const*, int, char*, int)
unsigned fetch(const uint8_t *pkt, const uint8_t *s, int pktsiz, char *dst, int dstlen) {
    const uint8_t *e = pkt + pktsiz;
    unsigned skip = 0;
    bool labelj = false;
    int j, i = 0, n = 0;

    while (*s != 0 && s < e) {
        if (n > 0)
            dst[i++] = '.';

        if (i >= dstlen)
            break;

        if (((n = *s++) & 0xc0) == 0xc0) {
            s = pkt + (((n&3) << 8) | *s);    /* New offset */
            n = 0;
            if (!labelj)
                skip += 2;
            labelj = true;
        } else {
            if (!labelj)
                skip += std::min(n, dstlen - i) + 1;
            for (j = 0; j < n && i < dstlen; j++)
                dst[i++] = *s++;
        }
    }

    dst[i] = '\0';
    return skip + (labelj ? 0 : 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movb $0x0, -0x35(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x17022
movq -0x10(%rbp), %rax
cmpq -0x30(%rbp), %rax
setb %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x1702e
jmp 0x1713f
cmpl $0x0, -0x44(%rbp)
jle 0x1704a
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x40(%rbp)
movslq %ecx, %rcx
movb $0x2e, (%rax,%rcx)
movl -0x40(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x17057
jmp 0x1713f
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x44(%rbp)
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x170b7
movq -0x8(%rbp), %rax
movl -0x44(%rbp), %ecx
andl $0x3, %ecx
shll $0x8, %ecx
movq -0x10(%rbp), %rdx
movzbl (%rdx), %edx
orl %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x44(%rbp)
testb $0x1, -0x35(%rbp)
jne 0x170ae
movl -0x34(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movb $0x1, -0x35(%rbp)
jmp 0x1713a
testb $0x1, -0x35(%rbp)
jne 0x170de
movl -0x24(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x44(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x18110
movl (%rax), %eax
addl $0x1, %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x44(%rbp), %ecx
movb %al, -0x4a(%rbp)
jge 0x170fe
movl -0x40(%rbp), %eax
cmpl -0x24(%rbp), %eax
setl %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
testb $0x1, %al
jne 0x17107
jmp 0x17138
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %dl
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x40(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x170e5
jmp 0x1713a
jmp 0x17003
movq -0x20(%rbp), %rax
movslq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x34(%rbp), %eax
movb -0x35(%rbp), %sil
movl $0x1, %ecx
xorl %edx, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
addl %ecx, %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)