// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/lib/dns.c
// Function: dns_hosts_query
struct dns_packet *dns_hosts_query(struct dns_hosts *hosts, struct dns_packet *Q, int *error_) {
	struct dns_packet *P	= dns_p_new(512);
	struct dns_packet *A	= 0;
	struct dns_rr rr;
	struct dns_hosts_entry *ent;
	int error, af;
	char qname[DNS_D_MAXNAME + 1];
	size_t qlen;

	if ((error = dns_rr_parse(&rr, 12, Q)))
		goto error;

	if (!(qlen = dns_d_expand(qname, sizeof qname, rr.dn.p, Q, &error)))
		goto error;
	else if (qlen >= sizeof qname)
		goto toolong;

	if ((error = dns_p_push(P, DNS_S_QD, qname, qlen, rr.type, rr.class, 0, 0)))
		goto error;

	switch (rr.type) {
	case DNS_T_PTR:
		for (ent = hosts->head; ent; ent = ent->next) {
			if (ent->alias || 0 != strcasecmp(qname, ent->arpa))
				continue;

			if ((error = dns_p_push(P, DNS_S_AN, qname, qlen, rr.type, rr.class, 0, ent->host)))
				goto error;
		}

		break;
	case DNS_T_AAAA:
		af	= AF_INET6;

		goto loop;
	case DNS_T_A:
		af	= AF_INET;

loop:		for (ent = hosts->head; ent; ent = ent->next) {
			if (ent->af != af || 0 != strcasecmp(qname, ent->host))
				continue;

			if ((error = dns_p_push(P, DNS_S_AN, qname, qlen, rr.type, rr.class, 0, &ent->addr)))
				goto error;
		}

		break;
	default:
		break;
	} /* switch() */


	if (!(A = dns_p_copy(dns_p_make(P->end, &error), P)))
		goto error;

	return A;
toolong:
	error = DNS_EILLEGAL;
error:
	*error_	= error;

	dns_p_free(A);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x388, %rsp            # imm = 0x388
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x128(%rsp), %r12
movl $0x260, %edx            # imm = 0x260
movq %r12, %rdi
xorl %esi, %esi
callq 0xf790
movq $0x200, 0x48(%r12)      # imm = 0x200
movq $0xc, 0x50(%r12)
andq $0x0, 0x5c(%r12)
andl $0x0, 0x64(%r12)
leaq 0x8(%rsp), %rdi
pushq $0xc
popq %rsi
movq %r15, %rdx
callq 0xf750
movl %eax, (%rsp)
testl %eax, %eax
je 0x275f7
movl (%rsp), %eax
movl %eax, (%rbx)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl 0xc(%rsp), %edx
leaq 0x20(%rsp), %rdi
movq %rsp, %r8
movl $0x100, %esi            # imm = 0x100
movq %r15, %rcx
callq 0xff50
testq %rax, %rax
je 0x275da
movq %rax, %r15
cmpq $0xff, %rax
jbe 0x2762a
movl $0x9b918cc1, (%rsp)     # imm = 0x9B918CC1
jmp 0x275da
movl 0x10(%rsp), %r12d
movl 0x14(%rsp), %ebp
leaq 0x128(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x20(%rsp), %rdx
movq %r15, %rcx
movl %r12d, %r8d
movl %ebp, %r9d
pushq $0x0
pushq $0x0
callq 0x10780
popq %rcx
popq %rdx
movl %eax, (%rsp)
testl %eax, %eax
jne 0x275da
cmpl $0x1, %r12d
je 0x276e7
cmpl $0x1c, %r12d
je 0x276df
cmpl $0xc, %r12d
jne 0x27750
leaq 0x20(%rsp), %r12
pushq $0xc
popq %r13
movq (%r14), %r14
testq %r14, %r14
je 0x2774c
cmpb $0x0, 0x160(%r14)
jne 0x276d6
leaq 0x100(%r14), %rsi
movq %r12, %rdi
callq 0xfed0
testl %eax, %eax
jne 0x276d6
leaq 0x128(%rsp), %rdi
pushq $0x2
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r13d, %r8d
movl %ebp, %r9d
pushq %r14
pushq $0x0
callq 0x10780
addq $0x10, %rsp
testl %eax, %eax
jne 0x27798
addq $0x168, %r14            # imm = 0x168
jmp 0x27681
movl %ebp, 0x4(%rsp)
pushq $0xa
jmp 0x276ed
movl %ebp, 0x4(%rsp)
pushq $0x2
popq %rbp
leaq 0x20(%rsp), %r13
movq (%r14), %r14
testq %r14, %r14
je 0x2774c
cmpl %ebp, 0x14c(%r14)
jne 0x27743
movq %r13, %rdi
movq %r14, %rsi
callq 0xfed0
testl %eax, %eax
jne 0x27743
leaq 0x150(%r14), %rax
leaq 0x128(%rsp), %rdi
pushq $0x2
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
movl %r12d, %r8d
movl 0x4(%rsp), %r9d
pushq %rax
pushq $0x0
callq 0x10780
addq $0x10, %rsp
testl %eax, %eax
jne 0x27798
addq $0x168, %r14            # imm = 0x168
jmp 0x276f3
andl $0x0, (%rsp)
movq 0x178(%rsp), %rdi
movq %rsp, %rsi
callq 0xfaa0
testq %rax, %rax
je 0x275da
movq %rax, %r14
leaq 0x184(%rsp), %rsi
movq 0x48(%rax), %rax
movq -0xc(%rsi), %rdx
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq %rdx, 0x50(%r14)
movq %r14, %rdi
addq $0x5c, %rdi
callq 0xfad0
jmp 0x275e2
movl %eax, (%rsp)
jmp 0x275da