// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/socket.c
// Function: lso_checkopts
static struct so_options lso_checkopts(lua_State *L, int index) {
	struct so_options opts = *so_opts();

	/* TODO: Support explicit interface name via .if_name/.name */
	if (lso_altfield(L, index, "bind", "sa_bind")) {
		static const int regindex;
		struct sockaddr *sa;
		const char *addr = NULL;
		size_t plen;
		const char *path = NULL;
		int port = -1, error;

		if (lua_istable(L, -1)) {
			if (lso_altfield(L, -1, "path", "sun_path") || lso_rawgeti(L, -1, 1)) {
				path = luaL_checklstring(L, -1, &plen);
				lua_pop(L, 1);
			} else {
				if (lso_altfield(L, -1, "addr", "address", "sin_addr", "sin6_addr") || lso_rawgeti(L, -1, 1)) {
					addr = luaL_checkstring(L, -1);
					lua_pop(L, 1);
				}

				if (lso_altfield(L, -1, "port", "sin_port", "sin6_port") || lso_rawgeti(L, -1, 2)) {
					port = luaL_checkint(L, -1);
					lua_pop(L, 1);
				}
			}
		} else {
			addr = luaL_checkstring(L, -1);
		}

		luaL_argcheck(L, path != NULL || addr != NULL, index, "no bind address specified");

		if (path) {
			sa = lso_singleton(L, CQS_UNIQUE_LIGHTUSERDATA_MASK(&regindex), NULL, sizeof(struct sockaddr_un));
			sa->sa_family = AF_UNIX;
			memcpy(((struct sockaddr_un*)sa)->sun_path, path, MIN(plen, sizeof(((struct sockaddr_un*)sa)->sun_path)));
		} else {
			sa = lso_singleton(L, CQS_UNIQUE_LIGHTUSERDATA_MASK(&regindex), NULL, sizeof(struct sockaddr_storage));
			if (!sa_pton(sa, sizeof(struct sockaddr_storage), addr, NULL, &error))
				luaL_argerror(L, index, lua_pushfstring(L, "%s: unable to parse bind address (%s)", addr, cqs_strerror(error)));

			if (port >= 0)
				*sa_port(sa, &(unsigned short){ 0 }, NULL) = htons((unsigned short)port);
		}

		opts.sa_bind = sa;

		lua_pop(L, 1);
	}

	if (lso_altfield(L, index, "mode", "sun_mode")) {
		opts.sun_mode = S_IFSOCK | lso_checkperm(L, -1);
		lua_pop(L, 1);
	}

	if (lso_altfield(L, index, "mask", "sun_mask")) {
		opts.sun_mask = S_IFSOCK | lso_checkperm(L, -1);
		lua_pop(L, 1);
	}

	if (lso_altfield(L, index, "unlink", "sun_unlink"))
		opts.sun_unlink = lso_popbool(L);

	if (lso_altfield(L, index, "reuseaddr", "sin_reuseaddr"))
		opts.sin_reuseaddr = lso_popbool(L);

	if (lso_altfield(L, index, "reuseport", "sin_reuseport"))
		opts.sin_reuseport = lso_popbool(L);

	if (lso_altfield(L, index, "broadcast", "sin_broadcast"))
		opts.sin_broadcast = lso_popbool(L);

	if (lso_altfield(L, index, "nodelay", "sin_nodelay"))
		opts.sin_nodelay = lso_popbool(L);

	if (lso_altfield(L, index, "nopush", "sin_nopush"))
		opts.sin_nopush = lso_popbool(L);

	if (lso_altfield(L, index, "v6only", "sin_v6only"))
		opts.sin_v6only = (lso_popbool(L))? SO_V6ONLY_ENABLE : SO_V6ONLY_DISABLE;

	if (lso_altfield(L, index, "oobinline", "sin_oobinline"))
		opts.sin_oobinline = lso_popbool(L);

	if (lso_altfield(L, index, "nonblock", "fd_nonblock"))
		opts.fd_nonblock = lso_popbool(L);

	if (lso_altfield(L, index, "cloexec", "fd_cloexec"))
		opts.fd_cloexec = lso_popbool(L);

	if (lso_altfield(L, index, "nosigpipe", "fd_nosigpipe"))
		opts.fd_nosigpipe = lso_popbool(L);

	if (lso_altfield(L, index, "verify", "tls_verify"))
		opts.tls_verify = lso_popbool(L);

