// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rcx, %rbp
movl %edx, %r15d
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
testq %r8, %r8
je 0x31ad6
lock
incq 0x320(%r13)
jmp 0x31af2
testb $0x4, (%rbp)
jne 0x31af2
cmpl $0x0, (%r14)
jne 0x31c61
movl $0x16, (%r14)
jmp 0x31c61
movl $0x588, %edi            # imm = 0x588
callq 0x10110
movq %rax, %rbx
testq %rax, %rax
je 0x31b6f
movl %r15d, 0xc(%rsp)
movq %r14, %r15
movq %rbx, %rdi
addq $0x30, %rdi
xorl %r14d, %r14d
movl $0x558, %edx            # imm = 0x558
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 %r13, 0x30(%rbx)
movb (%r12,%r14), %al
movb %al, 0x38(%rbx,%r14)
testb %al, %al
je 0x31b7b
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x31b3d
movb $0x0, 0x137(%rbx)
addq %r12, %r14
leaq 0x1(%r14), %rax
cmpb $0x0, (%r14)
movq %rax, %r14
jne 0x31b60
jmp 0x31b82
callq 0xf0a0
movl (%rax), %esi
jmp 0x31c4e
leaq (%r12,%r14), %rax
incq %rax
subq %rax, %r12
cmpq $-0x100, %r12
jae 0x31b9e
movl $0x24, %esi
xorl %r13d, %r13d
movq %r15, %r14
jmp 0x31c4e
movl 0xc(%rsp), %eax
movl %eax, 0x138(%rbx)
movw $0x0, 0x13c(%rbx)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x31c22
movq %r15, %r14
movb (%rdi), %dl
xorl %eax, %eax
movq %rdi, %rcx
cmpb $0x30, %dl
jl 0x31bf7
cmpb $0x39, %dl
ja 0x31bf5
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x31bf5
leaq (%rax,%rax,4), %rax
addb $-0x30, %dl
movsbq %dl, %rdx
movl %edx, %edx
leaq (%rdx,%rax,2), %rax
movb 0x1(%rcx), %dl
incq %rcx
cmpb $0x2f, %dl
jg 0x31bca
jmp 0x31bf7
movb $0x1, %dl
movl $0x9b918cc9, %esi       # imm = 0x9B918CC9
testb %dl, %dl
je 0x31c04
xorl %edx, %edx
jmp 0x31c1e
xorl %edx, %edx
cmpq %rdi, %rcx
je 0x31c1e
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x31c1e
movw %ax, 0x13c(%rbx)
xorl %esi, %esi
movb $0x1, %dl
testb %dl, %dl
je 0x31c4b
movzwl 0x13c(%rbx), %eax
movw %ax, 0x13e(%rbx)
movl 0xc(%rsp), %eax
cmpl $0x1c, %eax
je 0x31c86
cmpl $0x1, %eax
jne 0x31c75
movq $0x2, 0x140(%rbx)
jmp 0x31c63
xorl %r13d, %r13d
movl %esi, (%r14)
movq %rbx, %rdi
callq 0xff50
movq %r13, %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
movl 0x4(%rbx), %eax
testl %eax, %eax
je 0x31c93
cmpl $0x2, %eax
je 0x31c3e
cmpl $0xa, %eax
jne 0x31c63
movq $0x200, 0x140(%rbx) # imm = 0x200
jmp 0x31c63
movq $0x202, 0x140(%rbx) # imm = 0x202
jmp 0x31c63