// File: /workspace/github_c_makefile_star2_O1/wahern[P]cqueues/src/lib/socket.c
// Function: so_write
size_t so_write(struct socket *so, const void *src, size_t len, int *error_) {
	size_t count;
	int error;

	so_pipeign(so, 0);

	so->todo |= SO_S_SETWRITE;

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

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

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

			ERR_clear_error();

			if ((n = SSL_write(so->ssl.ctx, src, SO_MIN(len, 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.sent.eof = 1;
				goto error;
			}

			count = n;
		} else {
			count = 0;
		}
	} else {
		if (!(count = so_syswrite(so, src, len, &error)))
			goto error;
	}

	so_trace(SO_T_WRITE, so->fd, so->host, src, (size_t)count, "sent %zu bytes", (size_t)count);
	st_update(&so->st.sent, count, &so->opts);

	so_pipeok(so, 0);

	return count;
error:
	*error_ = error;

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

	so_pipeok(so, 0);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
xorl %esi, %esi
callq 0x24fd1
orb $0x1, 0xb9(%rbx)
movq %rbx, %rdi
callq 0x24162
movl %eax, 0x10(%rsp)
testl %eax, %eax
je 0x25612
movl 0x10(%rsp), %edi
movl %edi, (%r12)
cmpl $0xb, %edi
je 0x255f3
movl 0x58(%rbx), %ebp
movq 0xa8(%rbx), %r14
callq 0xfbe0
movq %rax, (%rsp)
leaq 0x10998(%rip), %r9      # 0x35f75
movl $0x3, %edi
movl %ebp, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x251a8
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2546f
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, 0x58(%rbx)
je 0x256d3
movq %r12, 0x18(%rsp)
andb $-0x5, 0xb0(%rbx)
leaq 0xb0(%rbx), %rax
movq %rax, 0x20(%rsp)
movl 0x10(%rsp), %r12d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpq %rbp, %r13
cmovbq %r13, %rbp
movl %r12d, 0x14(%rsp)
cmpq $0x0, 0xc8(%rbx)
je 0x256e0
testq %r13, %r13
je 0x25708
callq 0x10130
movq 0xc8(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x10980
testl %eax, %eax
js 0x25684
je 0x256a8
movl %eax, %r15d
xorl %eax, %eax
jmp 0x256b7
movq 0xc8(%rbx), %rdi
movl %eax, %esi
movq 0x20(%rsp), %rdx
callq 0x250a7
movl %eax, %r12d
xorl %eax, %eax
cmpl $0x4, %r12d
sete %al
orl $0x2, %eax
jmp 0x256b7
movb $0x1, 0x78(%rbx)
movl $0x2, %eax
movl $0x20, %r12d
cmpl $0x3, %eax
je 0x2564a
testl %eax, %eax
je 0x25710
cmpl $0x1, %eax
jne 0x2576d
movl %r12d, 0x10(%rsp)
jmp 0x25600
movl $0x6b, 0x10(%rsp)
jmp 0x255b6
leaq 0x10(%rsp), %rcx
movl %r12d, (%rcx)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2577c
movq %rax, %r15
testq %rax, %rax
movq 0x18(%rsp), %r12
jne 0x25715
jmp 0x255b6
xorl %r15d, %r15d
movl 0x14(%rsp), %r12d
movl %r12d, 0x10(%rsp)
movl 0x58(%rbx), %esi
movq 0xa8(%rbx), %rdx
movq %r15, (%rsp)
leaq 0x1124b(%rip), %r9      # 0x36975
movl $0x3, %edi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x251a8
movq 0x70(%rbx), %rax
addq %r15, %rax
movq $-0x1, %rcx
cmovaeq %rax, %rcx
movq %rcx, 0x70(%rbx)
cmpb $0x1, 0x48(%rbx)
jne 0x255f6
leaq 0x80(%rbx), %rdi
callq 0xfc20
jmp 0x255f6
movl %r12d, 0x10(%rsp)
movq 0x18(%rsp), %r12
jmp 0x255b6