// File: /workspace/github_c_makefile_star2_O0/tomka[P]cliaspora/ssl.c
// Function: ssl_connect
ssl_conn_t *
ssl_connect(const char *host, u_short port)
{
	int	s;
	SSL	*handle;
	SSL_CTX *ctx;
	ssl_conn_t	   *cp;
	static int	   init = 1;
	struct sockaddr_in target;

	errno = 0;
	if (init == 1) {
		SSL_load_error_strings();
		(void)SSL_library_init();
		init = 0;
	}
        if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
		return (NULL);
	(void)memset(&target, 0, sizeof(target));
	target.sin_family = AF_INET;
	target.sin_port = htons(port);
	if ((target.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
		struct hostent *t_info;

		if ((t_info = gethostbyname(host)) == NULL) {
			herror("gethostbyname()");
			return (NULL);
		}
		(void)memcpy((char *)&target.sin_addr.s_addr, t_info->h_addr,
		    t_info->h_length);
	}
	if (connect(s, (struct sockaddr *)&target,
	    sizeof(struct sockaddr)) == -1)
		return (NULL);
	if ((ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) {
		ERR_print_errors_fp(stderr);
		return (NULL);
	}
	if ((handle = SSL_new(ctx)) == NULL) {
		ERR_print_errors_fp(stderr);
		return (NULL);
	}
	if (SSL_set_fd(handle, s) == 0) {
		ERR_print_errors_fp(stderr);
		(void)close(s); SSL_free(handle);
		return (NULL);
	}

	if (!SSL_set_tlsext_host_name(handle, host))
		ERR_print_errors_fp(stderr);

	if (SSL_connect(handle) != 1) {
		ERR_print_errors_fp(stderr);
		(void)close(s); SSL_free(handle);
		return (NULL);
	}
	if ((cp = malloc(sizeof(ssl_conn_t))) == NULL) {
		warn("malloc()"); (void)close(s); SSL_free(handle);
		return (NULL);
	}
	cp->ctx	   = ctx;
	cp->sock   = s;
	cp->handle = handle;
	cp->lnbuf  = NULL;
	cp->state  = SSL_STATE_CONNECTED;
	cp->slen   = cp->bufsz = cp->rd = 0;
	cp->host   = strdup(host);
	if (cp->host == NULL) {
		warn("strdup()"); ssl_disconnect(cp);
		return (NULL);
	}
	return (cp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movw %si, %ax
movq %rdi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
callq 0x2060
movl $0x0, (%rax)
cmpl $0x1, 0x8453(%rip)      # 0x12388
jne 0x9f5b
movl $0x200002, %edi         # imm = 0x200002
xorl %eax, %eax
movl %eax, %esi
callq 0x2250
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x2250
movl $0x0, 0x842d(%rip)      # 0x12388
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2100
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
jne 0x9f81
movq $0x0, -0x8(%rbp)
jmp 0xa213
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x21d0
movw $0x2, -0x40(%rbp)
movzwl -0x12(%rbp), %edi
callq 0x2090
movw %ax, -0x3e(%rbp)
movq -0x10(%rbp), %rdi
callq 0x22b0
movl %eax, -0x3c(%rbp)
cmpl $-0x1, %eax
jne 0xa001
movq -0x10(%rbp), %rdi
callq 0x2370
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x9fe1
leaq 0x56df(%rip), %rdi      # 0xf6ae
callq 0x23e0
movq $0x0, -0x8(%rbp)
jmp 0xa213
leaq -0x40(%rbp), %rdi
addq $0x4, %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0x48(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x2220
movl -0x18(%rbp), %edi
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
movl $0x10, %edx
callq 0x2230
cmpl $-0x1, %eax
jne 0xa02c
movq $0x0, -0x8(%rbp)
jmp 0xa213
callq 0x21a0
movq %rax, %rdi
callq 0x2490
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xa05f
movq 0x7f8e(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movq $0x0, -0x8(%rbp)
jmp 0xa213
movq -0x28(%rbp), %rdi
callq 0x22c0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0xa08e
movq 0x7f5f(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movq $0x0, -0x8(%rbp)
jmp 0xa213
movq -0x20(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x21f0
cmpl $0x0, %eax
jne 0xa0cc
movq 0x7f32(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movl -0x18(%rbp), %edi
callq 0x25d0
movq -0x20(%rbp), %rdi
callq 0x21e0
movq $0x0, -0x8(%rbp)
jmp 0xa213
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x37, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2140
cmpq $0x0, %rax
jne 0xa0f7
movq 0x7ee9(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movq -0x20(%rbp), %rdi
callq 0x2480
cmpl $0x1, %eax
je 0xa132
movq 0x7ecc(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movl -0x18(%rbp), %edi
callq 0x25d0
movq -0x20(%rbp), %rdi
callq 0x21e0
movq $0x0, -0x8(%rbp)
jmp 0xa213
movl $0x38, %edi
callq 0x2430
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xa172
leaq 0x4a91(%rip), %rdi      # 0xebde
movb $0x0, %al
callq 0x2120
movl -0x18(%rbp), %edi
callq 0x25d0
movq -0x20(%rbp), %rdi
callq 0x21e0
movq $0x0, -0x8(%rbp)
jmp 0xa213
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rdi
callq 0x2580
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xa20b
leaq 0x49f6(%rip), %rdi      # 0xebe7
movb $0x0, %al
callq 0x2120
movq -0x30(%rbp), %rdi
callq 0xa220
movq $0x0, -0x8(%rbp)
jmp 0xa213
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)