// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/lib/dns.c
// Function: dns_socket
static int dns_socket(struct sockaddr *local, int type, int *error_) {
	int fd = -1, flags, error;
#if defined FIONBIO
	unsigned long opt;
#endif

	flags = 0;
#if HAVE_SOCK_CLOEXEC
	flags |= SOCK_CLOEXEC;
#endif
#if HAVE_SOCK_NONBLOCK
	flags |= SOCK_NONBLOCK;
#endif
	if (-1 == (fd = socket(local->sa_family, type|flags, 0)))
		goto soerr;

#if defined F_SETFD && !HAVE_SOCK_CLOEXEC
	if (-1 == fcntl(fd, F_SETFD, 1))
		goto syerr;
#endif

#if defined O_NONBLOCK && !HAVE_SOCK_NONBLOCK
	if (-1 == (flags = fcntl(fd, F_GETFL)))
		goto syerr;
	if (-1 == fcntl(fd, F_SETFL, flags | O_NONBLOCK))
		goto syerr;
#elif defined FIONBIO && HAVE_IOCTLSOCKET
	opt = 1;
	if (0 != ioctlsocket(fd, FIONBIO, &opt))
		goto soerr;
#endif

#if defined SO_NOSIGPIPE
	if (type != SOCK_DGRAM) {
		if (0 != setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){ 1 }, sizeof (int)))
			goto soerr;
	}
#endif

	if (local->sa_family != AF_INET && local->sa_family != AF_INET6)
		return fd;

	if (type != SOCK_DGRAM)
		return fd;

	/*
	 * FreeBSD, Linux, OpenBSD, OS X, and Solaris use random ports by
	 * default. Though the ephemeral range is quite small on OS X
	 * (49152-65535 on 10.10) and Linux (32768-60999 on 4.4.0, Ubuntu
	 * Xenial). See also RFC 6056.
	 *
	 * TODO: Optionally rely on the kernel to select a random port.
	 */
	if (*dns_sa_port(local->sa_family, local) == 0) {
		struct sockaddr_storage tmp;
		unsigned i, port;

		memcpy(&tmp, local, dns_sa_len(local));

		for (i = 0; i < DNS_SO_MAXTRY; i++) {
			port = 1025 + (dns_random() % 64510);

			*dns_sa_port(tmp.ss_family, &tmp) = htons(port);

			if (0 == bind(fd, (struct sockaddr *)&tmp, dns_sa_len(&tmp)))
				return fd;
		}

		/* NB: continue to next bind statement */
	}

	if (0 == bind(fd, local, dns_sa_len(local)))
		return fd;

	/* FALL THROUGH */
soerr:
	error = dns_soerr();

	goto error;
#if (defined F_SETFD && !HAVE_SOCK_CLOEXEC) || (defined O_NONBLOCK && !HAVE_SOCK_NONBLOCK)
syerr:
	error = dns_syerr();

	goto error;
#endif
error:
	*error_ = error;

	dns_socketclose(&fd, NULL);

	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
orl $0x80000, %eax          # imm = 0x80000
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
orl $0x800, %eax            # imm = 0x800
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzwl (%rax), %edi
movl -0x14(%rbp), %esi
orl -0x28(%rbp), %esi
xorl %edx, %edx
callq 0xf340
movl %eax, %ecx
movl %ecx, -0x24(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x3dcf1
jmp 0x3de7b
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
je 0x3dd14
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
cmpl $0xa, %eax
je 0x3dd14
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3dea2
cmpl $0x2, -0x14(%rbp)
je 0x3dd25
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3dea2
movq -0x10(%rbp), %rax
movzwl (%rax), %edi
movq -0x10(%rbp), %rsi
callq 0x3a1b0
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x3de35
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movzwl (%rax), %edi
callq 0x3c6e0
movq -0xd0(%rbp), %rsi
movq %rax, %rdx
leaq -0xb0(%rbp), %rdi
callq 0xfb40
movl $0x0, -0xb4(%rbp)
cmpl $0x7, -0xb4(%rbp)
jae 0x3de33
callq 0x10700
callq *(%rax)
movl $0xfbfe, %ecx           # imm = 0xFBFE
xorl %edx, %edx
divl %ecx
addl $0x401, %edx            # imm = 0x401
movl %edx, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movzwl %ax, %edi
callq 0xf0e0
movw %ax, -0xd6(%rbp)
movzwl -0xb0(%rbp), %edi
leaq -0xb0(%rbp), %rsi
callq 0x3a1b0
movw -0xd6(%rbp), %cx
movw %cx, (%rax)
movl -0x24(%rbp), %eax
movl %eax, -0xd4(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movzwl -0xb0(%rbp), %edi
callq 0x3c6e0
movl -0xd4(%rbp), %edi
movl %eax, %edx
movq -0xc0(%rbp), %rsi
callq 0xf1a0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3de1d
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3dea2
jmp 0x3de1f
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x3dd78
jmp 0x3de35
movl -0x24(%rbp), %eax
movl %eax, -0xdc(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movzwl (%rax), %edi
callq 0x3c6e0
movl -0xdc(%rbp), %edi
movl %eax, %edx
movq -0xc8(%rbp), %rsi
callq 0xf1a0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3de79
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3dea2
jmp 0x3de7b
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
leaq -0x24(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x44490
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nop