// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/socket.c
// Function: lso_starttls
static lso_nargs_t lso_starttls(lua_State *L) {
	struct luasocket *S = lso_checkself(L, 1);
	SSL_CTX **ctx = NULL;
	SSL **ssl = NULL;
	int error;

	/*
	 * NB: short-circuit if we've already started so we don't
	 * unnecessarily check for or take a reference to the SSL_CTX
	 * object.
	 */
	if ((S->todo & LSO_DO_STARTTLS))
		goto check;

	if ((ssl = luaL_testudata(L, 2, "SSL*"))) {
		/* accept-mode check handled by so_starttls() */
	} else if ((ctx = luaL_testudata(L, 2, "SSL_CTX*"))) {
		/* accept-mode check handled by so_starttls() */
	} else if ((ctx = luaL_testudata(L, 2, "SSL:Context"))) { /* luasec compatability */
		luaL_argcheck(L, ((lsec_context*)ctx)->mode != LSEC_MODE_INVALID, 2, "invalid mode");
		so_setbool(&S->tls.config.accept, ((((lsec_context*)ctx)->mode) == LSEC_MODE_SERVER));
	}

	if (ssl && *ssl && *ssl != S->tls.config.instance) {
		if (S->tls.config.instance)
			SSL_free(S->tls.config.instance);

		SSL_up_ref(*ssl);
		S->tls.config.instance = *ssl;
	}

	if (ctx && *ctx && *ctx != S->tls.config.context) {
		if (S->tls.config.context)
			SSL_CTX_free(S->tls.config.context);

		SSL_CTX_up_ref(*ctx);
		S->tls.config.context = *ctx;
	}

	S->todo |= LSO_DO_STARTTLS;

	if (S->obuf.mode & LSO_AUTOFLUSH)
		S->todo |= LSO_DO_FLUSH;
check:
	if ((error = lso_checktodo(S)))
		goto error;

	lua_pushvalue(L, 1);

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

	return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1bba0
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x196c1
jmp 0x19853
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x2f1bd(%rip), %rdx     # 0x4888e
callq 0x108e0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x196e5
jmp 0x1977f
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x2f19e(%rip), %rdx     # 0x48893
callq 0x108e0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x19706
jmp 0x1977d
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x2f186(%rip), %rdx     # 0x4889c
callq 0x108e0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x1977b
movq -0x20(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x18(%rcx)
movb %al, -0x2d(%rbp)
jne 0x19752
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x2f164(%rip), %rdx     # 0x488a8
callq 0xf440
cmpl $0x0, %eax
setne %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
addq $0x8, %rdi
addq $0x28, %rdi
movq -0x20(%rbp), %rax
cmpl $0x1, 0x18(%rax)
sete %al
movzbl %al, %esi
andl $0x1, %esi
callq 0x1bd40
jmp 0x1977d
jmp 0x1977f
cmpq $0x0, -0x28(%rbp)
je 0x197d4
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x197d4
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
je 0x197d4
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x197b9
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xf7f0
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0xf120
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x19829
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x19829
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
je 0x19829
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1980e
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xf100
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xfc60
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl 0xa8(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x19851
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x19853
movq -0x18(%rbp), %rdi
callq 0x1bd70
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x19866
jmp 0x1987d
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0xfa50
movl $0x1, -0x4(%rbp)
jmp 0x1989a
movq -0x10(%rbp), %rdi
callq 0xfa10
movq -0x10(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0xf9a0
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)