// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]dohclient/src/ns_msg.c
// Function: ns_read_domainname
static int ns_read_domainname(stream_t *dst, stream_t *s)
{
	int spos = s->pos, dpos = dst->pos, len;

#define do_return(r) \
	s->pos = spos; \
	dst->pos = dpos; \
	return (r);

#define check_len(n) \
	if (stream_rsize(s) < (n)) { \
		loge("truncated stream\n"); \
		do_return(-1); \
	}

	check_len(1);
	len = stream_readi8(s);

	while (len > 0) {

		if ((len & 0xc0) == 0xc0) { /* compression pointer */
			int offset = (len & 0x3f);
			offset <<= 8;
			check_len(1);
			len = stream_readi8(s);
			offset |= len;
			if (offset >= s->size) {
				loge("invalid compression pointer\n");
				do_return(-1);
			}
			else {
				stream_t ns = *s;
				stream_seek(&ns, offset, SEEK_SET);
				return ns_read_domainname(dst, &ns);
			}
		}
		else if ((len & 0xc0)) {
			loge("invalid label len '0x%x'\n", len);
			do_return(-1);
		}
		else {

			check_len(len);

			if (stream_writess(dst, s, len) != len) {
				loge("write stream\n");
				do_return(-1);
			}

			if (stream_write(dst, ".", 2) != 2) {
				loge("write stream\n");
				do_return(-1);
			}

			stream_seek(dst, -1, SEEK_CUR);

			check_len(1);
			len = stream_readi8(s);
		}
	}

	if (dst->array == NULL) {

		if (stream_writei8(dst, 0) != 1) {
			loge("write stream\n");
			do_return(-1);
		}

		stream_seek(dst, -1, SEEK_CUR);
	}

#undef check_len
#undef do_return

	return dst->pos - dpos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc(%rsi), %r15d
movl 0xc(%rdi), %ebp
cmpl %r15d, 0x8(%rsi)
jle 0x1986c
movl %r15d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
pushq $0x1
popq %r12
pushq $0x2
popq %rbp
pushq $-0x1
popq %r13
movq %r14, %rdi
movl %r12d, %esi
callq 0x1bfb1
testl %eax, %eax
jle 0x19925
movl %eax, %r15d
testb $-0x40, %r15b
jne 0x198ac
movl 0x8(%r14), %eax
subl 0xc(%r14), %eax
cmpl %r15d, %eax
jl 0x1999b
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x1bb15
cmpl %r15d, %eax
jne 0x199c6
movq %rbx, %rdi
leaq 0xa682(%rip), %rsi      # 0x23e94
movl %ebp, %edx
callq 0x1ba37
cmpl $0x2, %eax
jne 0x199f1
movq %rbx, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x1b8c3
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jg 0x197c0
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19a21
leaq 0x93b3(%rip), %rsi      # 0x22c04
leaq 0x9700(%rip), %rdx      # 0x22f58
leaq 0x940e(%rip), %r8       # 0x22c6d
pushq $0x3
popq %rdi
movl $0x29d, %ecx            # imm = 0x29D
jmp 0x19a1a
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x1989c
leaq 0x9385(%rip), %rsi      # 0x22c04
leaq 0x96d2(%rip), %rdx      # 0x22f58
leaq 0x93e0(%rip), %r8       # 0x22c6d
pushq $0x3
popq %rdi
movl $0x274, %ecx            # imm = 0x274
xorl %eax, %eax
callq 0x1662e
movl %r15d, 0xc(%r14)
movl %ebp, 0xc(%rbx)
pushq $-0x1
popq %r13
jmp 0x19ac6
movl %r15d, %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
movl 0xc(%rsp), %ebp
jne 0x1995f
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jle 0x19a35
andl $0x3f, %r15d
shll $0x8, %r15d
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x1bfb1
orl %r15d, %eax
cmpl 0x8(%r14), %eax
jge 0x19a60
movq 0x10(%r14), %rcx
leaq 0x10(%rsp), %r15
movq %rcx, 0x10(%r15)
movups (%r14), %xmm0
movaps %xmm0, (%r15)
movq %r15, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1b8c3
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19787
movl %eax, %r13d
jmp 0x19ac6
cmpq $0x0, (%rbx)
movl 0xc(%rsp), %ebp
jne 0x19953
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1bbcd
cmpl $0x1, %eax
jne 0x19a8b
pushq $-0x1
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x1b8c3
movl 0xc(%rbx), %r13d
subl %ebp, %r13d
jmp 0x19ac6
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19abb
leaq 0x928e(%rip), %rsi      # 0x22c04
leaq 0x95db(%rip), %rdx      # 0x22f58
leaq 0x9604(%rip), %r8       # 0x22f88
pushq $0x3
popq %rdi
movl $0x28a, %ecx            # imm = 0x28A
movl %r15d, %r9d
xorl %eax, %eax
callq 0x1662e
jmp 0x19abb
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19a21
leaq 0x9256(%rip), %rsi      # 0x22c04
leaq 0x95a3(%rip), %rdx      # 0x22f58
leaq 0x92b1(%rip), %r8       # 0x22c6d
pushq $0x3
popq %rdi
movl $0x28f, %ecx            # imm = 0x28F
jmp 0x19a1a
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19a21
leaq 0x922b(%rip), %rsi      # 0x22c04
leaq 0x9578(%rip), %rdx      # 0x22f58
leaq 0x95bb(%rip), %r8       # 0x22fa2
pushq $0x3
popq %rdi
movl $0x292, %ecx            # imm = 0x292
jmp 0x19a1a
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19a21
leaq 0x9200(%rip), %rsi      # 0x22c04
leaq 0x954d(%rip), %rdx      # 0x22f58
leaq 0x9590(%rip), %r8       # 0x22fa2
pushq $0x3
popq %rdi
movl $0x297, %ecx            # imm = 0x297
xorl %eax, %eax
callq 0x1662e
movl 0x8(%rsp), %eax
movl %eax, 0xc(%r14)
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rbx)
jmp 0x19ac6
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19abb
leaq 0x91bc(%rip), %rsi      # 0x22c04
leaq 0x9509(%rip), %rdx      # 0x22f58
leaq 0x9217(%rip), %r8       # 0x22c6d
pushq $0x3
popq %rdi
movl $0x27c, %ecx            # imm = 0x27C
jmp 0x19ab4
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19abb
leaq 0x9191(%rip), %rsi      # 0x22c04
leaq 0x94de(%rip), %rdx      # 0x22f58
leaq 0x94ea(%rip), %r8       # 0x22f6b
pushq $0x3
popq %rdi
movl $0x280, %ecx            # imm = 0x280
jmp 0x19ab4
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x19abb
leaq 0x9166(%rip), %rsi      # 0x22c04
leaq 0x94b3(%rip), %rdx      # 0x22f58
leaq 0x94f6(%rip), %r8       # 0x22fa2
pushq $0x3
popq %rdi
movl $0x2a5, %ecx            # imm = 0x2A5
xorl %eax, %eax
callq 0x1662e
movl 0x8(%rsp), %eax
movl %eax, 0xc(%r14)
movl %ebp, 0xc(%rbx)
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq