// File: tenup-coin[P]seeder/dns.c
// Function: parse_name
int static parse_name(const unsigned char **inpos, const unsigned char *inend, const unsigned char *inbuf, char *buf, size_t bufsize) {
  size_t bufused = 0;
  int init = 1;
  do {
    if (*inpos == inend)
      return -1;
    // read length of next component
    int octet = *((*inpos)++);
    if (octet == 0) {
      buf[bufused] = 0;
      return 0;
    }
    // add dot in output
    if (!init) {
      if (bufused == bufsize-1)
        return -2;
      buf[bufused++] = '.';
    } else
      init = 0;
    // handle references
    if ((octet & 0xC0) == 0xC0) {
      if (*inpos == inend)
        return -1;
      int ref = ((octet - 0xC0) << 8) + *((*inpos)++);
      if (ref < 0 || ref >= (*inpos)-inbuf-2) return -1;
      const unsigned char *newbuf = inbuf + ref;
      return parse_name(&newbuf, (*inpos) - 2, inbuf, buf+bufused, bufsize-bufused);
    }
    if (octet > 63) return -1;
    // copy label
    while (octet) {
      if (*inpos == inend)
        return -1;
      if (bufused == bufsize-1)
        return -2;
      int c = *((*inpos)++);
      if (c == '.')
        return -1;
      octet--;
      buf[bufused++] = c;
    }
  } while(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x5c44
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e1f
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x5c79
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rbp)
jmp 0x5e1f
cmpl $0x0, -0x3c(%rbp)
jne 0x5cb5
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x5c9c
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5e1f
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb $0x2e, (%rax,%rcx)
jmp 0x5cbc
movl $0x0, -0x3c(%rbp)
movl -0x40(%rbp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x5d78
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x5ce8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e1f
movl -0x40(%rbp), %eax
subl $0xc0, %eax
shll $0x8, %eax
movq -0x10(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
movzbl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x5d2d
movslq -0x44(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq -0x20(%rbp), %rdx
subq %rdx, %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
jl 0x5d39
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e1f
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $-0x2, %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
subq -0x38(%rbp), %r8
leaq -0x50(%rbp), %rdi
callq 0x5c00
movl %eax, -0x4(%rbp)
jmp 0x5e1f
cmpl $0x3f, -0x40(%rbp)
jle 0x5d8a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e1f
jmp 0x5d8c
cmpl $0x0, -0x40(%rbp)
je 0x5e11
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x5da8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e1f
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x5dc2
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5e1f
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movzbl (%rax), %eax
movl %eax, -0x54(%rbp)
cmpl $0x2e, -0x54(%rbp)
jne 0x5de8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e1f
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x54(%rbp), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x38(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x5d8c
jmp 0x5e13
movb $0x1, %al
testb $0x1, %al
jne 0x5c2b
jmp 0x5e1f
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)