// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %r12
leaq 0x128(%rsp), %r15
movl $0x260, %edx            # imm = 0x260
movq %r15, %rdi
xorl %esi, %esi
callq 0xf750
movq $0x200, 0x48(%r15)      # imm = 0x200
movq $0xc, 0x50(%r15)
movq $0x0, 0x5c(%r15)
movl $0x0, 0x64(%r15)
leaq 0x8(%rsp), %rdi
movl $0xc, %esi
movq %r14, %rdx
callq 0xf710
movl %eax, (%rsp)
testl %eax, %eax
je 0x2b814
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 %r14, %rcx
callq 0xfec0
testq %rax, %rax
je 0x2b7f7
movq %rax, %r14
cmpq $0xff, %rax
jbe 0x2b847
movl $0x9b918cc1, (%rsp)     # imm = 0x9B918CC1
jmp 0x2b7f7
movl 0x10(%rsp), %ebp
movl 0x14(%rsp), %r15d
leaq 0x128(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movl $0x1, %esi
movq %r14, %rcx
movl %ebp, %r8d
movl %r15d, %r9d
pushq $0x0
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
movl %eax, (%rsp)
testl %eax, %eax
jne 0x2b7f7
cmpl $0x1, %ebp
je 0x2b970
cmpl $0x1c, %ebp
je 0x2b963
cmpl $0xc, %ebp
jne 0x2b911
movl %r15d, 0x4(%rsp)
movl (%rsp), %r13d
movq (%r12), %r15
testq %r15, %r15
je 0x2b90d
leaq 0x20(%rsp), %r12
cmpb $0x0, 0x160(%r15)
jne 0x2b901
leaq 0x100(%r15), %rsi
movq %r12, %rdi
callq 0xfe40
testl %eax, %eax
jne 0x2b901
leaq 0x128(%rsp), %rdi
movl $0x2, %esi
movq %r12, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movl 0x4(%rsp), %r9d
pushq %r15
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
movl %eax, %r13d
testl %eax, %eax
jne 0x2b9e5
movq 0x168(%r15), %r15
testq %r15, %r15
jne 0x2b8b1
movl %r13d, (%rsp)
movq 0x178(%rsp), %rdi
movq %rsp, %rsi
callq 0xfa30
testq %rax, %rax
je 0x2b952
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 0xfa60
jmp 0x2b955
xorl %r14d, %r14d
testq %r14, %r14
jne 0x2b7ff
jmp 0x2b7f7
movl %r15d, 0x4(%rsp)
movl $0xa, %r15d
jmp 0x2b97b
movl %r15d, 0x4(%rsp)
movl $0x2, %r15d
movl (%rsp), %r13d
movq (%r12), %r12
testq %r12, %r12
je 0x2b90d
cmpl %r15d, 0x14c(%r12)
jne 0x2b9db
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0xfe40
testl %eax, %eax
jne 0x2b9db
leaq 0x150(%r12), %rax
leaq 0x128(%rsp), %rdi
movl $0x2, %esi
leaq 0x20(%rsp), %rdx
movq %r14, %rcx
movl %ebp, %r8d
movl 0x4(%rsp), %r9d
pushq %rax
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
movl %eax, %r13d
testl %eax, %eax
jne 0x2b9e5
movq 0x168(%r12), %r12
jmp 0x2b983
movl %r13d, (%rsp)
jmp 0x2b7f7