// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc(%rsi), %r13d
movl 0xc(%rdi), %r12d
cmpl %r13d, 0x8(%rsi)
jle 0x1ab10
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d588
testl %eax, %eax
jle 0x1aad8
movl %eax, %ebp
leaq 0xb449(%rip), %r15      # 0x25ea6
testb $-0x40, %bpl
jne 0x1ab5e
movl 0x8(%r14), %eax
subl 0xc(%r14), %eax
cmpl %ebp, %eax
jl 0x1ac03
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1d05f
cmpl %ebp, %eax
jne 0x1ac37
movq %rbx, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x1cf7d
cmpl $0x2, %eax
jne 0x1ac6b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x1cde9
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jle 0x1acd3
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d588
movl %eax, %ebp
testl %eax, %eax
jg 0x1aa5d
cmpq $0x0, (%rbx)
jne 0x1ab08
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1d115
cmpl $0x1, %eax
jne 0x1ac9f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x1cde9
movl 0xc(%rbx), %eax
subl %r12d, %eax
jmp 0x1ab4f
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0xa0c1(%rip), %rsi      # 0x24be4
leaq 0xa40e(%rip), %rdx      # 0x24f38
leaq 0xa11c(%rip), %r8       # 0x24c4d
movl $0x3, %edi
movl $0x274, %ecx            # imm = 0x274
xorl %eax, %eax
callq 0x1771e
movl %r13d, 0xc(%r14)
movl %r12d, 0xc(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x1abc5
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jle 0x1ad07
andl $0x3f, %ebp
shll $0x8, %ebp
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d588
orl %ebp, %eax
cmpl 0x8(%r14), %eax
jge 0x1ad3b
movq 0x10(%r14), %rcx
movq %rsp, %r15
movq %rcx, 0x10(%r15)
movups (%r14), %xmm0
movaps %xmm0, (%r15)
movq %r15, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1cde9
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1aa19
jmp 0x1ab4f
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0xa008(%rip), %rsi      # 0x24be4
leaq 0xa355(%rip), %rdx      # 0x24f38
leaq 0xa37e(%rip), %r8       # 0x24f68
movl $0x3, %edi
movl $0x28a, %ecx            # imm = 0x28A
movl %ebp, %r9d
xorl %eax, %eax
callq 0x1771e
jmp 0x1ab42
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9fca(%rip), %rsi      # 0x24be4
leaq 0xa317(%rip), %rdx      # 0x24f38
leaq 0xa025(%rip), %r8       # 0x24c4d
movl $0x3, %edi
movl $0x28f, %ecx            # imm = 0x28F
jmp 0x1ab3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9f96(%rip), %rsi      # 0x24be4
leaq 0xa2e3(%rip), %rdx      # 0x24f38
leaq 0xa326(%rip), %r8       # 0x24f82
movl $0x3, %edi
movl $0x292, %ecx            # imm = 0x292
jmp 0x1ab3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9f62(%rip), %rsi      # 0x24be4
leaq 0xa2af(%rip), %rdx      # 0x24f38
leaq 0xa2f2(%rip), %r8       # 0x24f82
movl $0x3, %edi
movl $0x297, %ecx            # imm = 0x297
jmp 0x1ab3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9f2e(%rip), %rsi      # 0x24be4
leaq 0xa27b(%rip), %rdx      # 0x24f38
leaq 0xa2be(%rip), %r8       # 0x24f82
movl $0x3, %edi
movl $0x2a5, %ecx            # imm = 0x2A5
jmp 0x1ab3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9efa(%rip), %rsi      # 0x24be4
leaq 0xa247(%rip), %rdx      # 0x24f38
leaq 0x9f55(%rip), %r8       # 0x24c4d
movl $0x3, %edi
movl $0x29d, %ecx            # imm = 0x29D
jmp 0x1ab3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9ec6(%rip), %rsi      # 0x24be4
leaq 0xa213(%rip), %rdx      # 0x24f38
leaq 0x9f21(%rip), %r8       # 0x24c4d
movl $0x3, %edi
movl $0x27c, %ecx            # imm = 0x27C
jmp 0x1ab3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x1ab42
leaq 0x9e92(%rip), %rsi      # 0x24be4
leaq 0xa1df(%rip), %rdx      # 0x24f38
leaq 0xa1eb(%rip), %r8       # 0x24f4b
movl $0x3, %edi
movl $0x280, %ecx            # imm = 0x280
jmp 0x1ab3b