// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x25e0
cmpl $0x0, %eax
jle 0xa32b
jmp 0xa2dd
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x2080
movl %eax, -0x28(%rbp)
cmpl $-0x1, %eax
jne 0xa320
callq 0x2060
cmpl $0x4, (%rax)
je 0xa31e
movq 0x7cce(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa537
jmp 0xa2dd
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xa537
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x28(%rbp)
jge 0xa520
movslq -0x14(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq $0x0, -0xb8(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpq $0x10, %rax
jae 0xa39c
movq -0xd0(%rbp), %rax
movl -0xc4(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xa36a
jmp 0xa39e
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xb0(%rbp,%rax,8), %rcx
movq %rcx, -0xb0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edi
addl $0x1, %edi
leaq -0xb0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xc0(%rbp), %r8
movq %rcx, %rdx
callq 0x2290
cmpl $-0x1, %eax
jne 0xa42c
callq 0x2060
cmpl $0x4, (%rax)
je 0xa42a
leaq 0x52a7(%rip), %rdi      # 0xf6be
movb $0x0, %al
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa537
jmp 0xa3dd
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0xb0(%rbp,%rax,8), %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xd8(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0xa492
leaq 0x5254(%rip), %rdi      # 0xf6d3
movb $0x0, %al
callq 0x22f0
movl $0x0, -0x4(%rbp)
jmp 0xa537
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x2080
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
jge 0xa51b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0x28(%rbp), %esi
callq 0x2040
movl %eax, -0x2c(%rbp)
addl $-0x2, %eax
subl $0x1, %eax
ja 0xa4cd
jmp 0xa4cb
jmp 0xa519
callq 0x2060
cmpl $0x0, (%rax)
je 0xa4ed
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
leaq 0x5203(%rip), %rdi      # 0xf6e7
movb $0x0, %al
callq 0x2120
jmp 0xa501
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
leaq 0x51ed(%rip), %rdi      # 0xf6e7
movb $0x0, %al
callq 0x22f0
movq 0x7ad0(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x21c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa537
jmp 0xa51b
jmp 0xa332
cmpl $0x0, -0x28(%rbp)
jne 0xa531
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)