// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/lib/dns.c
// Function: dns_ai_open
struct dns_addrinfo *dns_ai_open(const char *host, const char *serv, enum dns_type qtype, const struct addrinfo *hints, struct dns_resolver *res, int *_error) {
	static const struct dns_addrinfo ai_initializer;
	struct dns_addrinfo *ai;
	int error;

	if (res) {
		dns_res_acquire(res);
	} else if (!(hints->ai_flags & AI_NUMERICHOST)) {
		/*
		 * NOTE: it's assumed that *_error is set from a previous
		 * API function call, such as dns_res_stub(). Should change
		 * this semantic, but it's applied elsewhere, too.
		 */
		if (!*_error)
			*_error = EINVAL;
		return NULL;
	}

	if (!(ai = malloc(sizeof *ai)))
		goto syerr;

	*ai = ai_initializer;
	ai->hints = *hints;

	ai->res = res;
	res = NULL;

	if (sizeof ai->qname <= dns_strlcpy(ai->qname, host, sizeof ai->qname))
		{ error = ENAMETOOLONG; goto error; }

	ai->qtype = qtype;
	ai->qport = 0;

	if (serv && (error = dns_ai_parseport(&ai->qport, serv, hints)))
		goto error;
	ai->port = ai->qport;

	/*
	 * FIXME: If an explicit A or AAAA record type conflicts with
	 * .ai_family or with resconf.family (i.e. AAAA specified but
	 * AF_INET6 not in interection of .ai_family and resconf.family),
	 * then what?
	 */
	switch (ai->qtype) {
	case DNS_T_A:
		ai->af.todo = DNS_AI_AF2INDEX(AF_INET);
		break;
	case DNS_T_AAAA:
		ai->af.todo = DNS_AI_AF2INDEX(AF_INET6);
		break;
	default: /* 0, MX, SRV, etc */
		switch (ai->hints.ai_family) {
		case AF_UNSPEC:
			ai->af.todo = DNS_AI_AF2INDEX(AF_INET) | DNS_AI_AF2INDEX(AF_INET6);
			break;
		case AF_INET:
			ai->af.todo = DNS_AI_AF2INDEX(AF_INET);
			break;
		case AF_INET6:
			ai->af.todo = DNS_AI_AF2INDEX(AF_INET6);
			break;
		default:
			break;
		}
	}

	return ai;
syerr:
	error = dns_syerr();
error:
	*_error = error;

	dns_ai_close(ai);
	dns_res_close(res);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, %rbp
movq %rsi, %r12
movq %rdi, %r13
testq %r8, %r8
je 0x2cbbc
lock
incq 0x320(%r15)
jmp 0x2cbd6
testb $0x4, (%rbp)
jne 0x2cbd6
cmpl $0x0, (%rbx)
jne 0x2cc63
movl $0x16, (%rbx)
jmp 0x2cc63
movl %edx, 0xc(%rsp)
movl $0x588, %edi            # imm = 0x588
callq 0x101a0
movq %rax, %r14
testq %rax, %rax
je 0x2cc4a
movq %rbx, 0x10(%rsp)
movq %r14, %rbx
addq $0x38, %rbx
movl $0x550, %edx            # imm = 0x550
movq %rbx, %rdi
xorl %esi, %esi
callq 0xf790
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm0, (%r14)
movups %xmm1, 0x10(%r14)
movups %xmm2, 0x20(%r14)
movq %r15, 0x30(%r14)
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf4f0
cmpq $0xff, %rax
jbe 0x2cc78
pushq $0x24
popq %rcx
xorl %r15d, %r15d
movq 0x10(%rsp), %rbx
jmp 0x2cc51
callq 0xf0a0
movl (%rax), %ecx
movl %ecx, (%rbx)
movq %r14, %rdi
callq 0xffe0
movq %r15, %rdi
callq 0xfe70
xorl %r14d, %r14d
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %edi
movl %edi, 0x138(%r14)
andw $0x0, 0x13c(%r14)
testq %r12, %r12
movq 0x10(%rsp), %rbx
je 0x2ccce
xorl %r15d, %r15d
xorl %edx, %edx
xorl %eax, %eax
movb (%r12,%rdx), %sil
movl $0x9b918cc9, %ecx       # imm = 0x9B918CC9
cmpb $0x30, %sil
jl 0x2ccf2
cmpb $0x39, %sil
ja 0x2cc51
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x2cc51
imulq $0xa, %rax, %rcx
addb $-0x30, %sil
movzbl %sil, %eax
addq %rcx, %rax
incq %rdx
jmp 0x2cc9d
xorl %eax, %eax
movw %ax, 0x13e(%r14)
cmpl $0x1c, %edi
je 0x2cd43
cmpl $0x1, %edi
jne 0x2cd1d
movq $0x2, 0x140(%r14)
jmp 0x2cc66
xorl %r15d, %r15d
testb %sil, %sil
jne 0x2cc51
testq %rdx, %rdx
je 0x2cc51
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x2cc51
movw %ax, 0x13c(%r14)
jmp 0x2ccd0
movl 0x4(%r14), %eax
cmpl $0xa, %eax
je 0x2cd43
cmpl $0x2, %eax
je 0x2cce2
testl %eax, %eax
jne 0x2cc66
movq $0x202, 0x140(%r14) # imm = 0x202
jmp 0x2cc66
movq $0x200, 0x140(%r14) # imm = 0x200
jmp 0x2cc66