// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movl $0x1, %esi
callq 0x24fd1
orb $-0x80, 0xb8(%rbx)
movq %rbx, %rdi
callq 0x24162
movl %eax, 0x14(%rsp)
testl %eax, %eax
je 0x24e7d
movl 0x14(%rsp), %edi
movl %edi, (%r15)
cmpl $0xb, %edi
je 0x24e5b
movl 0x58(%rbx), %ebp
movq 0xa8(%rbx), %r14
callq 0xfbe0
movq %rax, (%rsp)
leaq 0x11130(%rip), %r9      # 0x35f75
movl $0x2, %edi
movl %ebp, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x251a8
movq %rbx, %rdi
movl $0x1, %esi
callq 0x2546f
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, 0x58(%rbx)
je 0x24f2c
leaq 0xb0(%rbx), %rax
movq %rax, 0x20(%rsp)
andb $-0x2, 0xb0(%rbx)
movl 0x14(%rsp), %ebp
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
cmpq %r13, %r12
movq %r12, 0x18(%rsp)
cmovbq %r12, %r13
cmpq $0x0, 0xc8(%rbx)
je 0x24f39
callq 0x10130
movq 0xc8(%rbx), %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0xf0d0
testl %eax, %eax
js 0x24ede
je 0x24f00
movl %eax, %r12d
xorl %eax, %eax
jmp 0x24f11
movq 0xc8(%rbx), %rdi
movl %eax, %esi
movq 0x20(%rsp), %rdx
callq 0x250a7
movl %eax, %ebp
xorl %eax, %eax
cmpl $0x4, %ebp
sete %al
orl $0x2, %eax
jmp 0x24f11
movb $0x1, 0x90(%rbx)
movl $0x2, %eax
movl $0x20, %ebp
cmpl $0x3, %eax
je 0x24eb0
testl %eax, %eax
je 0x24f5d
cmpl $0x1, %eax
jne 0x24fc8
movl %ebp, 0x14(%rsp)
jmp 0x24e6b
movl $0x6b, 0x14(%rsp)
jmp 0x24e1f
leaq 0x14(%rsp), %rcx
movl %ebp, (%rcx)
movq %rbx, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
callq 0x2512b
movq %rax, %r12
testq %rax, %rax
jne 0x24f61
jmp 0x24e1f
movl %ebp, 0x14(%rsp)
movl 0x58(%rbx), %esi
movq 0xa8(%rbx), %rdx
movq %r12, (%rsp)
leaq 0x119f0(%rip), %r9      # 0x36966
movl $0x2, %edi
movq %r14, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x251a8
movq 0x88(%rbx), %rax
addq %r12, %rax
movq $-0x1, %rcx
cmovaeq %rax, %rcx
movq %rcx, 0x88(%rbx)
cmpb $0x1, 0x48(%rbx)
jne 0x24fb6
leaq 0x98(%rbx), %rdi
callq 0xfc20
movq %rbx, %rdi
movl $0x1, %esi
callq 0x2546f
jmp 0x24e6b
movl %ebp, 0x14(%rsp)
jmp 0x24e1f