// File: /workspace/github_c_makefile_star2_O1/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 0x82fb
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 0x1413c(%rip), %edi     # 0x1c354
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 0x8271
callq 0x66e0
movl (%rax), %edi
cmpl $0x4, %edi
je 0x81a4
jmp 0x830d
movl 0x140dd(%rip), %edi     # 0x1c354
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0x90(%rsp,%rax,8), %rax
btq %rdi, %rax
jae 0x82cb
cmpq %r12, %rbx
movq %r12, %rdx
cmovbq %rbx, %rdx
movq 0x8(%rsp), %rsi
callq 0x69f0
testq %rax, %rax
js 0x8323
movq %rax, %rbp
movq %rbx, %r13
subq %rax, %r13
jbe 0x82fb
cmpq %r12, %rbx
jae 0x82c3
callq 0x7e96
movq %rax, %r12
addq %rbp, 0x8(%rsp)
movq %r13, %rbx
movl 0x14083(%rip), %eax     # 0x1c354
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq 0x10(%rsp,%rcx,8), %rcx
btq %rax, %rcx
jae 0x82f2
callq 0x7e96
movq %rax, %r12
testq %rbx, %rbx
jne 0x81a4
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6570
leaq 0x84eb(%rip), %rdi      # 0x10804
movq %rax, %rsi
xorl %eax, %eax
callq 0x70c6
callq 0x66e0
movl (%rax), %edi
callq 0x6570
leaq 0x84e1(%rip), %rdi      # 0x10817
jmp 0x8319