// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %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 0x1f278(%rip), %rdx     # 0x3908c
leaq 0x1b9ba(%rip), %rcx     # 0x357d5
movq %rsi, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a06b
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xf260
cmpl $0x5, %eax
jne 0x19eae
leaq 0x1b996(%rip), %rdx     # 0x357e1
leaq 0x1b98b(%rip), %rcx     # 0x357dd
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
jne 0x19e7d
movq %r14, %rdi
movl $0x1, %esi
callq 0x1a4eb
testb %al, %al
je 0x19fe3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x18(%rsp)
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xf620
movq %rax, %r15
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
xorl %r12d, %r12d
jmp 0x19ecd
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0xf620
movq %rax, %r12
movq %r15, %rax
orq %r12, %rax
jne 0x19ee6
leaq 0x1b938(%rip), %rdx     # 0x35814
movq %r14, %rdi
movl %ebp, %esi
callq 0xf3f0
leaq 0x1b6a3(%rip), %rsi     # 0x35590
testq %r15, %r15
je 0x19f2c
movl $0x6e, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x162e0
movq %rax, %r13
movw $0x1, (%rax)
leaq 0x2(%rax), %rdi
movq 0x28(%rsp), %rax
cmpq $0x6c, %rax
movl $0x6c, %edx
cmovbq %rax, %rdx
movq %r15, %rsi
callq 0xfa60
jmp 0x1a05b
movl $0x80, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x162e0
movq %rax, %r13
leaq 0x24(%rsp), %r8
movl $0x80, %esi
movq %rax, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x10280
testq %rax, %rax
jne 0x19fb3
movl 0x24(%rsp), %edi
xorps %xmm0, %xmm0
leaq 0x30(%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 0xf250
leaq 0x1b898(%rip), %rsi     # 0x3582e
movq %r14, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xfff0
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xf3f0
movq 0x18(%rsp), %rcx
testl %ecx, %ecx
js 0x1a05b
rolw $0x8, %cx
movw $0x0, 0x16(%rsp)
movzwl (%r13), %eax
cmpl $0xa, %eax
je 0x19fda
cmpl $0x2, %eax
jne 0x1a053
movq %r13, %rax
addq $0x2, %rax
jmp 0x1a058
movq $0x0, (%rsp)
leaq 0x1b80a(%rip), %rdx     # 0x357fc
leaq 0x1b7ed(%rip), %rcx     # 0x357e6
leaq 0x1b7ee(%rip), %r8      # 0x357ee
leaq 0x1b7f0(%rip), %r9      # 0x357f7
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0x1a417
testb %al, %al
jne 0x1a02f
movq %r14, %rdi
movl $0x1, %esi
callq 0x1a4eb
testb %al, %al
je 0x1a3a5
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0xf620
movq %rax, %r12
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
jmp 0x1a3a8
leaq 0x16(%rsp), %rax
movw %cx, (%rax)
movq %r13, (%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b692(%rip), %rdx     # 0x35704
leaq 0x1b7db(%rip), %rcx     # 0x35854
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a0a9
movq %r14, %rdi
callq 0x1a529
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b7b1(%rip), %rdx     # 0x35861
leaq 0x1b7a6(%rip), %rcx     # 0x3585d
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a0e7
movq %r14, %rdi
callq 0x1a529
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0xc(%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b77c(%rip), %rdx     # 0x3586a
leaq 0x1b771(%rip), %rcx     # 0x35866
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a113
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x10(%rbx)
leaq 0x1b75b(%rip), %rdx     # 0x35875
leaq 0x1b750(%rip), %rcx     # 0x35871
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a13f
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x11(%rbx)
leaq 0x1b73d(%rip), %rdx     # 0x35883
leaq 0x1b732(%rip), %rcx     # 0x3587f
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a16b
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x12(%rbx)
leaq 0x1b71f(%rip), %rdx     # 0x35891
leaq 0x1b714(%rip), %rcx     # 0x3588d
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a197
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x13(%rbx)
leaq 0x1b701(%rip), %rdx     # 0x3589f
leaq 0x1b6f6(%rip), %rcx     # 0x3589b
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a1c3
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x14(%rbx)
leaq 0x1b6e1(%rip), %rdx     # 0x358ab
leaq 0x1b6d6(%rip), %rcx     # 0x358a7
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a1ef
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x15(%rbx)
leaq 0x1b6c0(%rip), %rdx     # 0x358b6
leaq 0x1b6b5(%rip), %rcx     # 0x358b2
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a225
movq %r14, %rdi
callq 0x1a5be
movzbl %al, %eax
movl $0x2, %ecx
subl %eax, %ecx
movl %ecx, 0x18(%rbx)
leaq 0x1b695(%rip), %rdx     # 0x358c1
leaq 0x1b68a(%rip), %rcx     # 0x358bd
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a251
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x16(%rbx)
leaq 0x1b676(%rip), %rdx     # 0x358ce
leaq 0x1b66c(%rip), %rcx     # 0x358cb
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a27d
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x1c(%rbx)
leaq 0x1b656(%rip), %rdx     # 0x358da
leaq 0x1b64c(%rip), %rcx     # 0x358d7
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a2a9
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x1d(%rbx)
leaq 0x1b635(%rip), %rdx     # 0x358e5
leaq 0x1b62b(%rip), %rcx     # 0x358e2
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a2d5
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x1e(%rbx)
leaq 0x1b617(%rip), %rdx     # 0x358f3
leaq 0x1b60c(%rip), %rcx     # 0x358ef
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a301
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x38(%rbx)
leaq 0x1b5f6(%rip), %rdx     # 0x358fe
leaq 0x1b5eb(%rip), %rcx     # 0x358fa
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a364
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xf260
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpl $0x1, %eax
jne 0x1a34c
callq 0xf540
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setne %al
jmp 0x1a353
xorl %edx, %edx
callq 0xf620
movq %rax, 0x40(%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b59f(%rip), %rdx     # 0x3590a
leaq 0x1b595(%rip), %rcx     # 0x35907
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
je 0x1a390
movq %r14, %rdi
callq 0x1a5be
movb %al, 0x48(%rbx)
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
leaq 0x1b460(%rip), %rdx     # 0x3580f
leaq 0x1b44b(%rip), %rcx     # 0x35801
leaq 0x1b44d(%rip), %r8      # 0x3580a
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x1a417
testb %al, %al
jne 0x1a3e4
movq %r14, %rdi
movl $0x2, %esi
callq 0x1a4eb
testb %al, %al
je 0x1a405
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10a60
movq %rax, 0x18(%rsp)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
jmp 0x1a40f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
jmp 0x19ecd