// File: /workspace/github_c_makefile_star2_O3/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 0x1f378(%rip), %rdx     # 0x3904c
leaq 0x1bad2(%rip), %rcx     # 0x357ad
movq %rsi, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19eb7
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xf260
cmpl $0x5, %eax
jne 0x19d6e
leaq 0x1baae(%rip), %rdx     # 0x357b9
leaq 0x1baa3(%rip), %rcx     # 0x357b5
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
jne 0x19d3d
movq %r14, %rdi
movl $0x1, %esi
callq 0x1a39d
testb %al, %al
je 0x1a1ee
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x8(%rsp)
leaq 0x18(%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 0x19d8d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x8(%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
je 0x19ddb
testq %r15, %r15
je 0x19dec
leaq 0x1b7c7(%rip), %rsi     # 0x35568
movl $0x6e, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x16351
movq %rax, %r13
movw $0x1, (%rax)
leaq 0x2(%rax), %rdi
movq 0x18(%rsp), %rax
cmpq $0x6c, %rax
movl $0x6c, %edx
cmovbq %rax, %rdx
movq %r15, %rsi
callq 0xfa60
jmp 0x19ea7
leaq 0x1ba0a(%rip), %rdx     # 0x357ec
movq %r14, %rdi
movl %ebp, %esi
callq 0xf3f0
leaq 0x1b775(%rip), %rsi     # 0x35568
movl $0x80, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x16351
movq %rax, %r13
leaq 0x10(%rsp), %r8
movl $0x80, %esi
movq %rax, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x10280
testq %rax, %rax
jne 0x19e7a
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 0xf250
leaq 0x1b9a9(%rip), %rsi     # 0x35806
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 0x8(%rsp), %rcx
testl %ecx, %ecx
js 0x19ea7
rolw $0x8, %cx
movzwl (%r13), %eax
cmpl $0xa, %eax
je 0x19e96
cmpl $0x2, %eax
jne 0x19e9f
movq %r13, %rax
addq $0x2, %rax
jmp 0x19ea4
leaq 0x16(%rsp), %rax
movw %cx, (%rax)
movq %r13, (%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b81e(%rip), %rdx     # 0x356dc
leaq 0x1b967(%rip), %rcx     # 0x3582c
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19ef5
movq %r14, %rdi
callq 0x1a3db
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b93d(%rip), %rdx     # 0x35839
leaq 0x1b932(%rip), %rcx     # 0x35835
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19f33
movq %r14, %rdi
callq 0x1a3db
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0xc(%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b908(%rip), %rdx     # 0x35842
leaq 0x1b8fd(%rip), %rcx     # 0x3583e
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19f5f
movq %r14, %rdi
callq 0x1a473
movb %al, 0x10(%rbx)
leaq 0x1b8e7(%rip), %rdx     # 0x3584d
leaq 0x1b8dc(%rip), %rcx     # 0x35849
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19f8b
movq %r14, %rdi
callq 0x1a473
movb %al, 0x11(%rbx)
leaq 0x1b8c9(%rip), %rdx     # 0x3585b
leaq 0x1b8be(%rip), %rcx     # 0x35857
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19fb7
movq %r14, %rdi
callq 0x1a473
movb %al, 0x12(%rbx)
leaq 0x1b8ab(%rip), %rdx     # 0x35869
leaq 0x1b8a0(%rip), %rcx     # 0x35865
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x19fe3
movq %r14, %rdi
callq 0x1a473
movb %al, 0x13(%rbx)
leaq 0x1b88d(%rip), %rdx     # 0x35877
leaq 0x1b882(%rip), %rcx     # 0x35873
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a00f
movq %r14, %rdi
callq 0x1a473
movb %al, 0x14(%rbx)
leaq 0x1b86d(%rip), %rdx     # 0x35883
leaq 0x1b862(%rip), %rcx     # 0x3587f
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a03b
movq %r14, %rdi
callq 0x1a473
movb %al, 0x15(%rbx)
leaq 0x1b84c(%rip), %rdx     # 0x3588e
leaq 0x1b841(%rip), %rcx     # 0x3588a
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a071
movq %r14, %rdi
callq 0x1a473
movzbl %al, %eax
movl $0x2, %ecx
subl %eax, %ecx
movl %ecx, 0x18(%rbx)
leaq 0x1b821(%rip), %rdx     # 0x35899
leaq 0x1b816(%rip), %rcx     # 0x35895
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a09d
movq %r14, %rdi
callq 0x1a473
movb %al, 0x16(%rbx)
leaq 0x1b802(%rip), %rdx     # 0x358a6
leaq 0x1b7f8(%rip), %rcx     # 0x358a3
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a0c9
movq %r14, %rdi
callq 0x1a473
movb %al, 0x1c(%rbx)
leaq 0x1b7e2(%rip), %rdx     # 0x358b2
leaq 0x1b7d8(%rip), %rcx     # 0x358af
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a0f5
movq %r14, %rdi
callq 0x1a473
movb %al, 0x1d(%rbx)
leaq 0x1b7c1(%rip), %rdx     # 0x358bd
leaq 0x1b7b7(%rip), %rcx     # 0x358ba
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a121
movq %r14, %rdi
callq 0x1a473
movb %al, 0x1e(%rbx)
leaq 0x1b7a3(%rip), %rdx     # 0x358cb
leaq 0x1b798(%rip), %rcx     # 0x358c7
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a14d
movq %r14, %rdi
callq 0x1a473
movb %al, 0x38(%rbx)
leaq 0x1b782(%rip), %rdx     # 0x358d6
leaq 0x1b777(%rip), %rcx     # 0x358d2
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a1b0
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xf260
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpl $0x1, %eax
jne 0x1a198
callq 0xf540
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setne %al
jmp 0x1a19f
xorl %edx, %edx
callq 0xf620
movq %rax, 0x40(%rbx)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
leaq 0x1b72b(%rip), %rdx     # 0x358e2
leaq 0x1b721(%rip), %rcx     # 0x358df
movq %r14, %rdi
movl %ebp, %esi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
je 0x1a1dc
movq %r14, %rdi
callq 0x1a473
movb %al, 0x48(%rbx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, (%rsp)
leaq 0x1b5d7(%rip), %rdx     # 0x357d4
leaq 0x1b5ba(%rip), %rcx     # 0x357be
leaq 0x1b5bb(%rip), %r8      # 0x357c6
leaq 0x1b5bd(%rip), %r9      # 0x357cf
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
jne 0x1a236
movq %r14, %rdi
movl $0x1, %esi
callq 0x1a39d
testb %al, %al
je 0x1a257
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 0x1a25a
xorl %r12d, %r12d
leaq 0x1b586(%rip), %rdx     # 0x357e7
leaq 0x1b571(%rip), %rcx     # 0x357d9
leaq 0x1b573(%rip), %r8      # 0x357e2
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x1a2c9
testb %al, %al
jne 0x1a296
movq %r14, %rdi
movl $0x2, %esi
callq 0x1a39d
testb %al, %al
je 0x1a2b7
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10a60
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x10640
jmp 0x1a2c1
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
jmp 0x19d8d