// File: /workspace/github_c_makefile_star2_O0/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
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
xorl %esi, %esi
callq 0x2e860
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0xb8(%rax)
movq -0x10(%rbp), %rdi
callq 0x2dbb0
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x2f64f
jmp 0x2f7d5
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x58(%rax)
jne 0x2f665
movl $0x6b, -0x34(%rbp)
jmp 0x2f7d5
movq -0x10(%rbp), %rax
movswl 0xb0(%rax), %ecx
andl $-0x5, %ecx
movw %cx, 0xb0(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x2f753
cmpq $0x0, -0x20(%rbp)
jbe 0x2f749
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 0x2f6c7
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2f6d2
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x50(%rbp)
jmp 0x2f6d2
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
callq 0x10b80
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
jge 0x2f723
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 0x2f71e
jmp 0x2f67a
jmp 0x2f7d5
cmpl $0x0, -0x38(%rbp)
jne 0x2f73d
movl $0x20, -0x34(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x78(%rax)
jmp 0x2f7d5
jmp 0x2f73f
movslq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x2f751
movq $0x0, -0x30(%rbp)
jmp 0x2f776
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x34(%rbp), %rcx
callq 0x2f850
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x2f774
jmp 0x2f7d5
jmp 0x2f776
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 $0x3, %edi
leaq 0x1a559(%rip), %r9      # 0x49cf9
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2eb90
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x2f450
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2f4a0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2f83e
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpl $0xb, -0x34(%rbp)
je 0x2f82b
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 $0x3, %edi
xorl %ecx, %ecx
movl %ecx, %r8d
leaq 0x19904(%rip), %r9      # 0x49121
movq %r8, %rcx
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2eb90
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2f4a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)