// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/lib/socket.c
// Function: so_read
size_t so_read(struct socket *so, void *dst, size_t lim, int *error_) {
	size_t len;
	int error;

	so_pipeign(so, 1);

	so->todo |= SO_S_SETREAD;

	if ((error = so_exec(so)))
		goto error;

	if (so->fd == -1) {
		error = ENOTCONN;
		goto error;
	}

	so->events &= ~POLLIN;
retry:
	if (so->ssl.ctx) {
		int n;

		ERR_clear_error();

		if ((n = SSL_read(so->ssl.ctx, dst, SO_MIN(lim, INT_MAX))) < 0) {
			if (SO_EINTR == (error = ssl_error(so->ssl.ctx, n, &so->events)))
				goto retry;
			goto error;
		} else if (n == 0) {
			error = EPIPE; /* FIXME: differentiate clean from unclean shutdown? */
			so->st.rcvd.eof = 1;
			goto error;
		}

		len = n;
	} else {
		if (!(len = so_sysread(so, dst, lim, &error)))
			goto error;
	}

	so_trace(SO_T_READ, so->fd, so->host, dst, (size_t)len, "rcvd %zu bytes", (size_t)len);
	st_update(&so->st.rcvd, len, &so->opts);

	so_pipeok(so, 1);

	return len;
error:
	*error_ = error;

	if (error != SO_EAGAIN)
		so_trace(SO_T_READ, so->fd, so->host, (void *)0, (size_t)0, "%s", so_strerror(error));

	so_pipeok(so, 1);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2e860
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0xb8(%rax)
movq -0x10(%rbp), %rdi
callq 0x2dbb0
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x2e662
jmp 0x2e7dd
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x58(%rax)
jne 0x2e678
movl $0x6b, -0x34(%rbp)
jmp 0x2e7dd
movq -0x10(%rbp), %rax
movswl 0xb0(%rax), %ecx
andl $-0x2, %ecx
movw %cx, 0xb0(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x2e754
callq 0x10280
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x7fffffff, -0x20(%rbp) # imm = 0x7FFFFFFF
jae 0x2e6cf
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2e6da
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x50(%rbp)
jmp 0x2e6da
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
callq 0xf0d0
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
jge 0x2e72b
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rdi
movl -0x38(%rbp), %esi
movq -0x10(%rbp), %rdx
addq $0xb0, %rdx
callq 0x2e970
movl %eax, %ecx
movl %ecx, -0x34(%rbp)
movl $0x4, %eax
cmpl %ecx, %eax
jne 0x2e726
jmp 0x2e68d
jmp 0x2e7dd
cmpl $0x0, -0x38(%rbp)
jne 0x2e748
movl $0x20, -0x34(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x90(%rax)
jmp 0x2e7dd
jmp 0x2e74a
movslq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x2e777
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x34(%rbp), %rcx
callq 0x2ea90
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x2e775
jmp 0x2e7dd
jmp 0x2e777
movq -0x10(%rbp), %rax
movl 0x58(%rax), %esi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rdx
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x30(%rbp), %rax
movl $0x2, %edi
leaq 0x1b549(%rip), %r9      # 0x49cea
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2eb90
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
addq $0x18, %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x2f450
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2f4a0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2e849
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpl $0xb, -0x34(%rbp)
je 0x2e833
movq -0x10(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x34(%rbp), %edi
callq 0xfcd0
movl -0x5c(%rbp), %esi
movq -0x58(%rbp), %rdx
movl $0x2, %edi
xorl %ecx, %ecx
movl %ecx, %r8d
leaq 0x1a8fc(%rip), %r9      # 0x49121
movq %r8, %rcx
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2eb90
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2f4a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)