// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x1, %eax
jge 0x28afd
jmp 0x28aa9
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28adb
movl $0x3, %edi
leaq 0xf953(%rip), %rsi      # 0x38414
leaq 0xfca0(%rip), %rdx      # 0x38768
movl $0x274, %ecx            # imm = 0x274
leaq 0xf9a9(%rip), %r8       # 0x3847d
movb $0x0, %al
callq 0x243b0
jmp 0x28add
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x28e9f
movl -0x24(%rbp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x28c60
movl -0x24(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x1, %eax
jge 0x28ba6
jmp 0x28b52
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28b84
movl $0x3, %edi
leaq 0xf8aa(%rip), %rsi      # 0x38414
leaq 0xfbf7(%rip), %rdx      # 0x38768
movl $0x27c, %ecx            # imm = 0x27C
leaq 0xf900(%rip), %r8       # 0x3847d
movb $0x0, %al
callq 0x243b0
jmp 0x28b86
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
orl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jl 0x28c22
jmp 0x28bce
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28c00
movl $0x3, %edi
leaq 0xf82e(%rip), %rsi      # 0x38414
leaq 0xfb7b(%rip), %rdx      # 0x38768
movl $0x280, %ecx            # imm = 0x280
leaq 0xfb82(%rip), %r8       # 0x3877b
movb $0x0, %al
callq 0x243b0
jmp 0x28c02
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x28(%rbp), %esi
leaq -0x40(%rbp), %rdi
xorl %edx, %edx
callq 0x2d6a0
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x28a70
movl %eax, -0x4(%rbp)
jmp 0x28f31
movl -0x24(%rbp), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
je 0x28cc7
jmp 0x28c6f
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28ca5
movl -0x24(%rbp), %r9d
movl $0x3, %edi
leaq 0xf789(%rip), %rsi      # 0x38414
leaq 0xfad6(%rip), %rdx      # 0x38768
movl $0x28a, %ecx            # imm = 0x28A
leaq 0xfafa(%rip), %r8       # 0x38798
movb $0x0, %al
callq 0x243b0
jmp 0x28ca7
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl -0x24(%rbp), %eax
jge 0x28d30
jmp 0x28cdc
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28d0e
movl $0x3, %edi
leaq 0xf720(%rip), %rsi      # 0x38414
leaq 0xfa6d(%rip), %rdx      # 0x38768
movl $0x28f, %ecx            # imm = 0x28F
leaq 0xf776(%rip), %r8       # 0x3847d
movb $0x0, %al
callq 0x243b0
jmp 0x28d10
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x2db40
cmpl -0x24(%rbp), %eax
je 0x28d9b
jmp 0x28d47
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28d79
movl $0x3, %edi
leaq 0xf6b5(%rip), %rsi      # 0x38414
leaq 0xfa02(%rip), %rdx      # 0x38768
movl $0x292, %ecx            # imm = 0x292
leaq 0xfa40(%rip), %r8       # 0x387b2
movb $0x0, %al
callq 0x243b0
jmp 0x28d7b
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x10(%rbp), %rdi
leaq 0x108ee(%rip), %rsi     # 0x39694
movl $0x2, %edx
callq 0x2d9e0
cmpl $0x2, %eax
je 0x28e0b
jmp 0x28db7
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28de9
movl $0x3, %edi
leaq 0xf645(%rip), %rsi      # 0x38414
leaq 0xf992(%rip), %rdx      # 0x38768
movl $0x297, %ecx            # imm = 0x297
leaq 0xf9d0(%rip), %r8       # 0x387b2
movb $0x0, %al
callq 0x243b0
jmp 0x28deb
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x2d6a0
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x1, %eax
jge 0x28e87
jmp 0x28e33
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28e65
movl $0x3, %edi
leaq 0xf5c9(%rip), %rsi      # 0x38414
leaq 0xf916(%rip), %rdx      # 0x38768
movl $0x29d, %ecx            # imm = 0x29D
leaq 0xf61f(%rip), %r8       # 0x3847d
movb $0x0, %al
callq 0x243b0
jmp 0x28e67
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x2e340
movl %eax, -0x24(%rbp)
jmp 0x28e9a
jmp 0x28b0e
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x28f24
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x2dc90
cmpl $0x1, %eax
je 0x28f11
jmp 0x28ec0
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x28ef2
movl $0x3, %edi
leaq 0xf53c(%rip), %rsi      # 0x38414
leaq 0xf889(%rip), %rdx      # 0x38768
movl $0x2a5, %ecx            # imm = 0x2A5
leaq 0xf8c7(%rip), %r8       # 0x387b2
movb $0x0, %al
callq 0x243b0
jmp 0x28ef4
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x28f31
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x2d6a0
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)