// File: /workspace/github_c_makefile_star2_O2/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 $0x98, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
callq 0x25e0
testl %eax, %eax
jle 0x738c
movq 0x28(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2080
cmpl $-0x1, %eax
jne 0x7494
callq 0x2060
cmpl $0x4, (%rax)
je 0x7357
movq 0x7c59(%rip), %rax      # 0xefd8
movq (%rax), %rdi
callq 0x21b0
jmp 0x748e
movslq %r15d, %rax
movq %rax, (%rsp)
pushq $-0x1
popq %r13
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %r12
testl %r13d, %r13d
jns 0x74ac
movq (%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
xorl %eax, %eax
pushq $0x40
popq %r13
cmpq $0x10, %rax
je 0x73d0
andq $0x0, 0x18(%rsp,%rax,8)
incq %rax
jmp 0x73bf
movl 0xc(%rbx), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0x18(%rsp,%rdx,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 0x7411
callq 0x2060
cmpl $0x4, (%rax)
je 0x73ec
jmp 0x7480
movl 0xc(%rbx), %eax
cltd
idivl %r13d
cltq
movq 0x18(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0x74b7
movq 0x28(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2080
movl %eax, %r13d
testl %eax, %eax
jns 0x73a1
movq 0x28(%rbx), %rdi
movl %r13d, %esi
callq 0x2040
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
je 0x73a1
movl %eax, %ebx
callq 0x2060
cmpl $0x0, (%rax)
je 0x74ca
leaq 0x41d4(%rip), %rdi      # 0xb643
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
jmp 0x7378
leaq 0x4193(%rip), %rdi      # 0xb61a
xorl %eax, %eax
callq 0x2110
pushq $-0x1
popq %r13
jmp 0x7497
movl %eax, %r13d
movl %r13d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jne 0x7497
andl $0x0, 0x10(%rbx)
xorl %r13d, %r13d
jmp 0x7497
leaq 0x4171(%rip), %rdi      # 0xb62f
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x22e0
jmp 0x7497
leaq 0x4172(%rip), %rdi      # 0xb643
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x22e0
jmp 0x7378