// File: /workspace/github_c_makefile_star2_O1/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 0x1b2d2
movq %r14, %rdi
movl $0x1, %esi
callq 0x1dd7b
testl %eax, %eax
jle 0x1b29a
movl %eax, %ebp
leaq 0xac45(%rip), %r15      # 0x25e64
testb $-0x40, %bpl
jne 0x1b320
movl 0x8(%r14), %eax
subl 0xc(%r14), %eax
cmpl %ebp, %eax
jl 0x1b3c5
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1d878
cmpl %ebp, %eax
jne 0x1b3f9
movq %rbx, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x1d7ad
cmpl $0x2, %eax
jne 0x1b42d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x1d619
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jle 0x1b495
movq %r14, %rdi
movl $0x1, %esi
callq 0x1dd7b
movl %eax, %ebp
testl %eax, %eax
jg 0x1b21f
cmpq $0x0, (%rbx)
jne 0x1b2ca
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1d916
cmpl $0x1, %eax
jne 0x1b461
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x1d619
movl 0xc(%rbx), %eax
subl %r12d, %eax
jmp 0x1b311
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x98ef(%rip), %rsi      # 0x24bd4
leaq 0x9c3c(%rip), %rdx      # 0x24f28
leaq 0x994a(%rip), %r8       # 0x24c3d
movl $0x3, %edi
movl $0x274, %ecx            # imm = 0x274
xorl %eax, %eax
callq 0x17d92
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 0x1b387
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jle 0x1b4c9
andl $0x3f, %ebp
shll $0x8, %ebp
movq %r14, %rdi
movl $0x1, %esi
callq 0x1dd7b
orl %ebp, %eax
cmpl 0x8(%r14), %eax
jge 0x1b4fd
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 0x1d619
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1b1db
jmp 0x1b311
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x9836(%rip), %rsi      # 0x24bd4
leaq 0x9b83(%rip), %rdx      # 0x24f28
leaq 0x9bac(%rip), %r8       # 0x24f58
movl $0x3, %edi
movl $0x28a, %ecx            # imm = 0x28A
movl %ebp, %r9d
xorl %eax, %eax
callq 0x17d92
jmp 0x1b304
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x97f8(%rip), %rsi      # 0x24bd4
leaq 0x9b45(%rip), %rdx      # 0x24f28
leaq 0x9853(%rip), %r8       # 0x24c3d
movl $0x3, %edi
movl $0x28f, %ecx            # imm = 0x28F
jmp 0x1b2fd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x97c4(%rip), %rsi      # 0x24bd4
leaq 0x9b11(%rip), %rdx      # 0x24f28
leaq 0x9b54(%rip), %r8       # 0x24f72
movl $0x3, %edi
movl $0x292, %ecx            # imm = 0x292
jmp 0x1b2fd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x9790(%rip), %rsi      # 0x24bd4
leaq 0x9add(%rip), %rdx      # 0x24f28
leaq 0x9b20(%rip), %r8       # 0x24f72
movl $0x3, %edi
movl $0x297, %ecx            # imm = 0x297
jmp 0x1b2fd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x975c(%rip), %rsi      # 0x24bd4
leaq 0x9aa9(%rip), %rdx      # 0x24f28
leaq 0x9aec(%rip), %r8       # 0x24f72
movl $0x3, %edi
movl $0x2a5, %ecx            # imm = 0x2A5
jmp 0x1b2fd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x9728(%rip), %rsi      # 0x24bd4
leaq 0x9a75(%rip), %rdx      # 0x24f28
leaq 0x9783(%rip), %r8       # 0x24c3d
movl $0x3, %edi
movl $0x29d, %ecx            # imm = 0x29D
jmp 0x1b2fd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x96f4(%rip), %rsi      # 0x24bd4
leaq 0x9a41(%rip), %rdx      # 0x24f28
leaq 0x974f(%rip), %r8       # 0x24c3d
movl $0x3, %edi
movl $0x27c, %ecx            # imm = 0x27C
jmp 0x1b2fd
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x1b304
leaq 0x96c0(%rip), %rsi      # 0x24bd4
leaq 0x9a0d(%rip), %rdx      # 0x24f28
leaq 0x9a19(%rip), %r8       # 0x24f3b
movl $0x3, %edi
movl $0x280, %ecx            # imm = 0x280
jmp 0x1b2fd