// File: /workspace/github_c_makefile_star2_O1/wahern[P]cqueues/src/lib/dns.c
// Function: dns_ai_setent
static int dns_ai_setent(struct addrinfo **ent, union dns_any *any, enum dns_type type, struct dns_addrinfo *ai) {
	union { struct sockaddr saddr; struct sockaddr_in sin; struct sockaddr_in6 sin6; } saddr = {0};
	const char *cname;
	size_t clen;

	switch (type) {
	case DNS_T_A:
		saddr.sin.sin_family = AF_INET;
		saddr.sin.sin_port = htons(ai->port);

		memcpy(&saddr.sin.sin_addr, any, sizeof saddr.sin.sin_addr);

		break;
	case DNS_T_AAAA:
		saddr.sin6.sin6_family = AF_INET6;
		saddr.sin6.sin6_port = htons(ai->port);

		memcpy(&saddr.sin6.sin6_addr, any, sizeof saddr.sin6.sin6_addr);

		break;
	default:
		return EINVAL;
	} /* switch() */

	if (ai->hints.ai_flags & AI_CANONNAME) {
		cname	= (*ai->cname)? ai->cname : ai->qname;
		clen	= strlen(cname);
	} else {
		cname	= NULL;
		clen	= 0;
	}

	if (!(*ent = malloc(sizeof **ent + dns_sa_len(&saddr) + ((ai->hints.ai_flags & AI_CANONNAME)? clen + 1 : 0))))
		return dns_syerr();

	memset(*ent, '\0', sizeof **ent);

	(*ent)->ai_family	= saddr.saddr.sa_family;
	(*ent)->ai_socktype	= ai->hints.ai_socktype;
	(*ent)->ai_protocol	= ai->hints.ai_protocol;

	(*ent)->ai_addr		= memcpy((unsigned char *)*ent + sizeof **ent, &saddr, dns_sa_len(&saddr));
	(*ent)->ai_addrlen	= dns_sa_len(&saddr);

	if (ai->hints.ai_flags & AI_CANONNAME)
		(*ent)->ai_canonname	= memcpy((unsigned char *)*ent + sizeof **ent + dns_sa_len(&saddr), cname, clen + 1);

	ai->found++;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpl $0x1c, %edx
je 0x32634
movl $0x16, %eax
cmpl $0x1, %edx
jne 0x32732
movw $0x2, 0x10(%rsp)
movzwl 0x13e(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x12(%rsp)
movl (%rsi), %eax
movl %eax, 0x14(%rsp)
jmp 0x32653
movw $0xa, 0x10(%rsp)
movzwl 0x13e(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x12(%rsp)
movups (%rsi), %xmm0
movups %xmm0, 0x18(%rsp)
movl (%rbx), %eax
testb $0x2, %al
movl %eax, 0x4(%rsp)
movq %rdi, %r12
jne 0x32674
movl $0x1, %eax
movq %rax, 0x8(%rsp)
movl $0x30, %edi
xorl %r15d, %r15d
jmp 0x326a1
leaq 0x230(%rbx), %r15
leaq 0x38(%rbx), %rax
cmpb $0x0, 0x230(%rbx)
cmoveq %rax, %r15
movq %r15, %rdi
callq 0xf560
movq %rax, %rdi
incq %rax
movq %rax, 0x8(%rsp)
addq $0x31, %rdi
movzwl 0x10(%rsp), %r14d
leaq 0x6132(%rip), %rax      # 0x387e0
movq (%rax,%r14,8), %r13
addq %r13, %rdi
callq 0x10110
movq %rax, (%r12)
testq %rax, %rax
je 0x3272b
movq %rax, %rbp
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movl %r14d, 0x4(%rax)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%rbp)
movl 0xc(%rbx), %eax
movl %eax, 0xc(%rbp)
movq %rbp, %r14
addq $0x30, %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0xfa60
movq %r14, 0x18(%rbp)
movl %r13d, 0x10(%rbp)
testb $0x2, 0x4(%rsp)
je 0x32721
addq %r13, %r14
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0xfa60
movq %r14, 0x20(%rbp)
incl 0x538(%rbx)
xorl %eax, %eax
jmp 0x32732
callq 0xf0a0
movl (%rax), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq