// File: /workspace/github_c_makefile_star2_O1/wahern[P]cqueues/src/lib/dns.c
// Function: dns_d_comp
size_t dns_d_comp(void *dst_, size_t lim, const void *src_, size_t len, struct dns_packet *P, int *error) {
	struct { unsigned char *b; size_t p, x; } dst, src;
	unsigned char ch	= '.';

	dst.b	= dst_;
	dst.p	= 0;
	dst.x	= 1;

	src.b	= (unsigned char *)src_;
	src.p	= 0;
	src.x	= 0;

	while (src.x < len) {
		ch	= src.b[src.x];

		if (ch == '.') {
			if (dst.p < lim)
				dst.b[dst.p]	= (0x3f & (src.x - src.p));

			dst.p	= dst.x++;
			src.p	= ++src.x;
		} else {
			if (dst.x < lim)
				dst.b[dst.x]	= ch;

			dst.x++;
			src.x++;
		}
	} /* while() */

	if (src.x > src.p) {
		if (dst.p < lim)
			dst.b[dst.p]	= (0x3f & (src.x - src.p));

		dst.p	= dst.x;
	}

	if (dst.p > 1) {
		if (dst.p < lim)
			dst.b[dst.p]	= 0x00;

		dst.p++;
	}

#if 1
	if (dst.p < lim) {
		struct { unsigned char label[DNS_D_MAXLABEL + 1]; size_t len; unsigned short p, x, y; } a, b;
		unsigned i;

		a.p	= 0;

		while ((a.len = dns_l_expand(a.label, sizeof a.label, a.p, &a.x, dst.b, lim))) {
			for (i = 0; i < lengthof(P->dict) && P->dict[i]; i++) {
				b.p	= P->dict[i];

				while ((b.len = dns_l_expand(b.label, sizeof b.label, b.p, &b.x, P->data, P->end))) {
					a.y	= a.x;
					b.y	= b.x;

					while (a.len && b.len && 0 == strcasecmp((char *)a.label, (char *)b.label)) {
						a.len = dns_l_expand(a.label, sizeof a.label, a.y, &a.y, dst.b, lim);
						b.len = dns_l_expand(b.label, sizeof b.label, b.y, &b.y, P->data, P->end);
					}

					if (a.len == 0 && b.len == 0 && b.p <= 0x3fff) {
						dst.b[a.p++]	= 0xc0
								| (0x3f & (b.p >> 8));
						dst.b[a.p++]	= (0xff & (b.p >> 0));

						/* silence static analyzers */
						dns_assume(a.p > 0);

						return a.p;
					}

					b.p	= b.x;
				} /* while() */
			} /* for() */

			a.p	= a.x;
		} /* while() */
	} /* if () */
#endif

	if (!dst.p)
		*error = DNS_EILLEGAL;

	return dst.p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
movl $0x1, %r12d
testq %rcx, %rcx
je 0x27aab
xorl %edi, %edi
xorl %eax, %eax
xorl %esi, %esi
movq 0x10(%rsp), %r9
movb (%rdx,%rax), %r8b
cmpb $0x2e, %r8b
jne 0x27a95
cmpq %r13, %rsi
jae 0x27a8a
movl %eax, %r8d
subl %edi, %r8d
andb $0x3f, %r8b
movq 0x10(%rsp), %rdi
movb %r8b, (%rdi,%rsi)
incq %rax
movq %r12, %rsi
movq %rax, %rdi
jmp 0x27aa1
cmpq %r13, %r12
jae 0x27a9e
movb %r8b, (%r9,%r12)
incq %rax
incq %r12
cmpq %rcx, %rax
jb 0x27a68
jmp 0x27ab1
xorl %esi, %esi
xorl %eax, %eax
xorl %edi, %edi
cmpq %rdi, %rax
jbe 0x27ac9
cmpq %r13, %rsi
jae 0x27acc
subl %edi, %eax
andb $0x3f, %al
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%rsi)
jmp 0x27acc
movq %rsi, %r12
cmpq $0x2, %r12
jb 0x27ae4
cmpq %r13, %r12
jae 0x27ae1
movq 0x10(%rsp), %rax
movb $0x0, (%rax,%r12)
incq %r12
cmpq %r13, %r12
jae 0x27d22
leaq 0x82(%rsp), %rdx
movw $0x0, -0x2(%rdx)
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rcx
movq %r13, %r8
callq 0x27d43
movq %rax, 0x40(%rbx)
testq %rax, %rax
sete %cl
je 0x27d1d
movq %r13, 0x20(%rsp)
leaq 0x5c(%r15), %rbx
leaq 0x38(%rsp), %rbp
leaq 0x88(%rsp), %r13
movq %r14, 0x18(%rsp)
movq %r15, 0x28(%rsp)
movb %cl, 0xf(%rsp)
xorl %ecx, %ecx
movzwl (%r15,%rcx,2), %eax
testw %ax, %ax
je 0x27c94
movq %rcx, 0x30(%rsp)
movq 0x50(%r15), %r15
movw %ax, 0xd0(%rsp)
movzwl %ax, %esi
movq %r13, %rdi
leaq 0xd2(%rsp), %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x27d43
movq %rax, 0xc8(%rsp)
testq %rax, %rax
je 0x27c7d
movzwl 0x82(%rsp), %eax
movw %ax, 0x84(%rsp)
movzwl 0xd2(%rsp), %eax
movw %ax, 0xd4(%rsp)
movq 0x78(%rsp), %r14
testq %r14, %r14
setne %cl
movq 0xc8(%rsp), %rax
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x27c47
movq %rbp, %rdi
movq %r13, %rsi
callq 0xfe40
testl %eax, %eax
jne 0x27c3c
movzwl 0x84(%rsp), %esi
movq %rbp, %rdi
leaq 0x84(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
callq 0x27d43
movq %rax, %r14
movq %rax, 0x78(%rsp)
movzwl 0xd4(%rsp), %esi
movq %r13, %rdi
leaq 0xd4(%rsp), %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x27d43
movq %rax, 0xc8(%rsp)
testq %r14, %r14
je 0x27c47
testq %rax, %rax
jne 0x27bd1
jmp 0x27c47
movl $0x1, %r14d
movl $0x1, %eax
orq %rax, %r14
sete %al
movzwl 0xd0(%rsp), %ecx
movzwl %cx, %edx
cmpl $0x4000, %edx           # imm = 0x4000
setb %dl
andb %al, %dl
cmpb $0x1, %dl
je 0x27cd9
movzwl 0xd2(%rsp), %esi
movw %si, 0xd0(%rsp)
jmp 0x27b6a
movq 0x30(%rsp), %rcx
incq %rcx
cmpq $0x10, %rcx
movq 0x28(%rsp), %r15
jne 0x27b48
movzwl 0x82(%rsp), %esi
movw %si, 0x80(%rsp)
movq %rbp, %rdi
leaq 0x82(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
callq 0x27d43
movq %rax, %rcx
movq %rax, 0x78(%rsp)
testq %rcx, %rcx
sete %cl
movq 0x18(%rsp), %r14
jne 0x27b42
jmp 0x27d1d
movl %ecx, %eax
shrl $0x8, %eax
orb $-0x40, %al
movzwl 0x80(%rsp), %edx
leal 0x1(%rdx), %esi
movw %si, 0x80(%rsp)
movq 0x10(%rsp), %rdi
movb %al, (%rdi,%rdx)
leal 0x2(%rdx), %eax
movw %ax, 0x80(%rsp)
movl $0xffff, %edx           # imm = 0xFFFF
andl %edx, %esi
movb %cl, (%rdi,%rsi)
andl %edx, %eax
movq 0x18(%rsp), %r14
movb 0xf(%rsp), %cl
jmp 0x27d1d
testb $0x1, %cl
je 0x27d31
testq %r12, %r12
jne 0x27d2e
movl $0x9b918cc1, (%r14)     # imm = 0x9B918CC1
movq %r12, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq