// File: /workspace/github_c_makefile_star2_O1/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 $0x5e8, %rsp            # imm = 0x5E8
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
movq $0x0, (%rdi)
leaq 0x230(%rsi), %r15
leaq 0x38(%rsi), %rax
movq %rax, 0x10(%rsp)
leaq 0x330(%rsi), %rax
movq %rax, 0x40(%rsp)
leaq 0x1a0(%rsi), %rax
movq %rax, 0x38(%rsp)
leaq 0x1b0(%rsi), %rax
movq %rax, 0x30(%rsp)
leaq 0x168(%rsi), %rax
movq %rax, 0x60(%rsp)
leaq 0x430(%rsi), %rax
movq %rax, 0x58(%rsp)
leaq 0x1f8(%rsi), %rax
movq %rax, 0x50(%rsp)
leaq 0x208(%rsi), %rax
movq %rax, 0x48(%rsp)
leaq 0x1c0(%rsi), %rax
movq %rax, 0x68(%rsp)
leaq 0x4ed8(%rip), %r13      # 0x36c4c
leaq 0xd0(%rsp), %rbp
leaq 0x4(%rsp), %r14
leaq 0x149f8(%rip), %r12     # 0x46780
movl 0x534(%rbx), %eax
cmpq $0xd, %rax
ja 0x32565
movslq (%r13,%rax,4), %rax
addq %r13, %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 0x31f7a
cmpl $0x17, %ecx
je 0x31f93
cmpl $0x20, %ecx
je 0x32050
cmpl $0x22, %ecx
je 0x3205d
jmp 0x3206c
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0xc0(%rsp)
movl $0x1, 0x70(%rsp)
movq 0x1c8(%rbx), %rax
movq %rax, 0x78(%rsp)
movl 0x1d0(%rbx), %eax
movl %eax, 0x80(%rsp)
leaq 0xa8(%rsp), %rax
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq 0x160(%rbx), %rcx
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
leaq 0x70(%rsp), %rdx
movq %r14, %r8
callq 0xfd70
movl $0x6, %ebp
testl %eax, %eax
jne 0x32495
movl 0x530(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x530(%rbx)
testl %eax, %eax
jg 0x32495
movq 0x30(%rbx), %rdi
movq 0x1c8(%rbx), %rsi
movl 0x1d0(%rbx), %edx
movl $0x1, %ecx
callq 0xf340
movl $0x0, 0x4(%rsp)
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
callq 0xf510
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x3256a
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x32741
testq %rax, %rax
je 0x324db
movq %rax, %rbp
movq 0x160(%rbx), %rdi
movl $0xf, %esi
movq %rax, %rdx
movl $0xf, %ecx
movq %r14, %r8
callq 0x10410
movq %rax, %r13
movq %rbp, %rdi
callq 0xff30
testq %r13, %r13
je 0x324db
movq 0x160(%rbx), %rdi
cmpq 0x158(%rbx), %rdi
je 0x31f30
callq 0xff30
movq %r13, 0x160(%rbx)
movq 0x1c8(%rbx), %rbp
movq %rbp, %rdi
callq 0xf560
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %rbp, %rdx
movq %rax, %rcx
movq %r13, %r8
movq %r14, %r9
callq 0xff60
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leal 0x6(,%rcx,2), %ebp
leaq 0x4cd7(%rip), %r13      # 0x36c4c
jmp 0x32495
testl %ecx, %ecx
je 0x31f88
cmpl $0x15, %ecx
je 0x31f93
jmp 0x3206c
cmpq $0x0, 0x30(%rbx)
je 0x32044
leaq 0xd0(%rsp), %rbp
cmpl $0x2, %eax
jg 0x3205d
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 0x32038
cmpl $0x21, %edi
jae 0x31feb
leal -0x1(%rdi), %r8d
movq 0x140(%rbx), %rcx
movzbl %r8b, %r8d
btq %r8, %rcx
jb 0x31ffe
incl %eax
addq $0x4, %rsi
addl $0x100, %edx            # imm = 0x100
cmpl $0x2, %eax
jl 0x31fcb
jmp 0x3203d
cmpl $0xa, %edi
je 0x324af
addl $0x2, %eax
cmpl $0x2, %edi
jne 0x31f9b
andl $0xff00, %edx           # imm = 0xFF00
orl $0x15, %edx
movl %edx, 0x148(%rbx)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14c(%rbx)
andq $-0x3, %rcx
jmp 0x320d0
addl $0x2, %eax
jmp 0x3205d
movl $0x3, %eax
jmp 0x3205d
movq 0x140(%rbx), %rcx
testb $0x2, %cl
jne 0x320a7
movq 0x140(%rbx), %rcx
btl $0x9, %ecx
jb 0x32081
shll $0x8, %eax
orl $0x25, %eax
movzwl %ax, %eax
movl %eax, 0x148(%rbx)
movq $0x0, 0x14c(%rbx)
movl $0xd, %ebp
jmp 0x32495
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 0x320c8
shll $0x8, %eax
orl $0x20, %eax
movl %eax, 0x148(%rbx)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14c(%rbx)
andq $-0x3, %rcx
leaq 0xd0(%rsp), %rbp
movq %rcx, 0x140(%rbx)
incl 0x534(%rbx)
movl $0x2, %edi
movq 0x10(%rsp), %r13
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10960
cmpl $0x1, %eax
jne 0x32115
movl $0x1, %ebp
cmpl $0x2, 0x14c(%rbx)
leaq 0x4b42(%rip), %r13      # 0x36c4c
jne 0x32495
jmp 0x3257c
movl $0xa, %edi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10960
movl $0x1, %ebp
cmpl $0x1, %eax
jne 0x32148
cmpl $0xa, 0x14c(%rbx)
leaq 0x4b0f(%rip), %r13      # 0x36c4c
jne 0x32495
jmp 0x3259d
testb $0x4, (%rbx)
leaq 0x4afa(%rip), %r13      # 0x36c4c
jne 0x32495
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x325c5
movl 0x138(%rbx), %edx
testl %edx, %edx
movq 0x10(%rsp), %rsi
jne 0x32180
movl 0x150(%rbx), %edx
movl $0x1, %ecx
callq 0xf340
movl $0x0, 0x4(%rsp)
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
callq 0xf510
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x3256a
incl 0x534(%rbx)
movq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x32741
testq %rax, %rax
je 0x324db
movq %rax, %r13
movq 0x160(%rbx), %rdi
cmpq 0x158(%rbx), %rdi
je 0x321e0
callq 0xff30
movq 0x158(%rbx), %rdi
callq 0xff30
movq %r13, 0x158(%rbx)
movq %r13, 0x160(%rbx)
movl $0x100, %esi            # imm = 0x100
leaq 0x4e0(%rsp), %rbp
movq %rbp, %rdi
movl $0xc, %edx
movq %r13, %rcx
movq %r14, %r8
callq 0xfec0
testq %rax, %rax
je 0x324db
cmpq $0xff, %rax
ja 0x32520
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %rbp, %rdx
movq %rax, %rcx
movq %r13, %r8
movq %r14, %r9
callq 0xff60
testq %rax, %rax
je 0x324db
xorl %eax, %eax
leaq 0x49f2(%rip), %r13      # 0x36c4c
movb (%r15,%rax), %cl
movb %cl, 0x100(%r15,%rax)
testb %cl, %cl
je 0x32288
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x3225a
movb $0x0, 0x42f(%rbx)
addq %r15, %rax
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x3227f
movq 0x38(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x30(%rsp), %rax
movups %xmm0, (%rax)
movl $0x2, 0x168(%rbx)
movq 0x40(%rsp), %rax
movq %rax, 0x170(%rbx)
movl 0x138(%rbx), %eax
testl %eax, %eax
jne 0x322c1
movl 0x150(%rbx), %eax
movl %eax, 0x178(%rbx)
movq 0x14cb2(%rip), %rax     # 0x46f80
movq %rax, 0x190(%rbx)
incl 0x534(%rbx)
movq 0x158(%rbx), %rcx
movl $0x1, %ebp
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
movq 0x60(%rsp), %rdx
movq %r14, %r8
callq 0xfd70
testl %eax, %eax
je 0x32495
movq 0x158(%rbx), %rdx
leaq 0xd0(%rsp), %rbp
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0xfe70
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x3256a
movzwl 0x13c(%rbx), %eax
movw %ax, 0x13e(%rbx)
movl 0x20(%rsp), %edx
cmpl $0x1, %edx
je 0x32509
cmpl $0x1c, %edx
je 0x32509
xorl %eax, %eax
cmpl %edx, (%rax,%r12)
jne 0x32362
cmpq $0x0, 0x18(%rax,%r12)
jne 0x32375
leaq 0x40(%rax), %rcx
cmpq $0x300, %rax            # imm = 0x300
movq %rcx, %rax
jb 0x32354
xorl %eax, %eax
jmp 0x32378
addq %r12, %rax
testq %rax, %rax
je 0x3239a
movq 0x38(%rax), %rcx
testq %rcx, %rcx
je 0x3239a
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq *%rcx
movq %rax, %rcx
jmp 0x3239c
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x324a8
movq 0x158(%rbx), %r8
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r15, %rdx
movq %r14, %r9
callq 0xff60
testq %rax, %rax
je 0x324db
cmpl $0x21, 0x20(%rsp)
jne 0x323de
movzwl 0xd4(%rsp), %eax
movw %ax, 0x13e(%rbx)
incl 0x534(%rbx)
movl $0x0, 0x530(%rbx)
incl 0x534(%rbx)
xorl %eax, %eax
movb (%r15,%rax), %cl
movb %cl, 0x200(%r15,%rax)
testb %cl, %cl
je 0x32424
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x323f6
movb $0x0, 0x52f(%rbx)
addq %r15, %rax
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x3241b
movq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x48(%rsp), %rax
movups %xmm0, (%rax)
movl $0xe, 0x1c0(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x1c8(%rbx)
movl 0x150(%rbx), %eax
movl %eax, 0x1d0(%rbx)
incl 0x534(%rbx)
movq 0x160(%rbx), %rcx
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
movq 0x68(%rsp), %rdx
movq %r14, %r8
callq 0xfd70
testl %eax, %eax
jne 0x324e4
xorl %eax, %eax
cmpw $0x0, 0x1fa(%rbx)
sete %al
leal 0x6(,%rax,4), %ebp
movl %ebp, 0x534(%rbx)
leaq 0xd0(%rsp), %rbp
jmp 0x31d88
movl $0x6, %ebp
jmp 0x32495
andl $0xff00, %edx           # imm = 0xFF00
orl $0x17, %edx
movl %edx, 0x148(%rbx)
movabsq $0x1c0000000a, %rax     # imm = 0x1C0000000A
movq %rax, 0x14c(%rbx)
andq $-0x201, %rcx           # imm = 0xFDFF
jmp 0x320d0
movl 0x4(%rsp), %eax
jmp 0x3256a
movq 0x160(%rbx), %rdx
leaq 0xd0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0xfe70
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x3256a
movl 0x20(%rsp), %edx
leaq 0xd0(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq %rbx, %rcx
callq 0x325e4
jmp 0x3256a
movl $0x9b918cc1, %eax       # imm = 0x9B918CC1
jmp 0x3256a
movl $0x2, %eax
cmpl $0x0, 0x538(%rbx)
jne 0x3256a
movq 0x158(%rbx), %rax
testq %rax, %rax
je 0x325be
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 0x3256a
movl $0x16, %eax
addq $0x5e8, %rsp            # imm = 0x5E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x534(%rbx)
leaq 0xd0(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl $0x1, %edx
jmp 0x32516
movl $0x1, 0x534(%rbx)
leaq 0xd0(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl $0x1c, %edx
jmp 0x32516
movl $0x9b918ccb, %eax       # imm = 0x9B918CCB
jmp 0x3256a
leaq 0x6b65(%rip), %rdi      # 0x39131
leaq 0x68ea(%rip), %rsi      # 0x38ebd
leaq 0x6b5f(%rip), %rcx      # 0x39139
movl $0x20a3, %edx           # imm = 0x20A3
callq 0xf890