// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/network_ssl/network_ssl.c
// Function: doread
static int
doread(struct network_ssl_ctx * ssl)
{
	size_t len;
	int sslerr;
	int ret;
#ifndef SO_NOSIGPIPE
	void (* oldsig)(int);
#endif

	/*
	 * We need to zero errno in order to distinguish socket EOF from
	 * a socket error.
	 */
	errno = 0;

	/*
	 * Flush any errors internal to the SSL stack; otherwise if we
	 * encounter an error we won't be able to identify which error
	 * needs to be reported.
	 */
	ERR_clear_error();

	/* If we don't have SO_NOSIGPIPE, ignore SIGPIPE. */
#ifndef SO_NOSIGPIPE
	if ((oldsig = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) {
		warnp("signal(SIGPIPE)");
		return (-1);
	}
#endif

	/* Ask the SSL stack to read some data. */
	while ((ret = SSL_read_ex(ssl->ssl, &ssl->read_buf[ssl->read_bufpos],
	    ssl->read_buflen - ssl->read_bufpos, &len)) > 0) {
		/* Got some data. */
		ssl->read_bufpos += len;

		/* Sanity-check. */
		assert(ssl->read_bufpos <= ssl->read_buflen);

		/* Do we have enough? */
		if (ssl->read_bufpos >= ssl->read_minlen) {
			/* If we ignored SIGPIPE, restore the old handler. */
#ifndef SO_NOSIGPIPE
			if (signal(SIGPIPE, oldsig) == SIG_ERR) {
				warnp("signal(SIGPIPE)");
				return (-1);
			}
#endif

			return (docallback(ssl->read_callback,
			    ssl->read_cookie, (ssize_t)ssl->read_bufpos,
			    &ssl->read_callback));
		}
	}

	/* If we ignored SIGPIPE, restore the old handler. */
#ifndef SO_NOSIGPIPE
	if (signal(SIGPIPE, oldsig) == SIG_ERR) {
		warnp("signal(SIGPIPE)");
		return (-1);
	}
#endif

	/* SSL_read_ex couldn't give us any data... why? */
	switch ((sslerr = SSL_get_error(ssl->ssl, ret))) {
	case SSL_ERROR_WANT_READ:
		/* Nothing to do until the socket is readable. */
		ssl->read_needs_r = 1;
		return (0);
	case SSL_ERROR_WANT_WRITE:
		/* Nothing to do until the socket is writable. */
		ssl->read_needs_w = 1;
		return (0);
	case SSL_ERROR_SYSCALL:
		/* Either a socket EOF or a legitimate error. */
		if (errno != 0)
			break;

		/* FALLTHROUGH */
	case SSL_ERROR_ZERO_RETURN:
		/* Connection EOF. */
		return (docallback(ssl->read_callback,
		    ssl->read_cookie, 0, &ssl->read_callback));
	case SSL_ERROR_SSL:
		/* SSL failure, probably a protocol error. */
		warn0("SSL failure: %s",
		    ERR_error_string(ERR_get_error(), NULL));
		break;
	default:
		/* Don't know what happened here.  Fail the read. */
		warn0("Unknown SSL error: %d", sslerr);
		break;
	}

	/* Connection failure. */
	return (docallback(ssl->read_callback, ssl->read_cookie, -1,
	    &ssl->read_callback));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
callq 0x3040
movl $0x0, (%rax)
callq 0x34e0
movl $0xd, %edi
movl $0x1, %esi
callq 0x35d0
movq %rax, -0x28(%rbp)
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x1499e
jmp 0x1495d
callq 0x3040
cmpl $0x0, (%rax)
je 0x14982
leaq 0xbd51(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x14990
leaq 0xbd36(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x6930
jmp 0x14992
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14c34
jmp 0x149a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rax
addq 0x48(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x10(%rbp), %rax
subq 0x48(%rax), %rdx
leaq -0x18(%rbp), %rcx
callq 0x35a0
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jle 0x14ac5
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
ja 0x14a01
jmp 0x14a20
leaq 0xbcc7(%rip), %rdi      # 0x206cf
leaq 0xba4f(%rip), %rsi      # 0x2045e
movl $0x127, %edx            # imm = 0x127
leaq 0xbcd9(%rip), %rcx      # 0x206f4
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jb 0x14ac0
movq -0x28(%rbp), %rsi
movl $0xd, %edi
callq 0x35d0
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x14a93
jmp 0x14a52
callq 0x3040
cmpl $0x0, (%rax)
je 0x14a77
leaq 0xbc5c(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x14a85
leaq 0xbc41(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x6930
jmp 0x14a87
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14c34
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x20, %rcx
callq 0x14f40
movl %eax, -0x4(%rbp)
jmp 0x14c34
jmp 0x149a0
movq -0x28(%rbp), %rsi
movl $0xd, %edi
callq 0x35d0
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x14b22
jmp 0x14ae1
callq 0x3040
cmpl $0x0, (%rax)
je 0x14b06
leaq 0xbbcd(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x14b14
leaq 0xbbb2(%rip), %rdi      # 0x206bf
movb $0x0, %al
callq 0x6930
jmp 0x14b16
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14c34
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x20(%rbp), %esi
callq 0x3030
movl %eax, -0x1c(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x5, %eax
ja 0x14bed
movq -0x30(%rbp), %rax
leaq 0xb89b(%rip), %rcx      # 0x203ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl $0x1, 0x50(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x14c34
movq -0x10(%rbp), %rax
movl $0x1, 0x54(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x14c34
callq 0x3040
cmpl $0x0, (%rax)
je 0x14b94
jmp 0x14c0d
jmp 0x14b96
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rcx
addq $0x20, %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x14f40
movl %eax, -0x4(%rbp)
jmp 0x14c34
jmp 0x14bbe
callq 0x34b0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3110
movq %rax, %rsi
leaq 0xbb40(%rip), %rdi      # 0x20719
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14c0d
jmp 0x14bef
movl -0x1c(%rbp), %esi
leaq 0xbb30(%rip), %rdi      # 0x20729
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
jmp 0x14c0d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rcx
addq $0x20, %rcx
movq $-0x1, %rdx
callq 0x14f40
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)