// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0x44(%rbp)
movaps %xmm0, -0x50(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x64(%rbp)
subl $0x1, %eax
je 0x4222c
jmp 0x42222
movl -0x64(%rbp), %eax
subl $0x1c, %eax
je 0x42251
jmp 0x42280
movw $0x2, -0x50(%rbp)
movq -0x28(%rbp), %rax
movzwl 0x13e(%rax), %edi
callq 0xf0e0
movw %ax, -0x4e(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
jmp 0x4228c
movw $0xa, -0x50(%rbp)
movq -0x28(%rbp), %rax
movzwl 0x13e(%rax), %edi
callq 0xf0e0
movw %ax, -0x4e(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x4228c
movl $0x16, -0x4(%rbp)
jmp 0x4245d
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x422dd
movq -0x28(%rbp), %rax
movsbl 0x230(%rax), %eax
cmpl $0x0, %eax
je 0x422ba
movq -0x28(%rbp), %rax
addq $0x230, %rax            # imm = 0x230
movq %rax, -0x70(%rbp)
jmp 0x422c6
movq -0x28(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0xf5c0
movq %rax, -0x60(%rbp)
jmp 0x422ed
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movzwl -0x50(%rbp), %edi
callq 0x3c6e0
addq $0x30, %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x4231a
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x42322
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0x42322
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rax
addq %rax, %rdi
callq 0x10260
movq -0x10(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x4234e
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x4245d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0xf7d0
movzwl -0x50(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x30, %rax
movq %rax, -0x88(%rbp)
movzwl -0x50(%rbp), %edi
callq 0x3c6e0
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq -0x50(%rbp), %rsi
callq 0xfb40
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movzwl -0x50(%rbp), %edi
callq 0x3c6e0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x42443
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x30, %rax
movq %rax, -0x98(%rbp)
movzwl -0x50(%rbp), %edi
callq 0x3c6e0
movq -0x98(%rbp), %rdi
addq %rax, %rdi
movq %rdi, -0x90(%rbp)
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq $0x1, %rdx
callq 0xfb40
movq -0x90(%rbp), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movl 0x538(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x538(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)