// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x411c1
movq -0x30(%rbp), %rdi
callq 0xfa90
jmp 0x411f1
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x411ef
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x411e2
movq -0x38(%rbp), %rax
movl $0x16, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x4139e
jmp 0x411f1
movl $0x588, %edi            # imm = 0x588
callq 0x10260
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x4120a
jmp 0x41371
movq -0x40(%rbp), %rdi
leaq 0xb363(%rip), %rsi      # 0x4c578
movl $0x588, %edx            # imm = 0x588
callq 0xfb40
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x30, %edx
callq 0xfb40
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
movq $0x0, -0x30(%rbp)
movq -0x40(%rbp), %rdi
addq $0x38, %rdi
movq -0x10(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0xf520
movq %rax, %rcx
movl $0x100, %eax            # imm = 0x100
cmpq %rcx, %rax
ja 0x41274
movl $0x24, -0x44(%rbp)
jmp 0x4137b
movl -0x1c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x138(%rax)
movq -0x40(%rbp), %rax
movw $0x0, 0x13c(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x412ba
movq -0x40(%rbp), %rdi
addq $0x13c, %rdi            # imm = 0x13C
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x413b0
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0x412ba
jmp 0x4137b
movq -0x40(%rbp), %rax
movw 0x13c(%rax), %cx
movw %cx, 0x13e(%rax)
movq -0x40(%rbp), %rax
movl 0x138(%rax), %eax
movl %eax, -0x48(%rbp)
subl $0x1, %eax
je 0x412ea
jmp 0x412e0
movl -0x48(%rbp), %eax
subl $0x1c, %eax
je 0x412fb
jmp 0x4130c
movq -0x40(%rbp), %rax
movq $0x2, 0x140(%rax)
jmp 0x41367
movq -0x40(%rbp), %rax
movq $0x200, 0x140(%rax) # imm = 0x200
jmp 0x41367
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x41330
jmp 0x4131c
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x41341
jmp 0x41326
movl -0x4c(%rbp), %eax
subl $0xa, %eax
je 0x41352
jmp 0x41363
movq -0x40(%rbp), %rax
movq $0x202, 0x140(%rax) # imm = 0x202
jmp 0x41365
movq -0x40(%rbp), %rax
movq $0x2, 0x140(%rax)
jmp 0x41365
movq -0x40(%rbp), %rax
movq $0x200, 0x140(%rax) # imm = 0x200
jmp 0x41365
jmp 0x41365
jmp 0x41367
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4139e
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rdi
callq 0x10090
movq -0x30(%rbp), %rdi
callq 0xfef0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)