// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/lib/socket.c
// Function: so_open
struct socket *(so_open)(const char *host, const char *port, int qtype, int domain, int type, const struct so_options *opts, int *error_) {
	_Bool isnumeric = sa_isnumeric(host);
	struct dns_resolver *res = NULL;
	struct addrinfo hints;
	struct socket *so;
	int error;

	if (!(so = so_make(opts, &error)))
		goto error;

	/*
	 * Copy host name as TLS server host name.
	 *
	 * NOTE: All the TLS RFCs (from RFC 3546 to RFC 6066)
	 * declare
	 *
	 *      Literal IPv4 and IPv6 addresses are not permitted in
	 *      "HostName".
	 *
	 * If the caller wants to send the IP address as the TLS
	 * server host name, they can set .tls_hostname explicitly.
	 */
	if (so->opts.tls_sendname == SO_OPTS_TLS_HOSTNAME && !isnumeric) {
		if (!(so->opts.tls_sendname = strdup(host)))
			goto syerr;
	}

	memset(&hints, 0, sizeof hints);

	hints.ai_flags    = AI_CANONNAME;
	hints.ai_family   = domain;
	hints.ai_socktype = type;

	if (isnumeric) {
		hints.ai_flags |= AI_NUMERICHOST;
	} else {
		struct dns_options *opts = dns_opts();

		opts->closefd.arg = so->opts.fd_close.arg;
		opts->closefd.cb = so->opts.fd_close.cb;

		if (!(res = dns_res_stub(opts, &error)))
			goto error;
	}

	if (!(so->res = dns_ai_open(host, port, qtype, &hints, res, &error)))
		goto error;

	so->todo = SO_S_GETADDR | SO_S_SOCKET | SO_S_BIND;

	dns_res_close(res);

	return so;
syerr:
	error = so_syerr();
error:
	dns_res_close(res);

	so_close(so);

	*error_ = error;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %rbx
movl %r8d, %r13d
movl %ecx, %ebp
movl %edx, 0x4(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
xorl %r12d, %r12d
leaq 0x10(%rsp), %rdi
movl $0x80, %esi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x10280
movq %rax, %r14
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x23a60
movq %rax, %rbx
testq %rax, %rax
je 0x23a2b
testq %r14, %r14
jne 0x23985
cmpq $0x1, 0x40(%rbx)
jne 0x23985
movq %r15, %rdi
callq 0x10890
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x23a1e
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rsp)
movups %xmm0, 0x28(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x2, 0x10(%rsp)
movl %ebp, 0x14(%rsp)
movl %r13d, 0x18(%rsp)
jmp 0x239be
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rsp)
movups %xmm0, 0x28(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x2, 0x10(%rsp)
movl %ebp, 0x14(%rsp)
movl %r13d, 0x18(%rsp)
testq %r14, %r14
je 0x239be
movl $0x6, 0x10(%rsp)
xorl %r12d, %r12d
jmp 0x239e5
leaq 0x90(%rsp), %rdi
movq $0x0, 0x10(%rdi)
movups 0x28(%rbx), %xmm0
movaps %xmm0, (%rdi)
movq %rsp, %rsi
callq 0xf830
movq %rax, %r12
testq %rax, %rax
je 0x23a28
leaq 0x10(%rsp), %rcx
movq %rsp, %r9
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edx
movq %r12, %r8
callq 0xfd00
movq %rax, 0x50(%rbx)
testq %rax, %rax
je 0x23a2b
movl $0xe, 0xb8(%rbx)
movq %r12, %rdi
callq 0xfde0
jmp 0x23a4b
callq 0xf0a0
movl (%rax), %eax
movl %eax, (%rsp)
xorl %r12d, %r12d
movq 0xe0(%rsp), %r14
movq %r12, %rdi
callq 0xfde0
movq %rbx, %rdi
callq 0xf420
movl (%rsp), %eax
movl %eax, (%r14)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq