// File: /workspace/github_c_makefile_star2_O1/tomka[P]cliaspora/ssl.c
// Function: ssl_read
int
ssl_read(ssl_conn_t *cp, int waitsecs, void *buf, int size)
{
	int	       n, ec;
	fd_set         rset;
	struct timeval tv;
	
	if (SSL_pending(cp->handle) > 0) {
		while ((n = SSL_read(cp->handle, buf, size)) == -1) {
			if (errno != EINTR) {
				ERR_print_errors_fp(stderr);
				return (-1);
			}
		}
		return (n);
	}
	for (n = -1; n < 0;) {
		tv.tv_sec = waitsecs; tv.tv_usec = 0;
		FD_ZERO(&rset); FD_SET(cp->sock, &rset);
		while (select(cp->sock + 1, &rset, NULL, NULL, &tv) == -1) {
			if (errno != EINTR) {
				warn("ssl_read(): select()");
				return (-1);
			}
		}
		if (!FD_ISSET(cp->sock, &rset)) {
			warnx("ssl_read(): Timeout");
			return (TIMEOUT);
		} 
		if ((n = SSL_read(cp->handle, buf, size)) < 0) {
			switch ((ec = SSL_get_error(cp->handle, n))) {
			case SSL_ERROR_WANT_READ:
			case SSL_ERROR_WANT_WRITE:
				/* FALLTHROUGH */
				break;
			default:
				if (errno != 0) {
					warn("SSL_read() returned with %d," \
					     "SSL-error code %d", n, ec);
				} else {
					warnx("SSL_read() returned with %d," \
					      "SSL-error code %d", n, ec);
				}
				ERR_print_errors_fp(stderr);
				return (-1);
			}
		}
	}
	if (n == 0)
		cp->state = SSL_STATE_DISCONNECTED;
	return (n);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
callq 0x25d0
testl %eax, %eax
jle 0x7af3
movq 0x28(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2080
cmpl $-0x1, %eax
jne 0x7c06
callq 0x2060
cmpl $0x4, (%rax)
je 0x7abe
movq 0x74f2(%rip), %rax      # 0xefd8
movq (%rax), %rdi
callq 0x21b0
jmp 0x7bfe
movslq %r15d, %rax
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r15
leaq 0x10(%rsp), %r12
movq %rax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
movl 0xc(%rbx), %ecx
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x20(%rsp,%rax,8)
movl 0xc(%rbx), %edi
incl %edi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x2270
cmpl $-0x1, %eax
jne 0x7b8d
callq 0x2060
cmpl $0x4, (%rax)
je 0x7b68
jmp 0x7bf0
movl 0xc(%rbx), %eax
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq 0x20(%rsp,%rcx,8), %rcx
btq %rax, %rcx
jae 0x7c1e
movq 0x28(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2080
movl %eax, %r13d
testl %eax, %eax
jns 0x7bd4
movq 0x28(%rbx), %rdi
movl %r13d, %esi
callq 0x2040
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x7c31
testl %r13d, %r13d
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
js 0x7b08
jne 0x7c09
movl $0x0, 0x10(%rbx)
jmp 0x7c09
leaq 0x3a43(%rip), %rdi      # 0xb63a
xorl %eax, %eax
callq 0x2110
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x7c09
movl %eax, %r13d
movl %r13d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a2a(%rip), %rdi      # 0xb64f
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x22d0
jmp 0x7c09
movl %eax, %ebx
callq 0x2060
cmpl $0x0, (%rax)
je 0x7c55
leaq 0x3a1f(%rip), %rdi      # 0xb663
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
jmp 0x7adf
leaq 0x3a07(%rip), %rdi      # 0xb663
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x22d0
jmp 0x7adf