// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
callq 0x14050
cmpl $0x0, %eax
je 0x13dfe
jmp 0x1403e
movl $0x90, %edi
callq 0x34c0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x13e17
jmp 0x1403e
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x70(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x8c(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x88(%rax)
movq 0x229d2(%rip), %rdi     # 0x368e0
callq 0x33c0
movq -0x20(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x13f41
jmp 0x13f23
leaq 0xc4ee(%rip), %rdi      # 0x20418
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14035
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
callq 0x3220
cmpl $0x0, %eax
jne 0x13f79
jmp 0x13f5b
leaq 0xc4be(%rip), %rdi      # 0x20420
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14028
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rcx
movl $0x37, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3180
cmpq $0x0, %rax
jne 0x13fb6
jmp 0x13f9b
leaq 0xc489(%rip), %rdi      # 0x2042b
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14028
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x30c0
cmpl $0x0, %eax
jne 0x13fe9
jmp 0x13fce
leaq 0xc46f(%rip), %rdi      # 0x20444
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14028
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x4, %esi
callq 0x3470
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3260
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3160
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x14046
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3200
movq -0x20(%rbp), %rdi
callq 0x3460
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq