// File: /workspace/github_c_makefile_star2_O2/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, 0x1c058(%rip)     # 0x288e0
je 0xc94b
movl $0x90, %edi
callq 0x34d0
testq %rax, %rax
je 0xca52
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 0x1c00d(%rip), %rdi     # 0x288e0
callq 0x3390
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0xc9d6
movq %rax, %r15
movq %rax, %rdi
movl %ebp, %esi
callq 0x31f0
testl %eax, %eax
je 0xc9f7
pushq $0x37
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x3170
testq %rax, %rax
je 0xca09
movq %r15, %rdi
movq %r14, %rsi
callq 0x30b0
testl %eax, %eax
je 0xca2c
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x3470
pushq $0x1
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x3230
movq %r15, %rdi
callq 0x3150
jmp 0xca54
xorl %edi, %edi
xorl %esi, %esi
callq 0x32f0
testl %eax, %eax
je 0xc9ee
callq 0x31c0
testq %rax, %rax
je 0xca00
movq %rax, %rdi
callq 0x3530
movq %rax, 0x1bf67(%rip)     # 0x288e0
testq %rax, %rax
je 0xca12
pushq $0x7b
popq %rsi
movl $0x303, %edx            # imm = 0x303
movq %rax, %rdi
xorl %ecx, %ecx
callq 0x3300
testq %rax, %rax
je 0xca62
movq 0x1bf3c(%rip), %rdi     # 0x288e0
pushq $0x21
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x3300
movq 0x1bf28(%rip), %rdi     # 0x288e0
callq 0x33f0
testl %eax, %eax
je 0xca6b
leaq 0x4ad(%rip), %rdi       # 0xce79
callq 0xf780
jmp 0xc88e
leaq 0x55a7(%rip), %rdi      # 0x11f84
xorl %eax, %eax
callq 0x553c
callq 0x3040
andl $0x0, (%rax)
jmp 0xca4a
leaq 0x577d(%rip), %rdi      # 0x12172
jmp 0xca19
leaq 0x558e(%rip), %rdi      # 0x11f8c
jmp 0xca33
leaq 0x578c(%rip), %rdi      # 0x12193
jmp 0xca19
leaq 0x5587(%rip), %rdi      # 0x11f97
jmp 0xca33
leaq 0x578c(%rip), %rdi      # 0x121a5
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x553c
callq 0x3040
andl $0x0, (%rax)
jmp 0xca54
leaq 0x557d(%rip), %rdi      # 0x11fb0
xorl %eax, %eax
callq 0x553c
callq 0x3040
andl $0x0, (%rax)
movq %r15, %rdi
callq 0x31d0
movq %rbx, %rdi
callq 0x3460
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5759(%rip), %rdi      # 0x121c2
jmp 0xca72
leaq 0x5772(%rip), %rdi      # 0x121e4
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x553c
callq 0x3040
andl $0x0, (%rax)
movq 0x1be56(%rip), %rdi     # 0x288e0
callq 0x3060
andq $0x0, 0x1be49(%rip)     # 0x288e0
jmp 0xca54