// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x288(%rbp), %rdi
xorl %esi, %esi
movl $0x260, %edx            # imm = 0x260
callq 0xf7d0
leaq -0x288(%rbp), %rdi
movl $0x25c, %esi            # imm = 0x25C
callq 0x10c30
movq %rax, -0x28(%rbp)
movq $0x0, -0x290(%rbp)
movq -0x18(%rbp), %rdx
leaq -0x2a8(%rbp), %rdi
movl $0xc, %esi
callq 0xf790
movl %eax, -0x2b4(%rbp)
cmpl $0x0, %eax
je 0x3976f
jmp 0x39a1f
leaq -0x3c0(%rbp), %rdi
movw -0x2a4(%rbp), %ax
movq -0x18(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
leaq -0x2b4(%rbp), %r8
movzwl %ax, %edx
callq 0xffd0
movq %rax, -0x3c8(%rbp)
cmpq $0x0, %rax
jne 0x397a7
jmp 0x39a1f
cmpq $0x100, -0x3c8(%rbp) # imm = 0x100
jb 0x397b9
jmp 0x39a15
jmp 0x397bb
movq -0x28(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
movq -0x3c8(%rbp), %rcx
movl -0x2a0(%rbp), %r8d
movl -0x29c(%rbp), %r9d
movl $0x1, %esi
xorl %eax, %eax
xorl %eax, %eax
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x10880
movl %eax, -0x2b4(%rbp)
cmpl $0x0, %eax
je 0x39809
jmp 0x39a1f
movl -0x2a0(%rbp), %eax
movl %eax, -0x3cc(%rbp)
subl $0x1, %eax
je 0x3990e
jmp 0x39820
movl -0x3cc(%rbp), %eax
subl $0xc, %eax
je 0x39841
jmp 0x3982d
movl -0x3cc(%rbp), %eax
subl $0x1c, %eax
je 0x39902
jmp 0x399d7
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2b0(%rbp)
cmpq $0x0, -0x2b0(%rbp)
je 0x398fd
movq -0x2b0(%rbp), %rax
testb $0x1, 0x160(%rax)
jne 0x3988f
leaq -0x3c0(%rbp), %rdi
movq -0x2b0(%rbp), %rsi
addq $0x100, %rsi            # imm = 0x100
callq 0xff50
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x39891
jmp 0x398e3
movq -0x28(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
movq -0x3c8(%rbp), %rcx
movl -0x2a0(%rbp), %r8d
movl -0x29c(%rbp), %r9d
movq -0x2b0(%rbp), %rax
movl $0x2, %esi
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10880
movl %eax, -0x2b4(%rbp)
cmpl $0x0, %eax
je 0x398e1
jmp 0x39a1f
jmp 0x398e3
movq -0x2b0(%rbp), %rax
movq 0x168(%rax), %rax
movq %rax, -0x2b0(%rbp)
jmp 0x3984f
jmp 0x399d9
movl $0xa, -0x2b8(%rbp)
jmp 0x39918
movl $0x2, -0x2b8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2b0(%rbp)
cmpq $0x0, -0x2b0(%rbp)
je 0x399d5
movq -0x2b0(%rbp), %rax
movl 0x14c(%rax), %eax
cmpl -0x2b8(%rbp), %eax
jne 0x39964
leaq -0x3c0(%rbp), %rdi
movq -0x2b0(%rbp), %rsi
callq 0xff50
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x39966
jmp 0x399bb
movq -0x28(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
movq -0x3c8(%rbp), %rcx
movl -0x2a0(%rbp), %r8d
movl -0x29c(%rbp), %r9d
movq -0x2b0(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movl $0x2, %esi
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10880
movl %eax, -0x2b4(%rbp)
cmpl $0x0, %eax
je 0x399b9
jmp 0x39a1f
jmp 0x399bb
movq -0x2b0(%rbp), %rax
movq 0x168(%rax), %rax
movq %rax, -0x2b0(%rbp)
jmp 0x39926
jmp 0x399d9
jmp 0x399d9
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x2b4(%rbp), %rsi
callq 0xfb10
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x10300
movq %rax, -0x290(%rbp)
cmpq $0x0, %rax
jne 0x39a08
jmp 0x39a1f
movq -0x290(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x39a3f
movl $0x9b918cc1, -0x2b4(%rbp) # imm = 0x9B918CC1
movl -0x2b4(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x290(%rbp), %rdi
callq 0x39a50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
nopl (%rax)