// File: /workspace/github_c_makefile_star2_O3/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 0x79d5
movq 0x28(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2080
cmpl $-0x1, %eax
jne 0x7b04
callq 0x2060
cmpl $0x4, (%rax)
je 0x79a0
movq 0x7610(%rip), %rax      # 0xefd8
movq (%rax), %rdi
callq 0x21b0
jmp 0x7afc
movslq %r15d, %rcx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r15
leaq 0x10(%rsp), %r12
movq %rcx, 0x8(%rsp)
movq %rcx, 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 0x7a6f
callq 0x2060
cmpl $0x4, (%rax)
je 0x7a4a
jmp 0x7aee
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 0x7b1c
movq 0x28(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2080
movl %eax, %r13d
testl %eax, %eax
jns 0x7b2f
movq 0x28(%rbx), %rdi
movl %r13d, %esi
callq 0x2040
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
movq 0x8(%rsp), %rcx
xorps %xmm0, %xmm0
je 0x79ea
movl %eax, %ebx
callq 0x2060
cmpl $0x0, (%rax)
je 0x7b3d
leaq 0x3b66(%rip), %rdi      # 0xb643
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
jmp 0x79c1
leaq 0x3b25(%rip), %rdi      # 0xb61a
xorl %eax, %eax
callq 0x2110
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x7b07
movl %eax, %r13d
movl %r13d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3b0c(%rip), %rdi      # 0xb62f
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x22d0
jmp 0x7b07
jne 0x7b07
movl $0x0, 0x10(%rbx)
xorl %r13d, %r13d
jmp 0x7b07
leaq 0x3aff(%rip), %rdi      # 0xb643
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x22d0
jmp 0x79c1