// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/lib/dns.c
// Function: dns_hints_query
struct dns_packet *dns_hints_query(struct dns_hints *hints, struct dns_packet *Q, int *error_) {
	struct dns_packet *A, *P;
	struct dns_rr rr;
	char zone[DNS_D_MAXNAME + 1];
	size_t zlen;
	struct dns_hints_i i;
	struct sockaddr *sa;
	socklen_t slen;
	int error;

	if (!dns_rr_grep(&rr, 1, dns_rr_i_new(Q, .section = DNS_S_QUESTION), Q, &error))
		goto error;

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

	P			= dns_p_new(512);
	dns_header(P)->qr	= 1;

	if ((error = dns_rr_copy(P, &rr, Q)))
		goto error;

	if ((error = dns_p_push(P, DNS_S_AUTHORITY, ".", strlen("."), DNS_T_NS, DNS_C_IN, 0, "hints.local.")))
		goto error;

	do {
		i.zone	= zone;

		dns_hints_i_init(&i, hints);

		while (dns_hints_grep(&sa, &slen, 1, &i, hints)) {
			int af		= sa->sa_family;
			int rtype	= (af == AF_INET6)? DNS_T_AAAA : DNS_T_A;

			if ((error = dns_p_push(P, DNS_S_ADDITIONAL, "hints.local.", strlen("hints.local."), rtype, DNS_C_IN, 0, dns_sa_addr(af, sa, NULL))))
				goto error;
		}
	} while ((zlen = dns_d_cleave(zone, sizeof zone, zone, zlen)));

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

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

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movq $0x0, 0x30(%rdx)
movl $0x1, (%rdx)
movups %xmm0, 0x38(%rdx)
movups %xmm0, 0x48(%rdx)
leaq 0x38(%rsp), %rdi
leaq 0xc(%rsp), %r8
movl $0x1, %esi
movq %r13, %rcx
callq 0xfd70
testl %eax, %eax
je 0x2d84b
movzwl 0x3c(%rsp), %edx
leaq 0x310(%rsp), %rbp
leaq 0xc(%rsp), %r8
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %r13, %rcx
callq 0xfec0
testq %rax, %rax
je 0x2d84b
movq %rax, %r12
cmpq $0xff, %rax
jbe 0x2d627
movl $0x9b918cc1, 0xc(%rsp)  # imm = 0x9B918CC1
jmp 0x2d84b
leaq 0xb0(%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)
movl $0x0, 0x64(%r15)
movq $0x800000, 0x5c(%r15)   # imm = 0x800000
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x10370
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x2d84b
leaq 0xba48(%rip), %rax      # 0x390c9
leaq 0xb88b(%rip), %rdx      # 0x38f13
leaq 0xb0(%rsp), %rdi
movl $0x1, %ecx
movl $0x4, %esi
movl $0x2, %r8d
movl $0x1, %r9d
pushq %rax
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x2d84b
leaq 0x20(%rsp), %r15
movq %rbp, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
callq *0x1abf9(%rip)          # 0x482d0
testl %eax, %eax
je 0x2d6d1
movl %eax, 0x1c(%rsp)
movq 0x8(%r14), %r13
testq %r13, %r13
je 0x2d755
movq %rbp, %rdi
movq %r13, %rsi
callq 0xfe40
testl %eax, %eax
je 0x2d700
movq 0x988(%r13), %r13
jmp 0x2d6e3
movq %rbx, 0x28(%rsp)
movl 0x980(%r13), %ebx
xorl %ecx, %ecx
cmpl $0x2, %ebx
jb 0x2d73f
xorl %r15d, %r15d
movl $0x1, %ebp
movl %ebp, %edi
movl %r15d, %esi
leaq 0x10(%rsp), %rdx
movq %r13, %rcx
callq 0x331b8
movl %ebp, %ecx
testl %eax, %eax
js 0x2d736
movl %r15d, %ecx
incl %ebp
movl %ecx, %r15d
cmpl %ebp, %ebx
jne 0x2d71b
movl %ecx, 0x18(%rsp)
movq 0x28(%rsp), %rbx
leaq 0x310(%rsp), %rbp
leaq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0x34(%rsp), %r13
movq %r13, %rsi
movl $0x1, %edx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
callq 0x102c0
testl %eax, %eax
je 0x2d7db
movq 0x20(%rsp), %rax
movzwl (%rax), %ecx
movl $0x1c, %r8d
cmpl $0xa, %ecx
je 0x2d78f
movl $0x1, %r8d
cmpl $0x2, %ecx
je 0x2d79f
cmpl $0xa, %ecx
jne 0x2d7a5
addq $0x8, %rax
jmp 0x2d7a7
addq $0x4, %rax
jmp 0x2d7a7
xorl %eax, %eax
movl $0xc, %ecx
leaq 0xb0(%rsp), %rdi
movl $0x8, %esi
leaq 0xb909(%rip), %rdx      # 0x390c9
movl $0x1, %r9d
pushq %rax
pushq $0x0
callq 0x106d0
addq $0x10, %rsp
testl %eax, %eax
jne 0x2d847
movq %r15, %rdi
jmp 0x2d75d
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x104f0
movq %rax, %r12
testq %rax, %rax
jne 0x2d6c3
leaq 0xc(%rsp), %rsi
movl $0x0, (%rsi)
movq 0x100(%rsp), %rdi
callq 0xfa30
testq %rax, %rax
je 0x2d84b
movq %rax, %r14
movq 0x48(%rax), %rax
movq 0x100(%rsp), %rdx
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq %rdx, 0x50(%r14)
movq %r14, %rdi
addq $0x5c, %rdi
leaq 0x10c(%rsp), %rsi
callq 0xfa60
jmp 0x2d854
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, (%rbx)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq