// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./terminal.h
// Function: push_esc
bool push_esc(struct terminal_t *term, uint8_t ch)
{
	long offset;

	if ((term->esc.bp - term->esc.buf) >= term->esc.size) { /* buffer limit */
		logging(DEBUG, "escape sequence length >= %d, term.esc.buf reallocated\n", term->esc.size);
		offset = term->esc.bp - term->esc.buf;
		term->esc.buf = erealloc(term->esc.buf, term->esc.size * 2);
		term->esc.bp  = term->esc.buf + offset;
		term->esc.size *= 2;
	}

	/* ref: http://www.vt100.net/docs/vt102-ug/appendixd.html */
	*term->esc.bp++ = ch;
	if (term->esc.state == STATE_ESC) {
		/* format:
			ESC  I.......I F
				 ' '  '/'  '0'  '~'
			0x1B 0x20-0x2F 0x30-0x7E
		*/
		if ('0' <= ch && ch <= '~')        /* final char */
			return true;
		else if (SPACE <= ch && ch <= '/') /* intermediate char */
			return false;
	} else if (term->esc.state == STATE_CSI) {
		/* format:
			CSI       P.......P I.......I F
			ESC  '['  '0'  '?'  ' '  '/'  '@'  '~'
			0x1B 0x5B 0x30-0x3F 0x20-0x2F 0x40-0x7E
		*/
		if ('@' <= ch && ch <= '~')
			return true;
		else if (SPACE <= ch && ch <= '?')
			return false;
	} else {
		/* format:
			OSC       I.....I F
			ESC  ']'          BEL  or ESC  '\'
			0x1B 0x5D unknown 0x07 or 0x1B 0x5C
			DCS       I....I  F
			ESC  'P'          BEL  or ESC  '\'
			0x1B 0x50 unknown 0x07 or 0x1B 0x5C
		*/
		if (ch == BEL || (ch == BACKSLASH
			&& (term->esc.bp - term->esc.buf) >= 2 && *(term->esc.bp - 2) == ESC))
			return true;
		else if ((ch == ESC || ch == CR || ch == LF || ch == BS || ch == HT)
			|| (SPACE <= ch && ch <= '~'))
			return false;
	}

	/* invalid sequence */
	reset_esc(term);
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x68(%rcx), %rcx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x78(%rcx), %rcx
cmpq %rcx, %rax
jl 0x5214
movq -0x10(%rbp), %rax
movl 0x78(%rax), %edx
xorl %edi, %edi
leaq 0x50b26(%rip), %rsi     # 0x55cd8
movb $0x0, %al
callq 0x2450
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x68(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
shll %eax
movslq %eax, %rsi
callq 0x2830
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
addq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movl 0x78(%rax), %ecx
shll %ecx
movl %ecx, 0x78(%rax)
movb -0x11(%rbp), %cl
movq -0x10(%rbp), %rdx
movq 0x70(%rdx), %rax
movq %rax, %rsi
addq $0x1, %rsi
movq %rsi, 0x70(%rdx)
movb %cl, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x7c(%rax)
jne 0x527b
movzbl -0x11(%rbp), %ecx
movl $0x30, %eax
cmpl %ecx, %eax
jg 0x5255
movzbl -0x11(%rbp), %eax
cmpl $0x7e, %eax
jg 0x5255
movb $0x1, -0x1(%rbp)
jmp 0x5368
movzbl -0x11(%rbp), %ecx
movl $0x20, %eax
cmpl %ecx, %eax
jg 0x5274
movzbl -0x11(%rbp), %eax
cmpl $0x2f, %eax
jg 0x5274
movb $0x0, -0x1(%rbp)
jmp 0x5368
jmp 0x5276
jmp 0x535b
movq -0x10(%rbp), %rax
cmpl $0x2, 0x7c(%rax)
jne 0x52ca
movzbl -0x11(%rbp), %ecx
movl $0x40, %eax
cmpl %ecx, %eax
jg 0x52a4
movzbl -0x11(%rbp), %eax
cmpl $0x7e, %eax
jg 0x52a4
movb $0x1, -0x1(%rbp)
jmp 0x5368
movzbl -0x11(%rbp), %ecx
movl $0x20, %eax
cmpl %ecx, %eax
jg 0x52c3
movzbl -0x11(%rbp), %eax
cmpl $0x3f, %eax
jg 0x52c3
movb $0x0, -0x1(%rbp)
jmp 0x5368
jmp 0x52c5
jmp 0x5359
movzbl -0x11(%rbp), %eax
cmpl $0x7, %eax
je 0x5306
movzbl -0x11(%rbp), %eax
cmpl $0x5c, %eax
jne 0x530c
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x68(%rcx), %rcx
subq %rcx, %rax
cmpq $0x2, %rax
jl 0x530c
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movsbl -0x2(%rax), %eax
cmpl $0x1b, %eax
jne 0x530c
movb $0x1, -0x1(%rbp)
jmp 0x5368
movzbl -0x11(%rbp), %eax
cmpl $0x1b, %eax
je 0x534f
movzbl -0x11(%rbp), %eax
cmpl $0xd, %eax
je 0x534f
movzbl -0x11(%rbp), %eax
cmpl $0xa, %eax
je 0x534f
movzbl -0x11(%rbp), %eax
cmpl $0x8, %eax
je 0x534f
movzbl -0x11(%rbp), %eax
cmpl $0x9, %eax
je 0x534f
movzbl -0x11(%rbp), %ecx
movl $0x20, %eax
cmpl %ecx, %eax
jg 0x5355
movzbl -0x11(%rbp), %eax
cmpl $0x7e, %eax
jg 0x5355
movb $0x0, -0x1(%rbp)
jmp 0x5368
jmp 0x5357
jmp 0x5359
jmp 0x535b
movq -0x10(%rbp), %rdi
callq 0x5130
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)