// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/socket.c
// Function: lso_connect2
static lso_nargs_t lso_connect2(lua_State *L) {
	const char *host NOTUSED = NULL, *port NOTUSED = NULL;
	const char *path = NULL;
	struct so_options opts;
	struct luasocket *S;
	size_t plen;
	int family, type, error;

	if (lua_istable(L, 1)) {
		opts = lso_checkopts(L, 1);

		lua_getfield(L, 1, "family");
		family = luaL_optinteger(L, -1, AF_UNSPEC);
		lua_pop(L, 1);

		lua_getfield(L, 1, "type");
		type = luaL_optinteger(L, -1, SOCK_STREAM);
		lua_pop(L, 1);

		if (lso_getfield(L, 1, "path")) {
			path = luaL_checklstring(L, -1, &plen);
			family = AF_UNIX;
		} else {
			lua_getfield(L, 1, "host");
			host = luaL_checkstring(L, -1);
			lua_getfield(L, 1, "port");
			port = luaL_checkstring(L, -1);
		}
	} else {
		opts = *so_opts();
		host = luaL_checkstring(L, 1);
		port = luaL_checkstring(L, 2);
		family = luaL_optinteger(L, 3, AF_UNSPEC);
		type = luaL_optinteger(L, 4, SOCK_STREAM);
	}

	S = lso_newsocket(L, type);

	opts.fd_close.arg = S;
	opts.fd_close.cb = &lso_closefd;

	if (path) {
		struct sockaddr_un sun;

		memset(&sun, 0, sizeof sun);
		sun.sun_family = AF_UNIX;
		memcpy(sun.sun_path, path, MIN(plen, sizeof sun.sun_path));

		if (!(S->socket = so_dial((struct sockaddr *)&sun, type, &opts, &error)))
			goto error;
	} else {
		if (!(S->socket = so_open(host, port, 0, family, type, &opts, &error)))
			goto error;
	}

	if ((error = lso_prepsocket(S)))
		goto error;

	(void)so_connect(S->socket);

	return 1;
error:
	lua_pushnil(L);
	lua_pushinteger(L, error);

	return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0xf280
cmpl $0x5, %eax
jne 0x203ba
movq -0x10(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
movl $0x1, %edx
callq 0x1f110
leaq -0x78(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movl $0x50, %edx
callq 0xfb40
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x2881d(%rip), %rdx     # 0x48ad5
callq 0xf200
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0xf450
movl %eax, -0x8c(%rbp)
movq -0x10(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x107f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x2d03b(%rip), %rdx     # 0x4d32e
callq 0xf200
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xf450
movl %eax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x107f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x2865e(%rip), %rdx     # 0x4898d
callq 0x1fd60
testb $0x1, %al
jne 0x2033a
jmp 0x2035f
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq -0x88(%rbp), %rdx
callq 0xf6a0
movq %rax, -0x28(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x203b5
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x2876d(%rip), %rdx     # 0x48adc
callq 0xf200
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0xf6a0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x28621(%rip), %rdx     # 0x489bb
callq 0xf200
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0xf6a0
movq %rax, -0x20(%rbp)
jmp 0x20478
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0xf7d0
movb $0x1, -0x127(%rbp)
movl $0x0, -0x120(%rbp)
movb $0x1, -0x11c(%rbp)
movb $0x1, -0x11b(%rbp)
movb $0x1, -0x11a(%rbp)
movl $0x1, %eax
movq %rax, -0xf8(%rbp)
movb $0x1, -0xf0(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x138(%rbp), %rsi
movl $0x50, %edx
callq 0xfb40
movq -0x10(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xf6a0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xf6a0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl $0x3, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xf450
movl %eax, -0x8c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0xf450
movl %eax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x18700
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x7c3a(%rip), %rax     # 0x18860
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x20556
leaq -0x1a6(%rbp), %rdi
xorl %esi, %esi
movl $0x6e, %edx
callq 0xf7d0
movw $0x1, -0x1a6(%rbp)
leaq -0x1a6(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x1b8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x6c, -0x88(%rbp)
jae 0x204fc
movq -0x88(%rbp), %rax
movq %rax, -0x1c0(%rbp)
jmp 0x2050a
movl $0x6c, %eax
movq %rax, -0x1c0(%rbp)
jmp 0x2050a
movq -0x1b0(%rbp), %rsi
movq -0x1b8(%rbp), %rdi
movq -0x1c0(%rbp), %rdx
callq 0xfb40
movl -0x90(%rbp), %esi
leaq -0x1a6(%rbp), %rdi
leaq -0x78(%rbp), %rdx
leaq -0x94(%rbp), %rcx
callq 0x104c0
movq -0x80(%rbp), %rcx
movq %rax, 0x128(%rcx)
cmpq $0x0, %rax
jne 0x20554
jmp 0x205c5
jmp 0x20596
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x8c(%rbp), %ecx
movl -0x90(%rbp), %r8d
xorl %edx, %edx
leaq -0x78(%rbp), %r9
leaq -0x94(%rbp), %rax
movq %rax, (%rsp)
callq 0xf230
movq -0x80(%rbp), %rcx
movq %rax, 0x128(%rcx)
cmpq $0x0, %rax
jne 0x20594
jmp 0x205c5
jmp 0x20596
movq -0x80(%rbp), %rdi
callq 0x18840
movl %eax, -0x94(%rbp)
cmpl $0x0, %eax
je 0x205ac
jmp 0x205c5
movq -0x80(%rbp), %rax
movq 0x128(%rax), %rdi
callq 0xf860
movl $0x1, -0x4(%rbp)
jmp 0x205e5
movq -0x10(%rbp), %rdi
callq 0xfa10
movq -0x10(%rbp), %rdi
movslq -0x94(%rbp), %rsi
callq 0xf9a0
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopw %cs:(%rax,%rax)