	if (lso_altfield(L, index, "sendname", "tls_sendname")) {
		if (lua_isboolean(L, -1)) {
			opts.tls_sendname = (lua_toboolean(L, -1))? SO_OPTS_TLS_HOSTNAME : NULL;
		} else {
			opts.tls_sendname = luaL_checkstring(L, -1);
		}

		lua_pop(L, 1);
	}

	if (lso_altfield(L, index, "time", "st_time"))
		opts.st_time = lso_popbool(L);

	return opts;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, (%rdi)
movb $0x1, %al
movb %al, 0x11(%rdi)
movw $0x101, 0x1c(%rdi)      # imm = 0x101
movb %al, 0x1e(%rdi)
movq $0x1, 0x40(%rdi)
movb %al, 0x48(%rdi)
leaq 0x1ba0b(%rip), %rdx     # 0x3403c
leaq 0x18175(%rip), %rcx     # 0x307ad
movq %rsi, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x187f7
pushq $-0x1
popq %r15
movq %r14, %rdi
movl %r15d, %esi
callq 0xf270
cmpl $0x5, %eax
jne 0x186bf
leaq 0x1814f(%rip), %rdx     # 0x307b9
leaq 0x18144(%rip), %rcx     # 0x307b5
pushq $-0x1
popq %r15
movq %r14, %rdi
movl %r15d, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
jne 0x1869c
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x18cb7
testb %al, %al
je 0x18b25
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
movl %r15d, %esi
callq 0xf660
movq %rax, %r12
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
xorl %r13d, %r13d
jmp 0x186d2
xorl %r12d, %r12d
movq %r14, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0xf660
movq %rax, %r13
movq %r12, %rax
orq %r13, %rax
je 0x1871c
testq %r12, %r12
je 0x1872d
leaq 0x17e82(%rip), %rsi     # 0x30568
pushq $0x6e
popq %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x150e7
movq %rax, %r13
movw $0x1, (%rax)
leaq 0x2(%rax), %rdi
movq 0x18(%rsp), %rax
cmpq $0x6c, %rax
pushq $0x6c
popq %rdx
cmovbq %rax, %rdx
movq %r12, %rsi
callq 0xfad0
jmp 0x187e9
leaq 0x180c9(%rip), %rdx     # 0x307ec
movq %r14, %rdi
movl %ebp, %esi
callq 0xf410
leaq 0x17e34(%rip), %rsi     # 0x30568
movl $0x80, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x150e7
movq %r13, %r12
movq %rax, %r13
leaq 0x10(%rsp), %r8
movl $0x80, %esi
movq %rax, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x10310
testq %rax, %rax
jne 0x187be
movl 0x10(%rsp), %edi
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x40(%rsi)
movaps %xmm0, 0x50(%rsi)
movaps %xmm0, 0x60(%rsi)
movaps %xmm0, 0x70(%rsi)
movl $0x80, %edx
callq 0xf260
leaq 0x18065(%rip), %rsi     # 0x30806
movq %r14, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x10080
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xf410
testl %r15d, %r15d
js 0x187e9
rolw $0x8, %r15w
movzwl (%r13), %eax
cmpl $0xa, %eax
je 0x187d7
cmpl $0x2, %eax
jne 0x187e0
movq %r13, %rax
addq $0x2, %rax
jmp 0x187e5
leaq 0x16(%rsp), %rax
movw %r15w, (%rax)
movq %r13, (%rbx)
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
leaq 0x17ede(%rip), %rdx     # 0x306dc
leaq 0x18027(%rip), %rcx     # 0x3082c
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18833
movq %r14, %rdi
callq 0x18cf0
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0x8(%rbx)
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
leaq 0x17fff(%rip), %rdx     # 0x30839
leaq 0x17ff4(%rip), %rcx     # 0x30835
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x1886f
movq %r14, %rdi
callq 0x18cf0
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0xc(%rbx)
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
leaq 0x17fcc(%rip), %rdx     # 0x30842
leaq 0x17fc1(%rip), %rcx     # 0x3083e
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x1889b
movq %r14, %rdi
callq 0x18d81
movb %al, 0x10(%rbx)
leaq 0x17fab(%rip), %rdx     # 0x3084d
leaq 0x17fa0(%rip), %rcx     # 0x30849
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x188c7
movq %r14, %rdi
callq 0x18d81
movb %al, 0x11(%rbx)
leaq 0x17f8d(%rip), %rdx     # 0x3085b
leaq 0x17f82(%rip), %rcx     # 0x30857
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x188f3
movq %r14, %rdi
callq 0x18d81
movb %al, 0x12(%rbx)
leaq 0x17f6f(%rip), %rdx     # 0x30869
leaq 0x17f64(%rip), %rcx     # 0x30865
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x1891f
movq %r14, %rdi
callq 0x18d81
movb %al, 0x13(%rbx)
leaq 0x17f51(%rip), %rdx     # 0x30877
leaq 0x17f46(%rip), %rcx     # 0x30873
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x1894b
movq %r14, %rdi
callq 0x18d81
movb %al, 0x14(%rbx)
leaq 0x17f31(%rip), %rdx     # 0x30883
leaq 0x17f26(%rip), %rcx     # 0x3087f
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18977
movq %r14, %rdi
callq 0x18d81
movb %al, 0x15(%rbx)
leaq 0x17f10(%rip), %rdx     # 0x3088e
leaq 0x17f05(%rip), %rcx     # 0x3088a
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x189ab
movq %r14, %rdi
callq 0x18d81
movzbl %al, %eax
pushq $0x2
popq %rcx
subl %eax, %ecx
movl %ecx, 0x18(%rbx)
leaq 0x17ee7(%rip), %rdx     # 0x30899
leaq 0x17edc(%rip), %rcx     # 0x30895
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x189d7
movq %r14, %rdi
callq 0x18d81
movb %al, 0x16(%rbx)
leaq 0x17ec8(%rip), %rdx     # 0x308a6
leaq 0x17ebe(%rip), %rcx     # 0x308a3
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18a03
movq %r14, %rdi
callq 0x18d81
movb %al, 0x1c(%rbx)
leaq 0x17ea8(%rip), %rdx     # 0x308b2
leaq 0x17e9e(%rip), %rcx     # 0x308af
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18a2f
movq %r14, %rdi
callq 0x18d81
movb %al, 0x1d(%rbx)
leaq 0x17e87(%rip), %rdx     # 0x308bd
leaq 0x17e7d(%rip), %rcx     # 0x308ba
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18a5b
movq %r14, %rdi
callq 0x18d81
movb %al, 0x1e(%rbx)
leaq 0x17e69(%rip), %rdx     # 0x308cb
leaq 0x17e5e(%rip), %rcx     # 0x308c7
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18a87
movq %r14, %rdi
callq 0x18d81
movb %al, 0x38(%rbx)
leaq 0x17e48(%rip), %rdx     # 0x308d6
leaq 0x17e3d(%rip), %rcx     # 0x308d2
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18ae4
pushq $-0x1
popq %rsi
movq %r14, %rdi
callq 0xf270
pushq $-0x1
popq %rsi
movq %r14, %rdi
cmpl $0x1, %eax
jne 0x18ace
callq 0xf560
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setne %al
jmp 0x18ad5
xorl %edx, %edx
callq 0xf660
movq %rax, 0x40(%rbx)
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
leaq 0x17df7(%rip), %rdx     # 0x308e2
leaq 0x17ded(%rip), %rcx     # 0x308df
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
je 0x18b10
movq %r14, %rdi
callq 0x18d81
movb %al, 0x48(%rbx)
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $0x0, (%rsp)
leaq 0x17ca3(%rip), %rdx     # 0x307d4
leaq 0x17c86(%rip), %rcx     # 0x307be
leaq 0x17c87(%rip), %r8      # 0x307c6
leaq 0x17c89(%rip), %r9      # 0x307cf
pushq $-0x1
popq %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x18be3
testb %al, %al
jne 0x18b66
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x18cb7
testb %al, %al
je 0x18b83
pushq $-0x1
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0xf660
movq %rax, %r13
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
jmp 0x18b86
xorl %r13d, %r13d
leaq 0x17c5a(%rip), %rdx     # 0x307e7
leaq 0x17c45(%rip), %rcx     # 0x307d9
leaq 0x17c47(%rip), %r8      # 0x307e2
pushq $-0x1
popq %r15
movq %r14, %rdi
movl %r15d, %esi
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x18be3
testb %al, %al
jne 0x18bc2
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x18cb7
testb %al, %al
je 0x18bdb
pushq $-0x1
popq %rsi
movq %r14, %rdi
callq 0x10b40
movq %rax, %r15
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x106f0
xorl %r12d, %r12d
jmp 0x186d2