// File: /workspace/github_c_makefile_star2_O3/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 $0x5d8, %rsp            # imm = 0x5D8
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
movq $0x0, (%rdi)
leaq 0x230(%rsi), %r15
leaq 0x38(%rsi), %r13
leaq 0x330(%rsi), %rax
movq %rax, 0x58(%rsp)
leaq 0x168(%rsi), %r12
leaq 0x1a0(%rsi), %rax
movq %rax, 0x50(%rsp)
leaq 0x1b0(%rsi), %rax
movq %rax, 0x48(%rsp)
leaq 0x430(%rsi), %rax
movq %rax, 0x40(%rsp)
leaq 0x1c0(%rsi), %r14
leaq 0x1f8(%rsi), %rax
movq %rax, 0x38(%rsp)
leaq 0x208(%rsi), %rax
movq %rax, 0x30(%rsp)
movl 0x534(%rsi), %ebp
movq %r14, 0x28(%rsp)
cmpl $0xd, %ebp
ja 0x31fa2
movl %ebp, %eax
leaq 0x5420(%rip), %rcx      # 0x36bfc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0x534(%rbx)
movl 0x148(%rbx), %ecx
movl %ecx, %eax
shrl $0x8, %eax
movl $0xff, %edx
andl %edx, %eax
andl %edx, %ecx
cmpl $0x16, %ecx
jle 0x31a0a
cmpl $0x17, %ecx
je 0x31a23
cmpl $0x22, %ecx
je 0x31ab2
cmpl $0x20, %ecx
jne 0x31ac1
movq 0x140(%rbx), %rcx
btl $0x9, %ecx
jae 0x31ab2
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 0x31b07
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x90(%rsp)
movl $0x1, 0x60(%rsp)
movq 0x1c8(%rbx), %rax
movq %rax, 0x68(%rsp)
movl 0x1d0(%rbx), %eax
movl %eax, 0x70(%rsp)
leaq 0x98(%rsp), %rax
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq 0x160(%rbx), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
leaq 0x60(%rsp), %rdx
leaq 0x4(%rsp), %r8
callq 0xfd70
movl $0x6, %ebp
testl %eax, %eax
jne 0x31ee9
movl 0x530(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x530(%rbx)
testl %eax, %eax
jg 0x31ee9
movq 0x30(%rbx), %rdi
movq 0x1c8(%rbx), %rsi
movl 0x1d0(%rbx), %edx
movl $0x1, %ecx
callq 0xf340
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
callq 0xf510
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x31fa7
incl 0x534(%rbx)
movq 0x30(%rbx), %rax
cmpl $0x16, 0x4b8(%rax)
jne 0x31f11
movq %r12, %r14
movq %r13, %r12
movq 0x4d8(%rax), %r13
movq $0x0, 0x4d8(%rax)
testq %r13, %r13
je 0x31f1b
movq %r13, %rdi
callq 0xf7a0
movq 0x160(%rbx), %rdi
movl $0xf, %esi
movq %r13, %rdx
movl $0xf, %ecx
leaq 0x4(%rsp), %r8
callq 0x10410
movq %rax, %rbp
movq %r13, %rdi
callq 0xff30
testq %rbp, %rbp
je 0x31f08
movq 0x160(%rbx), %rdi
cmpq 0x158(%rbx), %rdi
je 0x319b0
callq 0xff30
movq %rbp, 0x160(%rbx)
movq 0x1c8(%rbx), %r13
movq %r13, %rdi
callq 0xf560
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r13, %rdx
movq %rax, %rcx
movq %rbp, %r8
leaq 0x4(%rsp), %r9
callq 0xff60
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leal 0x6(,%rcx,2), %ebp
movq %r12, %r13
movq %r14, %r12
movq 0x28(%rsp), %r14
jmp 0x31ee9
movl $0x8, %eax
jmp 0x31e38
testl %ecx, %ecx
je 0x31a18
cmpl $0x15, %ecx
je 0x31a23
jmp 0x31ac1
cmpq $0x0, 0x30(%rbx)
je 0x31ad6
cmpl $0x2, %eax
jg 0x31ab2
movq 0x30(%rbx), %rcx
movq 0x300(%rcx), %rcx
movl %eax, %edx
leal -0x1(%rax), %edi
leaq (%rcx,%rdx,4), %rsi
addq $0x5a4, %rsi            # imm = 0x5A4
shll $0x8, %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, %edx
movl %edi, %eax
movl (%rsi), %edi
testl %edi, %edi
je 0x31aa8
cmpl $0x21, %edi
jae 0x31a73
leal -0x1(%rdi), %r8d
movq 0x140(%rbx), %rcx
movzbl %r8b, %r8d
btq %r8, %rcx
jb 0x31a86
incl %eax
addq $0x4, %rsi
addl $0x100, %edx            # imm = 0x100
cmpl $0x2, %eax
jl 0x31a53
jmp 0x31aad
cmpl $0xa, %edi
je 0x31ef4
addl $0x2, %eax
cmpl $0x2, %edi
jne 0x31a23
andl $0xff00, %edx           # imm = 0xFF00
orl $0x15, %edx
movl %edx, 0x148(%rbx)
jmp 0x31af2
addl $0x2, %eax
jmp 0x31ab2
movl $0x3, %eax
shll $0x8, %eax
orl $0x25, %eax
movzwl %ax, %eax
movl %eax, 0x148(%rbx)
movq $0x0, 0x14c(%rbx)
movl $0xd, %ebp
jmp 0x31ee9
movq 0x140(%rbx), %rcx
testb $0x2, %cl
je 0x3182e
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)
movl $0x2, %edi
movq %r13, %rsi
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdx
callq 0x10960
cmpl $0x1, %eax
jne 0x31b4c
movl $0x1, %ebp
cmpl $0x2, 0x14c(%rbx)
jne 0x31ee9
jmp 0x31fb9
movl $0xa, %edi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10960
movl $0x1, %ebp
cmpl $0x1, %eax
jne 0x31b78
cmpl $0xa, 0x14c(%rbx)
jne 0x31ee9
jmp 0x31fda
testb $0x4, (%rbx)
jne 0x31ee9
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x32002
movl 0x138(%rbx), %edx
testl %edx, %edx
jne 0x31ba4
movl 0x150(%rbx), %edx
movq %r13, %rsi
movl $0x1, %ecx
callq 0xf340
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
callq 0xf510
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x31fa7
incl 0x534(%rbx)
movq 0x30(%rbx), %rax
cmpl $0x16, 0x4b8(%rax)
jne 0x31f11
movq 0x4d8(%rax), %rbp
movq $0x0, 0x4d8(%rax)
testq %rbp, %rbp
je 0x31f1b
movq %rbp, %rdi
callq 0xf7a0
movq 0x158(%rbx), %rdi
movq 0x160(%rbx), %rax
cmpq %rdi, %rax
je 0x31c28
movq %rax, %rdi
callq 0xff30
movq 0x158(%rbx), %rdi
callq 0xff30
movq %rbp, 0x158(%rbx)
movq %rbp, 0x160(%rbx)
movl $0x100, %esi            # imm = 0x100
leaq 0x4d0(%rsp), %rdi
movl $0xc, %edx
movq %rbp, %rcx
leaq 0x4(%rsp), %r8
callq 0xfec0
testq %rax, %rax
je 0x31f08
cmpq $0xff, %rax
ja 0x31f5d
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
leaq 0x4d0(%rsp), %rdx
movq %rax, %rcx
movq %rbp, %r8
leaq 0x4(%rsp), %r9
callq 0xff60
testq %rax, %rax
je 0x31f08
xorl %eax, %eax
movb (%r15,%rax), %cl
movb %cl, 0x100(%r15,%rax)
testb %cl, %cl
je 0x31cc8
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x31c9a
movb $0x0, 0x42f(%rbx)
addq %r15, %rax
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x31cbf
movq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x48(%rsp), %rax
movups %xmm0, (%rax)
movl $0x2, 0x168(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x170(%rbx)
movl 0x138(%rbx), %eax
testl %eax, %eax
jne 0x31d01
movl 0x150(%rbx), %eax
movl %eax, 0x178(%rbx)
movq 0x15272(%rip), %rax     # 0x46f80
movq %rax, 0x190(%rbx)
incl 0x534(%rbx)
movq 0x158(%rbx), %rcx
movl $0x1, %ebp
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq %r12, %rdx
leaq 0x4(%rsp), %r8
callq 0xfd70
testl %eax, %eax
je 0x31ee9
movq 0x158(%rbx), %rdx
leaq 0xc0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xfe70
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x31fa7
movzwl 0x13c(%rbx), %eax
movw %ax, 0x13e(%rbx)
movl 0x18(%rsp), %edx
cmpl $0x1, %edx
je 0x31f46
cmpl $0x1c, %edx
je 0x31f46
movq $-0x40, %rax
leaq 0x149e3(%rip), %rcx     # 0x46780
cmpl %edx, 0x40(%rax,%rcx)
jne 0x31dab
cmpq $0x0, 0x58(%rax,%rcx)
jne 0x31dc1
addq $0x40, %rax
cmpq $0x300, %rax            # imm = 0x300
jb 0x31d9d
movl $0x6, %ebp
jmp 0x31ee9
movq 0x78(%rax,%rcx), %rcx
movl $0x6, %ebp
testq %rcx, %rcx
je 0x31ee9
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
leaq 0xc0(%rsp), %rdx
xorl %eax, %eax
callq *%rcx
testq %rax, %rax
je 0x31ee9
movq 0x158(%rbx), %r8
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r15, %rdx
movq %rax, %rcx
leaq 0x4(%rsp), %r9
callq 0xff60
testq %rax, %rax
je 0x31f08
cmpl $0x21, 0x18(%rsp)
jne 0x31e2f
movzwl 0xc4(%rsp), %eax
movw %ax, 0x13e(%rbx)
movl 0x534(%rbx), %eax
addl $0x2, %eax
movl $0x0, 0x530(%rbx)
movl %eax, 0x534(%rbx)
xorl %eax, %eax
movb (%r15,%rax), %cl
movb %cl, 0x200(%r15,%rax)
testb %cl, %cl
je 0x31e78
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x31e4a
movb $0x0, 0x52f(%rbx)
addq %r15, %rax
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x31e6f
movq 0x38(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x30(%rsp), %rax
movups %xmm0, (%rax)
movl $0xe, 0x1c0(%rbx)
movq 0x40(%rsp), %rax
movq %rax, 0x1c8(%rbx)
movl 0x150(%rbx), %eax
movl %eax, 0x1d0(%rbx)
incl 0x534(%rbx)
movq 0x160(%rbx), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq %r14, %rdx
leaq 0x4(%rsp), %r8
callq 0xfd70
testl %eax, %eax
jne 0x31f25
xorl %eax, %eax
cmpw $0x0, 0x1fa(%rbx)
sete %al
leal 0x6(,%rax,4), %ebp
movl %ebp, 0x534(%rbx)
jmp 0x317ca
andl $0xff00, %edx           # imm = 0xFF00
orl $0x17, %edx
movl %edx, 0x148(%rbx)
jmp 0x31844
movl 0x4(%rsp), %eax
jmp 0x31fa7
movl $0x9b918cc4, %eax       # imm = 0x9B918CC4
jmp 0x31fa7
movl $0x9b918cc8, %eax       # imm = 0x9B918CC8
jmp 0x31fa7
movq 0x160(%rbx), %rdx
leaq 0xc0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xfe70
testl %eax, %eax
jne 0x31fa7
movl 0x18(%rsp), %edx
leaq 0xc0(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq %rbx, %rcx
callq 0x32021
jmp 0x31fa7
movl $0x9b918cc1, %eax       # imm = 0x9B918CC1
jmp 0x31fa7
movl $0x2, %eax
cmpl $0x0, 0x538(%rbx)
jne 0x31fa7
movq 0x158(%rbx), %rax
testq %rax, %rax
je 0x31ffb
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 0x31fa7
movl $0x16, %eax
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x534(%rbx)
leaq 0xc0(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl $0x1, %edx
jmp 0x31f53
movl $0x1, 0x534(%rbx)
leaq 0xc0(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl $0x1c, %edx
jmp 0x31f53
movl $0x9b918ccb, %eax       # imm = 0x9B918CCB
jmp 0x31fa7
leaq 0x70e8(%rip), %rdi      # 0x390f1
leaq 0x6e6d(%rip), %rsi      # 0x38e7d
leaq 0x70e2(%rip), %rcx      # 0x390f9
movl $0x20a3, %edx           # imm = 0x20A3
callq 0xf890