// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %r8, %r12
movq %rcx, %rbp
movl %edx, %r15d
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
testq %r8, %r8
je 0x3153d
lock
incq 0x320(%r12)
jmp 0x31559
testb $0x4, (%rbp)
jne 0x31559
cmpl $0x0, (%r14)
jne 0x316a6
movl $0x16, (%r14)
jmp 0x316a6
movl $0x588, %edi            # imm = 0x588
callq 0x10110
movq %rax, %rbx
testq %rax, %rax
je 0x315d4
movq %r14, 0x8(%rsp)
movq %rbx, %rdi
addq $0x38, %rdi
xorl %r14d, %r14d
movl $0x550, %edx            # imm = 0x550
xorl %esi, %esi
callq 0xf750
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm0, (%rbx)
movups %xmm1, 0x10(%rbx)
movups %xmm2, 0x20(%rbx)
movq %r12, 0x30(%rbx)
movb (%r13,%r14), %al
movb %al, 0x38(%rbx,%r14)
testb %al, %al
je 0x315e0
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x315a1
movb $0x0, 0x137(%rbx)
addq %r13, %r14
leaq 0x1(%r14), %rax
cmpb $0x0, (%r14)
movq %rax, %r14
jne 0x315c5
jmp 0x315e7
callq 0xf0a0
movl (%rax), %edx
jmp 0x31693
leaq (%r14,%r13), %rax
incq %rax
subq %rax, %r13
cmpq $-0x100, %r13
jae 0x31605
movl $0x24, %edx
xorl %r12d, %r12d
movq 0x8(%rsp), %r14
jmp 0x31693
movl %r15d, 0x138(%rbx)
movw $0x0, 0x13c(%rbx)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r14
je 0x31660
movb (%rdi), %cl
cmpb $0x30, %cl
jl 0x31682
xorl %r12d, %r12d
xorl %eax, %eax
movq %rdi, %rsi
movl $0x9b918cc9, %edx       # imm = 0x9B918CC9
cmpb $0x39, %cl
ja 0x31693
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x31693
leaq (%rax,%rax,4), %rax
addb $-0x30, %cl
movzbl %cl, %ecx
leaq (%rcx,%rax,2), %rax
movb 0x1(%rsi), %cl
incq %rsi
cmpb $0x2f, %cl
jg 0x31638
jmp 0x31687
xorl %eax, %eax
movw %ax, 0x13e(%rbx)
cmpl $0x1c, %r15d
je 0x316e1
cmpl $0x1, %r15d
jne 0x316d0
movq $0x2, 0x140(%rbx)
jmp 0x316a8
xorl %eax, %eax
movq %rdi, %rsi
movl $0x9b918cc9, %edx       # imm = 0x9B918CC9
xorl %r12d, %r12d
testb %cl, %cl
je 0x316ba
movl %edx, (%r14)
movq %rbx, %rdi
callq 0xff50
movq %r12, %rdi
callq 0xfde0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %rdi, %rsi
je 0x31693
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x31693
movw %ax, 0x13c(%rbx)
jmp 0x31662
movl 0x4(%rbx), %eax
testl %eax, %eax
je 0x316ee
cmpl $0x2, %eax
je 0x31675
cmpl $0xa, %eax
jne 0x316a8
movq $0x200, 0x140(%rbx) # imm = 0x200
jmp 0x316a8
movq $0x202, 0x140(%rbx) # imm = 0x202
jmp 0x316a8