// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
callq 0x16f98
movq %rax, %r14
testb $0x2, (%rax)
jne 0x15502
leaq 0x1b2b5(%rip), %rdx     # 0x306ba
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x107e0
testq %rax, %rax
je 0x15452
movq %rax, %r15
movq (%rax), %rdi
testq %rdi, %rdi
je 0x154e7
movq 0x20(%r14), %rax
cmpq %rax, %rdi
je 0x154e7
testq %rax, %rax
je 0x15441
movq %rax, %rdi
callq 0xf7b0
movq (%r15), %rdi
movq %r14, %r12
addq $0x20, %r12
callq 0xf110
jmp 0x154e0
leaq 0x1b266(%rip), %rdx     # 0x306bf
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x107e0
movq %rax, %r15
testq %rax, %rax
jne 0x154b3
leaq 0x1b255(%rip), %rdx     # 0x306c8
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x107e0
testq %rax, %rax
je 0x154e7
movq %rax, %r15
movl 0x18(%rax), %eax
testl %eax, %eax
jne 0x154a3
leaq 0x1b240(%rip), %rdx     # 0x306d4
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0xf410
movl 0x18(%r15), %eax
cmpl $0x1, %eax
movl $0x1, 0x38(%r14)
sete 0x3c(%r14)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x154e7
movq 0x18(%r14), %rax
cmpq %rax, %rdi
je 0x154e7
testq %rax, %rax
je 0x154d4
movq %rax, %rdi
callq 0xf0f0
movq (%r15), %rdi
movq %r14, %r12
addq $0x18, %r12
callq 0xfbf0
movq (%r15), %rax
movq %rax, (%r12)
movl (%r14), %eax
movl %eax, %ecx
orl $0x2, %ecx
movl %ecx, (%r14)
testb $0x20, 0xa8(%r14)
je 0x15502
orl $0x3, %eax
movl %eax, (%r14)
movq %r14, %rdi
callq 0x17059
testl %eax, %eax
je 0x15528
movl %eax, %ebp
movq %rbx, %rdi
callq 0xf9d0
movslq %ebp, %rsi
movq %rbx, %rdi
callq 0xf960
pushq $0x2
popq %rbp
jmp 0x15535
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xfa10
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq