// File: /workspace/github_c_makefile_star2_O2/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, %r11
movq %r8, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
pushq $0x1
popq %r10
xorl %eax, %eax
xorl %esi, %esi
xorl %edi, %edi
movq 0x8(%rsp), %r9
cmpq %rcx, %rsi
jae 0x24925
movb (%rdx,%rsi), %r8b
cmpb $0x2e, %r8b
jne 0x24912
cmpq 0x10(%rsp), %rax
jae 0x24907
movl %esi, %r8d
subl %edi, %r8d
andb $0x3f, %r8b
movq 0x8(%rsp), %rdi
movb %r8b, (%rdi,%rax)
incq %rsi
movq %r10, %rax
movq %rsi, %rdi
jmp 0x24920
cmpq 0x10(%rsp), %r10
jae 0x2491d
movb %r8b, (%r9,%r10)
incq %rsi
incq %r10
jmp 0x248de
cmpq %rdi, %rsi
jbe 0x24942
cmpq 0x10(%rsp), %rax
jae 0x24945
subl %edi, %esi
andb $0x3f, %sil
movq 0x8(%rsp), %rcx
movb %sil, (%rcx,%rax)
jmp 0x24945
movq %rax, %r10
cmpq $0x2, %r10
jb 0x2495f
cmpq 0x10(%rsp), %r10
jae 0x2495c
movq 0x8(%rsp), %rax
movb $0x0, (%rax,%r10)
incq %r10
cmpq 0x10(%rsp), %r10
jae 0x24b2d
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
leaq 0x82(%rsp), %rdx
leaq 0x5c(%rbx), %r15
xorl %eax, %eax
leaq 0x38(%rsp), %r14
leaq 0x88(%rsp), %r12
movq %rbx, 0x28(%rsp)
movw %ax, 0x80(%rsp)
movzwl %ax, %esi
movq %r14, %rdi
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0x24b51
movq %rax, 0x78(%rsp)
testq %rax, %rax
je 0x24b23
movq %rax, %rbp
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0x24ae0
movzwl (%rbx,%rcx,2), %eax
testw %ax, %ax
je 0x24ae0
movq %rcx, 0x30(%rsp)
movq 0x50(%rbx), %rbx
movw %ax, 0xd0(%rsp)
movzwl %ax, %esi
movq %r12, %rdi
leaq 0xd2(%rsp), %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x24b51
movq %rax, 0xc8(%rsp)
testq %rax, %rax
je 0x24ace
movzwl 0x82(%rsp), %eax
movw %ax, 0x84(%rsp)
movzwl 0xd2(%rsp), %eax
movw %ax, 0xd4(%rsp)
pushq $0x1
popq %r13
testq %rbp, %rbp
je 0x24aa8
testq %r13, %r13
je 0x24aa8
movq %r14, %rdi
movq %r12, %rsi
callq 0xfed0
testl %eax, %eax
jne 0x24aa8
movzwl 0x84(%rsp), %esi
movq %r14, %rdi
leaq 0x84(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0x24b51
movq %rax, %rbp
movq %rax, 0x78(%rsp)
movzwl 0xd4(%rsp), %esi
movq %r12, %rdi
leaq 0xd4(%rsp), %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x24b51
movq %rax, %r13
movq %rax, 0xc8(%rsp)
jmp 0x24a3a
orq %rbp, %r13
sete %cl
movzwl 0xd0(%rsp), %eax
cmpw $0x4000, %ax            # imm = 0x4000
setb %dl
testb %dl, %cl
jne 0x24af5
movzwl 0xd2(%rsp), %eax
jmp 0x249e4
movq 0x30(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %rbx
jmp 0x249c4
movzwl 0x82(%rsp), %eax
leaq 0x82(%rsp), %rdx
jmp 0x24994
movl %eax, %ecx
shrl $0x8, %ecx
orb $-0x40, %cl
movzwl 0x80(%rsp), %edx
leal 0x1(%rdx), %esi
movq 0x8(%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
jmp 0x24b3c
movq 0x20(%rsp), %r10
movq 0x18(%rsp), %r11
testq %r10, %r10
jne 0x24b3c
movl $0x9b918cc1, (%r11)     # imm = 0x9B918CC1
xorl %r10d, %r10d
movq %r10, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq