// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
xorl %esi, %esi
callq 0x24e27
orb $0x1, 0xb9(%rbx)
movq %rbx, %rdi
callq 0x23ff4
testl %eax, %eax
je 0x25428
movl %eax, (%r14)
cmpl $0xb, %eax
jne 0x254c1
xorl %r12d, %r12d
jmp 0x254f6
cmpl $-0x1, 0x58(%rbx)
je 0x254b9
andb $-0x5, 0xb0(%rbx)
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpq %rbp, %r13
cmovbq %r13, %rbp
cmpq $0x0, 0xc8(%rbx)
je 0x25512
movq %r14, 0x8(%rsp)
leaq 0xb0(%rbx), %r14
xorl %r12d, %r12d
testq %r13, %r13
je 0x25544
callq 0x10130
movq 0xc8(%rbx), %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x10980
testl %eax, %eax
jns 0x2553a
movq 0xc8(%rbx), %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0x24f03
cmpl $0x4, %eax
jne 0x2559d
cmpq $0x0, 0xc8(%rbx)
jne 0x25462
movl $0x4, %eax
movq 0x8(%rsp), %r14
jmp 0x25514
movl $0x6b, %eax
movl %eax, (%r14)
movl 0x58(%rbx), %ebp
movq 0xa8(%rbx), %r14
movl %eax, %edi
callq 0xfbe0
movq %rax, (%rsp)
leaq 0x10a70(%rip), %r9      # 0x35f4d
xorl %r12d, %r12d
movl $0x3, %edi
movl %ebp, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x25004
movq %rbx, %rdi
xorl %esi, %esi
callq 0x252cb
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
leaq 0x14(%rsp), %rcx
movl %eax, (%rcx)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x255b5
movq %rax, %r12
testq %rax, %rax
jne 0x25544
movl 0x14(%rsp), %eax
jmp 0x25414
movq 0x8(%rsp), %r14
je 0x255a7
movl %eax, %r12d
movl 0x58(%rbx), %esi
movq 0xa8(%rbx), %rdx
movq %r12, (%rsp)
leaq 0x113ec(%rip), %r9      # 0x36945
movl $0x3, %edi
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x25004
movb 0x48(%rbx), %al
movq 0x70(%rbx), %rcx
addq %r12, %rcx
movq $-0x1, %rdx
cmovaeq %rcx, %rdx
movq %rdx, 0x70(%rbx)
cmpb $0x1, %al
jne 0x254f6
leaq 0x80(%rbx), %rdi
callq 0xfc20
jmp 0x254f6
movq 0x8(%rsp), %r14
jmp 0x25414
movb $0x1, 0x78(%rbx)
movl $0x20, %eax
jmp 0x254be