// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x100, -0x120(%rbp) # imm = 0x100
cmpq $0x0, -0x10(%rbp)
jbe 0x87d7
jmp 0x850b
leaq -0x90(%rbp), %rax
movq %rax, -0x130(%rbp)
movl $0x0, -0x124(%rbp)
movl -0x124(%rbp), %eax
cmpq $0x10, %rax
jae 0x8555
movq -0x130(%rbp), %rax
movl -0x124(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x8523
jmp 0x8557
jmp 0x8559
leaq -0x110(%rbp), %rax
movq %rax, -0x140(%rbp)
movl $0x0, -0x134(%rbp)
movl -0x134(%rbp), %eax
cmpq $0x10, %rax
jae 0x85a3
movq -0x140(%rbp), %rax
movl -0x134(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x8571
jmp 0x85a5
movl 0x17b39(%rip), %eax     # 0x200e4
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl 0x17b1c(%rip), %eax     # 0x200e4
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x90(%rbp,%rax,8), %rcx
movq %rcx, -0x90(%rbp,%rax,8)
movl 0x17afc(%rip), %eax     # 0x200e4
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl 0x17adf(%rip), %eax     # 0x200e4
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x110(%rbp,%rax,8), %rcx
movq %rcx, -0x110(%rbp,%rax,8)
movl 0x17abf(%rip), %edi     # 0x200e4
addl $0x1, %edi
leaq -0x110(%rbp), %rsi
leaq -0x90(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rcx
movq %r9, %r8
callq 0x6370
cmpl $0x0, %eax
jge 0x8677
callq 0x66e0
cmpl $0x4, (%rax)
jne 0x865a
jmp 0x84fe
callq 0x66e0
movl (%rax), %edi
callq 0x6570
movq %rax, %rsi
leaq 0xc444(%rip), %rdi      # 0x14ab4
movb $0x0, %al
callq 0x6c20
movl 0x17a67(%rip), %eax     # 0x200e4
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x90(%rbp,%rax,8), %rax
movq %rax, -0x148(%rbp)
movl 0x17a48(%rip), %eax     # 0x200e4
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x148(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x877c
movl 0x17a19(%rip), %eax     # 0x200e4
movl %eax, -0x154(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x120(%rbp), %rax
jae 0x86f6
movq -0x10(%rbp), %rax
movq %rax, -0x160(%rbp)
jmp 0x8704
movq -0x120(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x150(%rbp), %rsi
movl -0x154(%rbp), %edi
movq -0x160(%rbp), %rdx
callq 0x69e0
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
jge 0x872f
jmp 0x87d9
movq -0x118(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x8778
movq -0x10(%rbp), %rax
cmpq -0x120(%rbp), %rax
jae 0x8755
callq 0x8130
movq %rax, -0x120(%rbp)
movq -0x118(%rbp), %rcx
movq -0x10(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x118(%rbp), %rax
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x877a
jmp 0x87d7
jmp 0x877c
movl 0x17962(%rip), %eax     # 0x200e4
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x110(%rbp,%rax,8), %rax
movq %rax, -0x168(%rbp)
movl 0x17943(%rip), %eax     # 0x200e4
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x168(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x87d2
callq 0x8130
movq %rax, -0x120(%rbp)
jmp 0x84fe
jmp 0x87f6
callq 0x66e0
movl (%rax), %edi
callq 0x6570
movq %rax, %rsi
leaq 0xc2d8(%rip), %rdi      # 0x14ac7
movb $0x0, %al
callq 0x6c20
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nop