// File: /workspace/github_c_makefile_star2_O2/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)
andq $0x0, 0x30(%rdx)
movaps %xmm0, 0x20(%rdx)
movl $0x1, (%rdx)
movups %xmm0, 0x38(%rdx)
movups %xmm0, 0x48(%rdx)
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0xc(%rsp), %r8
movq %r13, %rcx
callq 0xfe00
testl %eax, %eax
je 0x294cc
movzwl 0x3c(%rsp), %edx
leaq 0x310(%rsp), %rbp
leaq 0xc(%rsp), %r8
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %r13, %rcx
callq 0xff50
testq %rax, %rax
je 0x294cc
movq %rax, %r12
cmpq $0xff, %rax
jbe 0x292e2
movl $0x9b918cc1, 0xc(%rsp)  # imm = 0x9B918CC1
jmp 0x294cc
leaq 0xb0(%rsp), %r15
movl $0x260, %edx            # imm = 0x260
movq %r15, %rdi
xorl %esi, %esi
callq 0xf790
movq $0x200, 0x48(%r15)      # imm = 0x200
movq $0xc, 0x50(%r15)
andl $0x0, 0x64(%r15)
movq $0x800000, 0x5c(%r15)   # imm = 0x800000
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x10410
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x294cc
leaq 0xad80(%rip), %rax      # 0x340b9
leaq 0xabc3(%rip), %rdx      # 0x33f03
leaq 0xb0(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rcx
pushq $0x2
popq %r8
pushq $0x1
popq %r13
movl %r13d, %r9d
pushq %rax
pushq $0x0
callq 0x10780
popq %rcx
popq %rdx
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x294cc
movq %rbx, 0x20(%rsp)
movq %rbp, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
callq *0x1cfbb(%rip)          # 0x46340
testl %eax, %eax
je 0x2937f
movl %eax, 0x1c(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x290c8
testq %rax, %rax
je 0x293e8
movq %rax, %r15
movl 0x980(%rax), %ebx
movl %r13d, %ebp
xorl %r13d, %r13d
cmpl %ebx, %ebp
jae 0x293d2
movl %ebp, %edi
movl %r13d, %esi
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x2e124
movl %ebp, %ecx
testl %eax, %eax
js 0x293cb
movl %r13d, %ecx
incl %ebp
movl %ecx, %r13d
jmp 0x293ac
movl %r13d, 0x18(%rsp)
movq 0x20(%rsp), %rbx
leaq 0x310(%rsp), %rbp
pushq $0x1
popq %r13
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x34(%rsp), %rsi
movl %r13d, %edx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
callq 0x10360
testl %eax, %eax
je 0x2945f
movq 0x28(%rsp), %rax
movzwl (%rax), %ecx
pushq $0x1c
popq %r8
cmpl $0xa, %ecx
je 0x2941d
movl %r13d, %r8d
cmpl $0x2, %ecx
je 0x2942d
cmpl $0xa, %ecx
jne 0x29433
addq $0x8, %rax
jmp 0x29435
addq $0x4, %rax
jmp 0x29435
xorl %eax, %eax
leaq 0xb0(%rsp), %rdi
pushq $0x8
popq %rsi
leaq 0xac72(%rip), %rdx      # 0x340b9
pushq $0xc
popq %rcx
movl %r13d, %r9d
pushq %rax
pushq $0x0
callq 0x10780
addq $0x10, %rsp
testl %eax, %eax
je 0x293ed
jmp 0x294c8
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x105a0
movq %rax, %r12
testq %rax, %rax
jne 0x29374
leaq 0xc(%rsp), %rsi
andl $0x0, (%rsi)
movq 0x100(%rsp), %rdi
callq 0xfaa0
testq %rax, %rax
je 0x294cc
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 0xfad0
jmp 0x294d5
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