// File: /workspace/github_c_makefile_star2_O3/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, %r15
leaq 0x128(%rsp), %r12
movl $0x260, %edx            # imm = 0x260
movq %r12, %rdi
xorl %esi, %esi
callq 0xf750
movq $0x200, 0x48(%r12)      # imm = 0x200
movq $0xc, 0x50(%r12)
movq $0x0, 0x5c(%r12)
movl $0x0, 0x64(%r12)
leaq 0x8(%rsp), %rdi
movl $0xc, %esi
movq %r14, %rdx
callq 0xf710
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x2b44e
movl 0x4(%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
leaq 0x4(%rsp), %r8
movl $0x100, %esi            # imm = 0x100
movq %r14, %rcx
callq 0xfec0
testq %rax, %rax
je 0x2b430
movq %rax, %r14
cmpq $0xff, %rax
jbe 0x2b484
movl $0x9b918cc1, 0x4(%rsp)  # imm = 0x9B918CC1
jmp 0x2b430
movl 0x10(%rsp), %r12d
movl 0x14(%rsp), %ebp
leaq 0x128(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movl $0x1, %esi
movq %r14, %rcx
movl %r12d, %r8d
movl %ebp, %r9d
pushq $0x0
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2b430
cmpl $0x1, %r12d
je 0x2b59f
cmpl $0x1c, %r12d
je 0x2b597
cmpl $0xc, %r12d
jne 0x2b54d
movq (%r15), %r13
testq %r13, %r13
je 0x2b545
leaq 0x20(%rsp), %r15
leaq 0x128(%rsp), %r12
cmpb $0x0, 0x160(%r13)
jne 0x2b539
leaq 0x100(%r13), %rsi
movq %r15, %rdi
callq 0xfe40
testl %eax, %eax
jne 0x2b539
movq %r12, %rdi
movl $0x2, %esi
movq %r15, %rdx
movq %r14, %rcx
movl $0xc, %r8d
movl %ebp, %r9d
pushq %r13
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
testl %eax, %eax
jne 0x2b602
movq 0x168(%r13), %r13
testq %r13, %r13
jne 0x2b4f0
movl $0x0, 0x4(%rsp)
movq 0x178(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0xfa30
testq %rax, %rax
je 0x2b430
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 0x2b439
movl $0xa, %r13d
jmp 0x2b5a5
movl $0x2, %r13d
movq (%r15), %r15
testq %r15, %r15
je 0x2b545
cmpl %r13d, 0x14c(%r15)
jne 0x2b5f9
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0xfe40
testl %eax, %eax
jne 0x2b5f9
leaq 0x150(%r15), %rax
leaq 0x128(%rsp), %rdi
movl $0x2, %esi
leaq 0x20(%rsp), %rdx
movq %r14, %rcx
movl %r12d, %r8d
movl %ebp, %r9d
pushq %rax
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
testl %eax, %eax
jne 0x2b602
movq 0x168(%r15), %r15
jmp 0x2b5a8
movl %eax, 0x4(%rsp)
jmp 0x2b430