// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/lib/dns.c
// Function: dns_d_expand
size_t dns_d_expand(void *dst, size_t lim, unsigned short src, struct dns_packet *P, int *error) {
	size_t dstp	= 0;
	unsigned nptrs	= 0;
	unsigned char len;

	while (src < P->end) {
		switch ((0x03 & (P->data[src] >> 6))) {
		case 0x00:	/* FOLLOWS */
			len	= (0x3f & P->data[src]);

			if (0 == len) {
				if (dstp == 0) {
					if (dstp < lim)
						((unsigned char *)dst)[dstp]	= '.';

					dstp++;
				}

				/* NUL terminate */
				if (lim > 0)
					((unsigned char *)dst)[DNS_PP_MIN(dstp, lim - 1)]	= '\0';

/* success ==> */		return dstp;
			}

			src++;

			if (P->end - src < len)
				goto toolong;

			if (dstp < lim)
				memcpy(&((unsigned char *)dst)[dstp], &P->data[src], DNS_PP_MIN(len, lim - dstp));

			src	+= len;
			dstp	+= len;

			if (dstp < lim)
				((unsigned char *)dst)[dstp]	= '.';

			dstp++;

			nptrs	= 0;

			continue;
		case 0x01:	/* RESERVED */
			goto reserved;
		case 0x02:	/* RESERVED */
			goto reserved;
		case 0x03:	/* POINTER */
			if (++nptrs > DNS_D_MAXPTRS)
				goto toolong;

			if (P->end - src < 2)
				goto toolong;

			src	= ((0x3f & P->data[src + 0]) << 8)
				| ((0xff & P->data[src + 1]) << 0);

			continue;
		} /* switch() */
	} /* while() */

toolong:
	*error	= DNS_EILLEGAL;

	if (lim > 0)
		((unsigned char *)dst)[DNS_PP_MIN(dstp, lim - 1)]	= '\0';

	return 0;
reserved:
	*error	= DNS_EILLEGAL;

	if (lim > 0)
		((unsigned char *)dst)[DNS_PP_MIN(dstp, lim - 1)]	= '\0';

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movzwl -0x1a(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jae 0x346b3
movq -0x28(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
movzbl 0x5c(%rax,%rcx), %eax
shrl $0x6, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x3, %eax
ja 0x346ae
movq -0x48(%rbp), %rax
leaq 0x159f3(%rip), %rcx     # 0x49ec0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
movzbl 0x5c(%rax,%rcx), %eax
andl $0x3f, %eax
movb %al, -0x3d(%rbp)
movzbl -0x3d(%rbp), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3456b
cmpq $0x0, -0x38(%rbp)
jne 0x3451c
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x34510
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x2e, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jbe 0x3455e
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x34546
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x34552
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3476e
movw -0x1a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1a(%rbp)
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movzwl -0x1a(%rbp), %ecx
subq %rcx, %rax
movzbl -0x3d(%rbp), %ecx
cmpq %rcx, %rax
jae 0x34594
jmp 0x346b5
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x345f5
movq -0x10(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
addq $0x5c, %rax
movzwl -0x1a(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movzbl -0x3d(%rbp), %eax
movq -0x18(%rbp), %rcx
subq -0x38(%rbp), %rcx
cmpq %rcx, %rax
jae 0x345d8
movzbl -0x3d(%rbp), %eax
movq %rax, -0x70(%rbp)
jmp 0x345e4
movq -0x18(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rdx
callq 0xfb40
movzbl -0x3d(%rbp), %ecx
movzwl -0x1a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1a(%rbp)
movzbl -0x3d(%rbp), %eax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x34625
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x2e, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
jmp 0x34491
jmp 0x3470b
jmp 0x3470b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x7f, %eax
jbe 0x34657
jmp 0x346b5
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movzwl -0x1a(%rbp), %ecx
subq %rcx, %rax
cmpq $0x2, %rax
jae 0x3466e
jmp 0x346b5
movq -0x28(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzbl 0x5c(%rax,%rcx), %eax
andl $0x3f, %eax
shll $0x8, %eax
movq -0x28(%rbp), %rcx
movzwl -0x1a(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movzbl 0x5c(%rcx,%rdx), %ecx
andl $0xff, %ecx
shll $0x0, %ecx
orl %ecx, %eax
movw %ax, -0x1a(%rbp)
jmp 0x34491
jmp 0x34491
jmp 0x346b5
movq -0x30(%rbp), %rax
movl $0x9b918cc1, (%rax)     # imm = 0x9B918CC1
cmpq $0x0, -0x18(%rbp)
jbe 0x34701
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x346e9
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x346f5
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq $0x0, -0x8(%rbp)
jmp 0x3476e
movq -0x30(%rbp), %rax
movl $0x9b918cc1, (%rax)     # imm = 0x9B918CC1
cmpq $0x0, -0x18(%rbp)
jbe 0x34766
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x34745
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x34754
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)