// File: /workspace/github_c_makefile_star2_O3/odknt[P]st/st.c
// Function: ttywriteraw
void
ttywriteraw(const char *s, size_t n)
{
	fd_set wfd, rfd;
	ssize_t r;
	size_t lim = 256;

	/*
	 * Remember that we are using a pty, which might be a modem line.
	 * Writing too much will clog the line. That's why we are doing this
	 * dance.
	 * FIXME: Migrate the world to Plan 9.
	 */
	while (n > 0) {
		FD_ZERO(&wfd);
		FD_ZERO(&rfd);
		FD_SET(cmdfd, &wfd);
		FD_SET(cmdfd, &rfd);

		/* Check if we can write. */
		if (pselect(cmdfd+1, &rfd, &wfd, NULL, NULL, NULL) < 0) {
			if (errno == EINTR)
				continue;
			die("select failed: %s\n", strerror(errno));
		}
		if (FD_ISSET(cmdfd, &wfd)) {
			/*
			 * Only write the bytes written by ttywrite() or the
			 * default of 256. This seems to be a reasonable value
			 * for a serial line. Bigger values might clog the I/O.
			 */
			if ((r = write(cmdfd, s, (n < lim)? n : lim)) < 0)
				goto write_error;
			if (r < n) {
				/*
				 * We weren't able to write out everything.
				 * This means the buffer is getting full
				 * again. Empty it.
				 */
				if (n < lim)
					lim = ttyread();
				n -= r;
				s += r;
			} else {
				/* All bytes have been written. */
				break;
			}
		}
		if (FD_ISSET(cmdfd, &rfd))
			lim = ttyread();
	}
	return;

write_error:
	die("write error on tty: %s\n", strerror(errno));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x8(%rsp)
testq %rsi, %rsi
je 0x84ec
movq %rsi, %rbx
movl $0x100, %r12d           # imm = 0x100
leaq 0x10(%rsp), %r14
leaq 0x90(%rsp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movl 0x14f5a(%rip), %edi     # 0x1d344
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x90(%rsp,%rax,8)
orq %rdx, 0x10(%rsp,%rax,8)
incl %edi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x6370
testl %eax, %eax
jns 0x8443
callq 0x66e0
movl (%rax), %edi
cmpl $0x4, %edi
je 0x8376
jmp 0x84fe
movl 0x14efb(%rip), %edi     # 0x1d344
leal 0x3f(%rdi), %edx
testl %edi, %edi
cmovnsl %edi, %edx
movl %edx, %eax
sarl $0x6, %eax
cltq
movq 0x90(%rsp,%rax,8), %rsi
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
btq %rcx, %rsi
jae 0x84d4
cmpq %r12, %rbx
movq %r12, %rdx
cmovbq %rbx, %rdx
movq 0x8(%rsp), %rsi
callq 0x69d0
testq %rax, %rax
js 0x8514
movq %rax, %rbp
movq %rbx, %r13
subq %rax, %r13
jbe 0x84ec
cmpq %r12, %rbx
jae 0x84aa
callq 0x7f71
movq %rax, %r12
addq %rbp, 0x8(%rsp)
movl 0x14e8f(%rip), %ecx     # 0x1d344
leal 0x3f(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movl %edx, %eax
sarl $0x6, %eax
cltq
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %r13, %rbx
testq %rdx, 0x10(%rsp,%rax,8)
je 0x84e3
callq 0x7f71
movq %rax, %r12
testq %rbx, %rbx
jne 0x8376
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6570
leaq 0x9328(%rip), %rdi      # 0x11832
movq %rax, %rsi
xorl %eax, %eax
callq 0x70a6
callq 0x66e0
movl (%rax), %edi
callq 0x6570
leaq 0x931e(%rip), %rdi      # 0x11845
jmp 0x850a