// File: /workspace/github_c_makefile_star2_O2/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 0x2d637
cmpl $0x1, %edx
jne 0x2d728
movw $0x2, 0x10(%rsp)
movzwl 0x13e(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x12(%rsp)
movl (%rsi), %eax
movl %eax, 0x14(%rsp)
movw $0x2, %bp
jmp 0x2d65a
movw $0xa, 0x10(%rsp)
movzwl 0x13e(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x12(%rsp)
movups (%rsi), %xmm0
movups %xmm0, 0x18(%rsp)
movw $0xa, %bp
movl (%rbx), %eax
testb $0x2, %al
movl %eax, 0x4(%rsp)
movq %rdi, %r12
jne 0x2d677
pushq $0x1
popq %rax
movq %rax, 0x8(%rsp)
pushq $0x30
popq %rdi
xorl %r15d, %r15d
jmp 0x2d6a4
leaq 0x230(%rbx), %r15
leaq 0x38(%rbx), %rax
cmpb $0x0, 0x230(%rbx)
cmoveq %rax, %r15
movq %r15, %rdi
callq 0xf580
movq %rax, %rdi
incq %rax
movq %rax, 0x8(%rsp)
addq $0x31, %rdi
movzwl %bp, %r14d
leaq 0x60e1(%rip), %rax      # 0x33790
movq (%rax,%r14,8), %r13
addq %r13, %rdi
callq 0x101a0
movq %rax, (%r12)
testq %rax, %rax
je 0x2d72d
movq %rax, %rbp
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movl %r14d, 0x4(%rax)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rbp)
movq %rbp, %r14
addq $0x30, %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0xfad0
movq %r14, 0x18(%rbp)
movl %r13d, 0x10(%rbp)
testb $0x2, 0x4(%rsp)
je 0x2d71e
addq %r13, %r14
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0xfad0
movq %r14, 0x20(%rbp)
incl 0x538(%rbx)
xorl %eax, %eax
jmp 0x2d734
pushq $0x16
popq %rax
jmp 0x2d734
callq 0xf0a0
movl (%rax), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq