// File: /workspace/github_c_makefile_star2_O3/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, 0x1b1e0(%rip)     # 0x288e0
je 0xd7c9
movl $0x90, %edi
callq 0x34c0
testq %rax, %rax
je 0xd8df
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 0x1b195(%rip), %rdi     # 0x288e0
callq 0x3380
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0xd85a
movq %rax, %r15
movq %rax, %rdi
movl %ebp, %esi
callq 0x31e0
testl %eax, %eax
je 0xd87e
movq %r15, %rdi
movl $0x37, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0x3170
testq %rax, %rax
je 0xd890
movq %r15, %rdi
movq %r14, %rsi
callq 0x30b0
testl %eax, %eax
je 0xd8b6
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 0xd8e1
xorl %edi, %edi
xorl %esi, %esi
callq 0x32e0
testl %eax, %eax
je 0xd875
callq 0x31b0
testq %rax, %rax
je 0xd887
movq %rax, %rdi
callq 0x3520
movq %rax, 0x1b0e9(%rip)     # 0x288e0
testq %rax, %rax
je 0xd899
movl $0x303, %edx            # imm = 0x303
movq %rax, %rdi
movl $0x7b, %esi
xorl %ecx, %ecx
callq 0x32f0
testq %rax, %rax
je 0xd8ef
movq 0x1b0bc(%rip), %rdi     # 0x288e0
movl $0x1, %edx
movl $0x21, %esi
xorl %ecx, %ecx
callq 0x32f0
movq 0x1b0a4(%rip), %rdi     # 0x288e0
callq 0x33e0
testl %eax, %eax
je 0xd8f8
leaq 0x4d2(%rip), %rdi       # 0xdd22
callq 0x109a0
jmp 0xd706
leaq 0x5797(%rip), %rdi      # 0x12ff8
xorl %eax, %eax
callq 0x58d7
callq 0x3040
movl $0x0, (%rax)
jmp 0xd8d7
leaq 0x596a(%rip), %rdi      # 0x131e6
jmp 0xd8a0
leaq 0x577b(%rip), %rdi      # 0x13000
jmp 0xd8bd
leaq 0x5979(%rip), %rdi      # 0x13207
jmp 0xd8a0
leaq 0x5774(%rip), %rdi      # 0x1300b
jmp 0xd8bd
leaq 0x5979(%rip), %rdi      # 0x13219
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x58d7
callq 0x3040
movl $0x0, (%rax)
jmp 0xd8e1
leaq 0x5767(%rip), %rdi      # 0x13024
xorl %eax, %eax
callq 0x58d7
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 0x5940(%rip), %rdi      # 0x13236
jmp 0xd8ff
leaq 0x5959(%rip), %rdi      # 0x13258
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x58d7
callq 0x3040
movl $0x0, (%rax)
movq 0x1afc6(%rip), %rdi     # 0x288e0
callq 0x3060
movq $0x0, 0x1afb6(%rip) # 0x288e0
jmp 0xd8e1