// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/liball/../libcperciva/network_ssl/network_ssl.c
// Function: network_ssl_open
struct network_ssl_ctx *
network_ssl_open(int s, const char * hostname)
{
	struct network_ssl_ctx * ssl;
#ifdef SO_NOSIGPIPE
	int val = 1;
#endif

	/* Make sure we've initialized properly. */
	if (init())
		goto err0;

	/* Allocate a state structure. */
	if ((ssl = malloc(sizeof(struct network_ssl_ctx))) == NULL)
		goto err0;
	ssl->s = s;
	ssl->waiting_r = ssl->waiting_w = 0;
	ssl->immediate_cookie = NULL;
	ssl->read_callback = NULL;
	ssl->read_cookie = NULL;
	ssl->read_buf = NULL;
	ssl->read_buflen = ssl->read_minlen = ssl->read_bufpos = 0;
	ssl->read_needs_r = ssl->read_needs_w = 0;
	ssl->write_callback = NULL;
	ssl->write_cookie = NULL;
	ssl->write_buf = NULL;
	ssl->write_buflen = ssl->write_minlen = ssl->write_bufpos = 0;
	ssl->write_needs_r = ssl->write_needs_w = 0;

	/* If we have SO_NOSIGPIPE, apply it to the socket. */
#ifdef SO_NOSIGPIPE
	if (setsockopt(ssl->s, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val))) {
		warnp("setsockopt(SO_NOSIGPIPE)");
		goto err1;
	}
#endif

	/* Create an SSL connection state within the SSL context. */
	if ((ssl->ssl = SSL_new(ctx)) == NULL) {
		warn0("SSL_new");
		goto err1;
	}

	/* Attach the provided socket to the SSL connection. */
	if (!SSL_set_fd(ssl->ssl, ssl->s)) {
		warn0("SSL_set_fd");
		goto err2;
	}

	/* Enable SNI; some servers need this to send us the right cert. */
	if (!SSL_set_tlsext_host_name(ssl->ssl, hostname)) {
		warn0("SSL_set_tlsext_host_name");
		goto err2;
	}

	/* Tell OpenSSL which host we're trying to talk to... */
	if (!SSL_set1_host(ssl->ssl, hostname)) {
		warn0("SSL_set1_host");
		goto err2;
	}

	/* ... and ask it to make sure that this is what is happening. */
	SSL_set_hostflags(ssl->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
	SSL_set_verify(ssl->ssl, SSL_VERIFY_PEER, NULL);

	/* Set ssl to work in client mode. */
	SSL_set_connect_state(ssl->ssl);

	/* Success! */
	return (ssl);

err2:
	SSL_free(ssl->ssl);
err1:
	free(ssl);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edi, %ebp
cmpq $0x0, 0x1b060(%rip)     # 0x288e0
je 0xd949
movl $0x90, %edi
callq 0x34c0
testq %rax, %rax
je 0xda5f
movq %rax, %rbx
movl %ebp, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x70(%rax)
movups %xmm0, 0x80(%rax)
movq 0x1b015(%rip), %rdi     # 0x288e0
callq 0x3380
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0xd9da
movq %rax, %r15
movq %rax, %rdi
movl %ebp, %esi
callq 0x31e0
testl %eax, %eax
je 0xd9fe
movq %r15, %rdi
movl $0x37, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0x3170
testq %rax, %rax
je 0xda10
movq %r15, %rdi
movq %r14, %rsi
callq 0x30b0
testl %eax, %eax
je 0xda36
movq %r15, %rdi
movl $0x4, %esi
callq 0x3460
movq %r15, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x3220
movq %r15, %rdi
callq 0x3150
jmp 0xda61
xorl %edi, %edi
xorl %esi, %esi
callq 0x32e0
testl %eax, %eax
je 0xd9f5
callq 0x31b0
testq %rax, %rax
je 0xda07
movq %rax, %rdi
callq 0x3520
movq %rax, 0x1af69(%rip)     # 0x288e0
testq %rax, %rax
je 0xda19
movl $0x303, %edx            # imm = 0x303
movq %rax, %rdi
movl $0x7b, %esi
xorl %ecx, %ecx
callq 0x32f0
testq %rax, %rax
je 0xda6f
movq 0x1af3c(%rip), %rdi     # 0x288e0
movl $0x1, %edx
movl $0x21, %esi
xorl %ecx, %ecx
callq 0x32f0
movq 0x1af24(%rip), %rdi     # 0x288e0
callq 0x33e0
testl %eax, %eax
je 0xda78
leaq 0x4c4(%rip), %rdi       # 0xde94
callq 0x10ab0
jmp 0xd886
leaq 0x579f(%rip), %rdi      # 0x13180
xorl %eax, %eax
callq 0x58ab
callq 0x3040
movl $0x0, (%rax)
jmp 0xda57
leaq 0x5972(%rip), %rdi      # 0x1336e
jmp 0xda20
leaq 0x5783(%rip), %rdi      # 0x13188
jmp 0xda3d
leaq 0x5981(%rip), %rdi      # 0x1338f
jmp 0xda20
leaq 0x577c(%rip), %rdi      # 0x13193
jmp 0xda3d
leaq 0x5981(%rip), %rdi      # 0x133a1
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x58ab
callq 0x3040
movl $0x0, (%rax)
jmp 0xda61
leaq 0x576f(%rip), %rdi      # 0x131ac
xorl %eax, %eax
callq 0x58ab
callq 0x3040
movl $0x0, (%rax)
movq %r15, %rdi
callq 0x31c0
movq %rbx, %rdi
callq 0x3450
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5948(%rip), %rdi      # 0x133be
jmp 0xda7f
leaq 0x5961(%rip), %rdi      # 0x133e0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x58ab
callq 0x3040
movl $0x0, (%rax)
movq 0x1ae46(%rip), %rdi     # 0x288e0
callq 0x3060
movq $0x0, 0x1ae36(%rip) # 0x288e0
jmp 0xda61