// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movq %r9, %r11
movq %rsi, %r13
movq %rdi, (%rsp)
testq %rcx, %rcx
je 0x27879
movl $0x1, %r10d
xorl %edi, %edi
xorl %eax, %eax
xorl %esi, %esi
movb (%rdx,%rax), %bl
cmpb $0x2e, %bl
jne 0x2784a
cmpq %r13, %rsi
jae 0x2783f
movl %eax, %r9d
subl %edi, %r9d
andb $0x3f, %r9b
movq (%rsp), %rdi
movb %r9b, (%rdi,%rsi)
incq %rax
movq %r10, %rsi
movq %rax, %rdi
jmp 0x2785a
cmpq %r13, %r10
jae 0x27857
movq (%rsp), %r9
movb %bl, (%r9,%r10)
incq %rax
incq %r10
cmpq %rcx, %rax
jb 0x27820
cmpq %rdi, %rax
jbe 0x2787e
cmpq %r13, %rsi
jae 0x27881
subl %edi, %eax
andb $0x3f, %al
movq (%rsp), %rcx
movb %al, (%rcx,%rsi)
jmp 0x27881
xorl %r10d, %r10d
jmp 0x27898
movq %rsi, %r10
cmpq $0x2, %r10
jb 0x27898
cmpq %r13, %r10
jae 0x27895
movq (%rsp), %rax
movb $0x0, (%rax,%r10)
incq %r10
cmpq %r13, %r10
jae 0x27a51
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
leaq 0xc2(%rsp), %rdx
movw $0x0, -0x2(%rdx)
movq %r8, 0x8(%rsp)
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq (%rsp), %rcx
movq %r13, %r8
callq 0x27aa2
movq %rax, 0x40(%rbx)
movq 0x8(%rsp), %rbx
testq %rax, %rax
je 0x27a47
movq %rax, %r15
leaq 0x5c(%rbx), %rbp
xorl %ecx, %ecx
leaq 0x78(%rsp), %r14
leaq 0x28(%rsp), %r12
movzwl (%rbx,%rcx,2), %eax
testw %ax, %ax
je 0x27a07
movq %rcx, 0x20(%rsp)
movq 0x50(%rbx), %rbx
movw %ax, 0x70(%rsp)
movzwl %ax, %esi
movq %r12, %rdi
leaq 0x72(%rsp), %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x27aa2
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x279f0
movzwl 0xc2(%rsp), %eax
movw %ax, 0xc4(%rsp)
movzwl 0x72(%rsp), %eax
movw %ax, 0x74(%rsp)
testq %r15, %r15
je 0x279de
movq %r14, %rdi
movq %r12, %rsi
callq 0xfe40
testl %eax, %eax
jne 0x279e1
movzwl 0xc4(%rsp), %esi
movq %r14, %rdi
leaq 0xc4(%rsp), %rdx
movq (%rsp), %rcx
movq %r13, %r8
callq 0x27aa2
movq %rax, %r15
movq %rax, 0xb8(%rsp)
movzwl 0x74(%rsp), %esi
movq %r12, %rdi
leaq 0x74(%rsp), %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x27aa2
movq %rax, 0x68(%rsp)
testq %r15, %r15
je 0x279bb
testq %rax, %rax
jne 0x2795b
movq %r15, %rcx
orq %rax, %rcx
sete %cl
movzwl 0x70(%rsp), %eax
movzwl %ax, %edx
cmpl $0x4000, %edx           # imm = 0x4000
setb %dl
testb %dl, %cl
je 0x279e1
jmp 0x27a62
xorl %r15d, %r15d
movzwl 0x72(%rsp), %esi
movw %si, 0x70(%rsp)
jmp 0x27917
movq 0x20(%rsp), %rcx
incq %rcx
cmpq $0x10, %rcx
movq 0x8(%rsp), %rbx
jne 0x278f9
movzwl 0xc2(%rsp), %esi
movw %si, 0xc0(%rsp)
movq %r14, %rdi
leaq 0xc2(%rsp), %rdx
movq (%rsp), %rcx
movq %r13, %r8
callq 0x27aa2
movq %rax, %r15
movq %rax, 0xb8(%rsp)
movl $0x0, %ecx
testq %rax, %rax
jne 0x278f9
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r11
testq %r10, %r10
jne 0x27a8d
movl $0x9b918cc1, (%r11)     # imm = 0x9B918CC1
xorl %r10d, %r10d
jmp 0x27a8d
movl %eax, %ecx
shrl $0x8, %ecx
orb $-0x40, %cl
movzwl 0xc0(%rsp), %edx
leal 0x1(%rdx), %esi
movq (%rsp), %rdi
movb %cl, (%rdi,%rdx)
leal 0x2(%rdx), %r10d
movl $0xffff, %ecx           # imm = 0xFFFF
andl %ecx, %esi
movb %al, (%rdi,%rsi)
andl %ecx, %r10d
movq %r10, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq