// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/lib/dns.c
// Function: dns_ai_nextent
int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
	struct dns_packet *ans, *glue;
	struct dns_rr rr;
	char qname[DNS_D_MAXNAME + 1];
	union dns_any any;
	size_t qlen, clen;
	int error;

	*ent = 0;

exec:

	switch (ai->state) {
	case DNS_AI_S_INIT:
		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_NEXTAF:
		if (!dns_ai_nextaf(ai))
			dns_ai_goto(DNS_AI_S_DONE);

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_NUMERIC:
		if (1 == dns_inet_pton(AF_INET, ai->qname, &any.a)) {
			if (ai->af.atype == AF_INET) {
				ai->state = DNS_AI_S_NEXTAF;
				return dns_ai_setent(ent, &any, DNS_T_A, ai);
			} else {
				dns_ai_goto(DNS_AI_S_NEXTAF);
			}
		}

		if (1 == dns_inet_pton(AF_INET6, ai->qname, &any.aaaa)) {
			if (ai->af.atype == AF_INET6) {
				ai->state = DNS_AI_S_NEXTAF;
				return dns_ai_setent(ent, &any, DNS_T_AAAA, ai);
			} else {
				dns_ai_goto(DNS_AI_S_NEXTAF);
			}
		}

		if (ai->hints.ai_flags & AI_NUMERICHOST)
			dns_ai_goto(DNS_AI_S_NEXTAF);

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_SUBMIT:
		assert(ai->res);

		if ((error = dns_res_submit(ai->res, ai->qname, dns_ai_qtype(ai), DNS_C_IN)))
			return error;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_CHECK:
		if ((error = dns_res_check(ai->res)))
			return error;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_FETCH:
		if (!(ans = dns_res_fetch_and_study(ai->res, &error)))
			return error;
		if (ai->glue != ai->answer)
			dns_p_free(ai->glue);
		ai->glue = dns_p_movptr(&ai->answer, &ans);

		/* Search generator may have changed the qname. */
		if (!(qlen = dns_d_expand(qname, sizeof qname, 12, ai->answer, &error)))
			return error;
		else if (qlen >= sizeof qname)
			return DNS_EILLEGAL;
		if (!dns_d_cname(ai->cname, sizeof ai->cname, qname, qlen, ai->answer, &error))
			return error;

		dns_strlcpy(ai->i_cname, ai->cname, sizeof ai->i_cname);
		dns_rr_i_init(&ai->i, ai->answer);
		ai->i.section = DNS_S_AN;
		ai->i.name    = ai->i_cname;
		ai->i.type    = dns_ai_qtype(ai);
		ai->i.sort    = &dns_rr_i_order;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_FOREACH_I:
		if (!dns_rr_grep(&rr, 1, &ai->i, ai->answer, &error))
			dns_ai_goto(DNS_AI_S_NEXTAF);

		if ((error = dns_any_parse(&any, &rr, ai->answer)))
			return error;

		ai->port = ai->qport;

		switch (rr.type) {
		case DNS_T_A:
		case DNS_T_AAAA:
			return dns_ai_setent(ent, &any, rr.type, ai);
		default:
			if (!(clen = dns_any_cname(ai->cname, sizeof ai->cname, &any, rr.type)))
				dns_ai_goto(DNS_AI_S_FOREACH_I);

			/*
			 * Find the "real" canonical name. Some authorities
			 * publish aliases where an RFC defines a canonical
			 * name. We trust that the resolver followed any
			 * CNAME chains on it's own, regardless of whether
			 * the "smart" option is enabled.
			 */
			if (!dns_d_cname(ai->cname, sizeof ai->cname, ai->cname, clen, ai->answer, &error))
				return error;

			if (rr.type == DNS_T_SRV)
				ai->port = any.srv.port;

			break;
		} /* switch() */

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_INIT_G:
		ai->g_depth = 0;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_ITERATE_G:
		dns_strlcpy(ai->g_cname, ai->cname, sizeof ai->g_cname);
		dns_rr_i_init(&ai->g, ai->glue);
		ai->g.section = DNS_S_ALL & ~DNS_S_QD;
		ai->g.name    = ai->g_cname;
		ai->g.type    = ai->af.qtype;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_FOREACH_G:
		if (!dns_rr_grep(&rr, 1, &ai->g, ai->glue, &error)) {
			if (dns_rr_i_count(&ai->g) > 0)
				dns_ai_goto(DNS_AI_S_FOREACH_I);
			else
				dns_ai_goto(DNS_AI_S_SUBMIT_G);
		}

		if ((error = dns_any_parse(&any, &rr, ai->glue)))
			return error;

		return dns_ai_setent(ent, &any, rr.type, ai);
	case DNS_AI_S_SUBMIT_G:
		/* skip if already queried */
		if (dns_rr_grep(&rr, 1, dns_rr_i_new(ai->glue, .section = DNS_S_QD, .name = ai->g.name, .type = ai->g.type), ai->glue, &error))
			dns_ai_goto(DNS_AI_S_FOREACH_I);
		/* skip if we recursed (CNAME chains should have been handled in the resolver) */
		if (++ai->g_depth > 1)
			dns_ai_goto(DNS_AI_S_FOREACH_I);

		if ((error = dns_res_submit(ai->res, ai->g.name, ai->g.type, DNS_C_IN)))
			return error;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_CHECK_G:
		if ((error = dns_res_check(ai->res)))
			return error;

		ai->state++;
		/* FALL THROUGH */
	case DNS_AI_S_FETCH_G:
		if (!(ans = dns_res_fetch_and_study(ai->res, &error)))
			return error;

		glue = dns_p_merge(ai->glue, DNS_S_ALL, ans, DNS_S_ALL, &error);
		dns_p_setptr(&ans, NULL);
		if (!glue)
			return error;

		if (ai->glue != ai->answer)
			dns_p_free(ai->glue);
		ai->glue = glue;

		if (!dns_d_cname(ai->cname, sizeof ai->cname, ai->g.name, strlen(ai->g.name), ai->glue, &error))
			dns_ai_goto(DNS_AI_S_FOREACH_I);

		dns_ai_goto(DNS_AI_S_ITERATE_G);
	case DNS_AI_S_DONE:
		if (ai->found) {
			return ENOENT; /* TODO: Just return 0 */
		} else if (ai->answer) {
			switch (dns_p_rcode(ai->answer)) {
			case DNS_RC_NOERROR:
				/* FALL THROUGH */
			case DNS_RC_NXDOMAIN:
				return DNS_ENONAME;
			default:
				return DNS_EFAIL;
			}
		} else {
			return DNS_EFAIL;
		}
	default:
		return EINVAL;
	} /* switch() */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5f8, %rsp            # imm = 0x5F8
movq %rdi, 0x10(%rsp)
andq $0x0, (%rdi)
movq %rsi, %rbx
leaq 0x158(%rsi), %r13
leaq 0x230(%rsi), %r12
leaq 0x38(%rsi), %rax
movq %rax, 0x18(%rsp)
leaq 0x330(%rsi), %rax
movq %rax, 0x50(%rsp)
leaq 0x168(%rsi), %rax
movq %rax, 0x70(%rsp)
leaq 0x1a0(%rsi), %rax
movq %rax, 0x48(%rsp)
leaq 0x1b0(%rsi), %rax
movq %rax, 0x40(%rsp)
leaq 0x430(%rsi), %rax
movq %rax, 0x68(%rsp)
leaq 0x1c0(%rsi), %rax
movq %rax, 0x78(%rsp)
leaq 0x1f8(%rsi), %rax
movq %rax, 0x60(%rsp)
leaq 0x208(%rsi), %rax
movq %rax, 0x58(%rsp)
movl 0x534(%rsi), %ecx
pushq $0x8
popq %rbp
movl $0xff, %r15d
pushq $0x1
popq %r14
cmpl $0xd, %ecx
ja 0x2d573
movl %ecx, %eax
leaq 0x4dad(%rip), %rdx      # 0x31bfc
movslq (%rdx,%rax,4), %rcx
addq %rdx, %rcx
movl %ebp, %eax
jmpq *%rcx
movl $0x1, 0x534(%rbx)
movl 0x148(%rbx), %ecx
movl %ecx, %eax
shrl $0x8, %eax
andl %r15d, %eax
testb %cl, %cl
je 0x2d06d
andl %r15d, %ecx
cmpl $0x15, %ecx
je 0x2d078
cmpl $0x17, %ecx
je 0x2d078
cmpl $0x22, %ecx
je 0x2d0fd
cmpl $0x20, %ecx
jne 0x2d10c
movq 0x140(%rbx), %rcx
btl $0x9, %ecx
jae 0x2d0fd
shll $0x8, %eax
orl $0x22, %eax
movl %eax, 0x148(%rbx)
movabsq $0x1c0000000a, %rax     # imm = 0x1C0000000A
movq %rax, 0x14c(%rbx)
andq $-0x201, %rcx           # imm = 0xFDFF
jmp 0x2d14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
andq $0x0, 0xb0(%rsp)
movl $0x1, 0x80(%rsp)
movq 0x1c8(%rbx), %rax
movq %rax, 0x88(%rsp)
movl 0x1d0(%rbx), %eax
movl %eax, 0x90(%rsp)
leaq 0xb8(%rsp), %rax
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq 0x160(%rbx), %rcx
leaq 0x28(%rsp), %rdi
movl %r14d, %esi
leaq 0x80(%rsp), %rdx
leaq 0xc(%rsp), %r8
callq 0xfe00
pushq $0x6
popq %rcx
testl %eax, %eax
jne 0x2d4c8
movl 0x530(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x530(%rbx)
pushq $0x6
popq %rcx
testl %eax, %eax
jg 0x2d4c8
movq 0x30(%rbx), %rdi
movq 0x1c8(%rbx), %rsi
movl 0x1d0(%rbx), %edx
movl %r14d, %ecx
callq 0xf350
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
callq 0xf530
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x2d5b0
incl 0x534(%rbx)
movq %r13, %r14
movq 0x30(%rbx), %rdi
leaq 0xc(%rsp), %rbp
movq %rbp, %rsi
callq 0x2d743
testq %rax, %rax
je 0x2d4e7
movq %rax, %r13
movq 0x160(%rbx), %rdi
pushq $0xf
popq %rcx
movl %ecx, %esi
movq %rax, %rdx
movq %rbp, %r8
callq 0x104c0
movq %rax, %rbp
movq %r13, %rdi
callq 0xffc0
andq $0x0, 0x20(%rsp)
testq %rbp, %rbp
je 0x2d4e7
movq 0x160(%rbx), %rdi
cmpq 0x158(%rbx), %rdi
je 0x2d01b
callq 0xffc0
movq %rbp, 0x160(%rbx)
movq 0x1c8(%rbx), %r13
movq %r13, %rdi
callq 0xf580
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %r13, %rdx
movq %rax, %rcx
movq %rbp, %r8
leaq 0xc(%rsp), %r9
callq 0xfff0
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leal 0x6(%rcx,%rcx), %ecx
movq %r14, %r13
pushq $0x8
popq %rbp
movl $0xff, %r15d
pushq $0x1
popq %r14
jmp 0x2d4c8
cmpq $0x0, 0x30(%rbx)
je 0x2d11c
movl %eax, %edx
movl %eax, %edi
addq $0x169, %rdi            # imm = 0x169
movl %eax, %esi
shll $0x8, %esi
addl $0x100, %esi            # imm = 0x100
cmpl $0x2, %edx
jg 0x2d0ee
movq 0x30(%rbx), %rcx
movq 0x300(%rcx), %rcx
movl (%rcx,%rdi,4), %r8d
testl %r8d, %r8d
je 0x2d0f9
cmpl $0x20, %r8d
ja 0x2d0c2
leal -0x1(%r8), %r9d
movq 0x140(%rbx), %rcx
movzbl %r9b, %r9d
btq %r9, %rcx
jb 0x2d0c9
incq %rdi
incl %edx
jmp 0x2d088
cmpl $0xa, %r8d
je 0x2d4d3
incl %edx
movl %edx, %eax
cmpl $0x2, %r8d
jne 0x2d07a
andl $0xff00, %esi           # imm = 0xFF00
orl $0x15, %esi
movl %esi, 0x148(%rbx)
jmp 0x2d138
cmpl $0x4, %eax
pushq $0x3
popq %rcx
cmovll %ecx, %eax
jmp 0x2d0fd
incl %edx
movl %edx, %eax
shll $0x8, %eax
orl $0x25, %eax
movzwl %ax, %eax
movl %eax, 0x148(%rbx)
andq $0x0, 0x14c(%rbx)
pushq $0xd
popq %rcx
jmp 0x2d4c8
movq 0x140(%rbx), %rcx
testb $0x2, %cl
je 0x2cea8
shll $0x8, %eax
orl $0x20, %eax
movl %eax, 0x148(%rbx)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14c(%rbx)
andq $-0x3, %rcx
movq %rcx, 0x140(%rbx)
movl $0x2, 0x534(%rbx)
movq %r13, %r15
movq %r12, %r14
pushq $0x2
popq %rdi
movq 0x18(%rsp), %r13
movq %r13, %rsi
leaq 0xe0(%rsp), %r12
movq %r12, %rdx
callq 0x10a40
cmpl $0x1, %eax
jne 0x2d1aa
cmpl $0x2, 0x14c(%rbx)
pushq $0x1
popq %rax
movl %eax, %ecx
movq %r14, %r12
movl %eax, %r14d
movq %r15, %r13
movl $0xff, %r15d
jne 0x2d4c8
jmp 0x2d578
pushq $0xa
popq %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x10a40
cmpl $0x1, %eax
jne 0x2d1e3
cmpl $0xa, 0x14c(%rbx)
pushq $0x1
popq %rax
movl %eax, %ecx
movq %r14, %r12
movl %eax, %r14d
movq %r15, %r13
movl $0xff, %r15d
jne 0x2d4c8
jmp 0x2d58e
testb $0x4, (%rbx)
pushq $0x1
popq %rax
movl %eax, %ecx
movq %r14, %r12
movl %eax, %r14d
movq %r15, %r13
movl $0xff, %r15d
jne 0x2d4c8
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x2d5c9
movl 0x138(%rbx), %edx
testl %edx, %edx
movq 0x18(%rsp), %rsi
jne 0x2d228
movl 0x150(%rbx), %edx
movl %r14d, %ecx
callq 0xf350
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
callq 0xf530
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x2d5b0
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
leaq 0xc(%rsp), %r15
movq %r15, %rsi
callq 0x2d743
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x2d4e7
movq 0x160(%rbx), %rdi
cmpq 0x158(%rbx), %rdi
je 0x2d285
callq 0xffc0
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2cab2
movq %rax, 0x160(%rbx)
movq 0x158(%rbx), %rbp
movl $0x100, %esi            # imm = 0x100
leaq 0x4f0(%rsp), %rdi
pushq $0xc
popq %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0xff50
testq %rax, %rax
je 0x2d4e7
cmpq $0xff, %rax
ja 0x2d533
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
leaq 0x4f0(%rsp), %rdx
movq %rax, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0xfff0
testq %rax, %rax
je 0x2d4e7
movl $0x100, %edx            # imm = 0x100
movq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xf4f0
movq 0x48(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x40(%rsp), %rax
movups %xmm0, (%rax)
movl $0x2, 0x168(%rbx)
movq %r15, 0x170(%rbx)
movl 0x138(%rbx), %eax
testl %eax, %eax
jne 0x2d340
movl 0x150(%rbx), %eax
movl %eax, 0x178(%rbx)
movq 0x17c33(%rip), %rax     # 0x44f80
movq %rax, 0x190(%rbx)
incl 0x534(%rbx)
pushq $0x8
popq %rbp
movl $0xff, %r15d
movq (%r13), %rcx
leaq 0x28(%rsp), %rdi
movl %r14d, %esi
movq 0x70(%rsp), %rdx
leaq 0xc(%rsp), %r8
callq 0xfe00
movl %r14d, %ecx
testl %eax, %eax
je 0x2d4c8
movq (%r13), %rdx
leaq 0xe0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xff00
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x2d5b0
movzwl 0x13c(%rbx), %eax
movw %ax, 0x13e(%rbx)
movl 0x30(%rsp), %ecx
cmpl $0x1c, %ecx
je 0x2d4f0
cmpl $0x1, %ecx
je 0x2d4f0
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
leaq 0xe0(%rsp), %rdx
callq 0x10460
pushq $0x6
popq %rcx
testq %rax, %rax
je 0x2d4c8
movq (%r13), %r8
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %r12, %rdx
movq %rax, %rcx
leaq 0xc(%rsp), %r9
callq 0xfff0
testq %rax, %rax
je 0x2d4e7
cmpl $0x21, 0x30(%rsp)
jne 0x2d42b
movzwl 0xe4(%rsp), %eax
movw %ax, 0x13e(%rbx)
movl 0x534(%rbx), %eax
addl $0x2, %eax
andl $0x0, 0x530(%rbx)
movl %eax, 0x534(%rbx)
movl $0x100, %edx            # imm = 0x100
movq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xf4f0
movq 0x60(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x58(%rsp), %rax
movups %xmm0, (%rax)
movl $0xe, 0x1c0(%rbx)
movq %r15, 0x1c8(%rbx)
movl $0xff, %r15d
movl 0x150(%rbx), %eax
movl %eax, 0x1d0(%rbx)
incl 0x534(%rbx)
movq 0x160(%rbx), %rcx
leaq 0x28(%rsp), %rdi
movl %r14d, %esi
movq 0x78(%rsp), %rdx
leaq 0xc(%rsp), %r8
callq 0xfe00
testl %eax, %eax
jne 0x2d504
xorl %eax, %eax
cmpw $0x0, 0x1fa(%rbx)
sete %al
leal 0x6(,%rax,4), %ecx
movl %ecx, 0x534(%rbx)
jmp 0x2ce3d
andl $0xff00, %esi           # imm = 0xFF00
orl $0x17, %esi
movl %esi, 0x148(%rbx)
jmp 0x2cebe
movl 0xc(%rsp), %eax
jmp 0x2d5b0
leaq 0xe0(%rsp), %rsi
movq 0x10(%rsp), %rdi
movl %ecx, %edx
jmp 0x2d5a8
movq 0x160(%rbx), %rdx
leaq 0xe0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xff00
testl %eax, %eax
jne 0x2d5b0
movl 0x30(%rsp), %edx
leaq 0xe0(%rsp), %rsi
jmp 0x2d5a3
movl $0x9b918cc1, %eax       # imm = 0x9B918CC1
jmp 0x2d5b0
cmpl $0x0, 0x538(%rbx)
pushq $0x2
popq %rax
jne 0x2d5b0
movq (%r13), %rax
testq %rax, %rax
je 0x2d5c2
movl 0x34(%rax), %ecx
shrl $0x14, %ecx
movzbl 0x5f(%rax), %eax
andl $0xf, %eax
orl %ecx, %eax
sete %cl
cmpl $0x3, %eax
sete %al
orb %cl, %al
movzbl %al, %eax
xorl $0x9b918ccb, %eax       # imm = 0x9B918CCB
jmp 0x2d5b0
pushq $0x16
popq %rax
jmp 0x2d5b0
movl $0x1, 0x534(%rbx)
leaq 0xe0(%rsp), %rsi
pushq $0x1
jmp 0x2d5a2
movl $0x1, 0x534(%rbx)
leaq 0xe0(%rsp), %rsi
pushq $0x1c
popq %rdx
movq 0x10(%rsp), %rdi
movq %rbx, %rcx
callq 0x2d5e8
addq $0x5f8, %rsp            # imm = 0x5F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x9b918ccb, %eax       # imm = 0x9B918CCB
jmp 0x2d5b0
leaq 0x6b11(%rip), %rdi      # 0x340e1
leaq 0x6896(%rip), %rsi      # 0x33e6d
leaq 0x6b0b(%rip), %rcx      # 0x340e9
movl $0x20a3, %edx           # imm = 0x20A3
callq 0xf8e0