// File: /workspace/github_c_makefile_star2_O0/garbeam[P]st/st.c
// Function: tputc
void
tputc(Rune u)
{
	char c[UTF_SIZ];
	int control;
	int width, len;
	Glyph *gp;

	control = ISCONTROL(u);
	if (!IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
		c[0] = u;
		width = len = 1;
	} else {
		len = utf8encode(u, c);
		if (!control && (width = wcwidth(u)) == -1) {
			memcpy(c, "\357\277\275", 4); /* UTF_INVALID */
			width = 1;
		}
	}

	if (IS_SET(MODE_PRINT))
		tprinter(c, len);

	/*
	 * STR sequence must be checked before anything else
	 * because it uses all following characters until it
	 * receives a ESC, a SUB, a ST or any other C1 control
	 * character.
	 */
	if (term.esc & ESC_STR) {
		if (u == '\a' || u == 030 || u == 032 || u == 033 ||
		   ISCONTROLC1(u)) {
			term.esc &= ~(ESC_START|ESC_STR|ESC_DCS);
			if (IS_SET(MODE_SIXEL)) {
				/* TODO: render sixel */;
				term.mode &= ~MODE_SIXEL;
				return;
			}
			term.esc |= ESC_STR_END;
			goto check_control_code;
		}

		if (IS_SET(MODE_SIXEL)) {
			/* TODO: implement sixel mode */
			return;
		}
		if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
			term.mode |= MODE_SIXEL;

		if (strescseq.len+len >= sizeof(strescseq.buf)-1) {
			/*
			 * Here is a bug in terminals. If the user never sends
			 * some code to stop the str or esc command, then st
			 * will stop responding. But this is better than
			 * silently failing with unknown characters. At least
			 * then users will report back.
			 *
			 * In the case users ever get fixed, here is the code:
			 */
			/*
			 * term.esc = 0;
			 * strhandle();
			 */
			return;
		}

		memmove(&strescseq.buf[strescseq.len], c, len);
		strescseq.len += len;
		return;
	}

check_control_code:
	/*
	 * Actions of control codes must be performed as soon they arrive
	 * because they can be embedded inside a control sequence, and
	 * they must not cause conflicts with sequences.
	 */
	if (control) {
		tcontrolcode(u);
		/*
		 * control codes are not shown ever
		 */
		return;
	} else if (term.esc & ESC_START) {
		if (term.esc & ESC_CSI) {
			csiescseq.buf[csiescseq.len++] = u;
			if (BETWEEN(u, 0x40, 0x7E)
					|| csiescseq.len >= \
					sizeof(csiescseq.buf)-1) {
				term.esc = 0;
				csiparse();
				csihandle();
			}
			return;
		} else if (term.esc & ESC_UTF8) {
			tdefutf8(u);
		} else if (term.esc & ESC_ALTCHARSET) {
			tdeftran(u);
		} else if (term.esc & ESC_TEST) {
			tdectest(u);
		} else {
			if (!eschandle(u))
				return;
			/* sequence already finished */
		}
		term.esc = 0;
		/*
		 * All characters which form part of a sequence are not
		 * printed
		 */
		return;
	}
	if (sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
		selclear();

	gp = &term.line[term.c.y][term.c.x];
	if (IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
		gp->mode |= ATTR_WRAP;
		tnewline(1);
		gp = &term.line[term.c.y][term.c.x];
	}

	if (IS_SET(MODE_INSERT) && term.c.x+width < term.col)
		memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph));

	if (term.c.x+width > term.col) {
		tnewline(1);
		gp = &term.line[term.c.y][term.c.x];
	}

	tsetchar(u, &term.c.attr, term.c.x, term.c.y);

	if (width == 2) {
		gp->mode |= ATTR_WIDE;
		if (term.c.x+1 < term.col) {
			gp[1].u = '\0';
			gp[1].mode = ATTR_WDUMMY;
		}
	}
	if (term.c.x+width < term.col) {
		tmoveto(term.c.x+width, term.c.y);
	} else {
		term.c.state |= CURSOR_WRAPNEXT;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
xorl %eax, %eax
cmpl -0x4(%rbp), %eax
ja 0x899d
movb $0x1, %al
cmpl $0x1f, -0x4(%rbp)
movb %al, -0x21(%rbp)
jbe 0x89ca
movb $0x1, %al
cmpl $0x7f, -0x4(%rbp)
movb %al, -0x21(%rbp)
je 0x89ca
xorl %eax, %eax
movl $0x80, %ecx
cmpl -0x4(%rbp), %ecx
movb %al, -0x22(%rbp)
ja 0x89c4
cmpl $0x9f, -0x4(%rbp)
setbe %al
movb %al, -0x22(%rbp)
movb -0x22(%rbp), %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xc(%rbp)
movl 0x103b1(%rip), %eax     # 0x18d8c
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x8a09
movl 0x103a3(%rip), %eax     # 0x18d8c
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x8a09
movl -0x4(%rbp), %eax
movb %al, -0x8(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0x8a40
movl -0x4(%rbp), %edi
leaq -0x8(%rbp), %rsi
callq 0x5bb0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x8a3e
movl -0x4(%rbp), %edi
callq 0x5630
movl %eax, -0x10(%rbp)
cmpl $-0x1, %eax
jne 0x8a3e
movl 0x901d(%rip), %eax      # 0x11a51
movl %eax, -0x8(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0x8a40
movl 0x10346(%rip), %eax     # 0x18d8c
andl $0x20, %eax
cmpl $0x0, %eax
je 0x8a5b
leaq -0x8(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0x86a0
movl 0x1032f(%rip), %eax     # 0x18d90
andl $0x4, %eax
cmpl $0x0, %eax
je 0x8b76
cmpl $0x7, -0x4(%rbp)
je 0x8a98
cmpl $0x18, -0x4(%rbp)
je 0x8a98
cmpl $0x1a, -0x4(%rbp)
je 0x8a98
cmpl $0x1b, -0x4(%rbp)
je 0x8a98
movl $0x80, %eax
cmpl -0x4(%rbp), %eax
ja 0x8ae3
cmpl $0x9f, -0x4(%rbp)
ja 0x8ae3
movl 0x102f2(%rip), %eax     # 0x18d90
andl $0xffffff7a, %eax       # imm = 0xFFFFFF7A
movl %eax, 0x102e7(%rip)     # 0x18d90
movl 0x102dd(%rip), %eax     # 0x18d8c
andl $0x80, %eax
cmpl $0x0, %eax
je 0x8acf
movl 0x102cd(%rip), %eax     # 0x18d8c
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
movl %eax, 0x102c2(%rip)     # 0x18d8c
jmp 0x8e55
movl 0x102bb(%rip), %eax     # 0x18d90
orl $0x10, %eax
movl %eax, 0x102b2(%rip)     # 0x18d90
jmp 0x8b78
movl 0x102a3(%rip), %eax     # 0x18d8c
andl $0x80, %eax
cmpl $0x0, %eax
je 0x8af8
jmp 0x8e55
movl 0x10292(%rip), %eax     # 0x18d90
andl $0x80, %eax
cmpl $0x0, %eax
je 0x8b28
cmpl $0x0, 0x124ad(%rip)     # 0x1afbc
jne 0x8b28
cmpl $0x71, -0x4(%rbp)
jne 0x8b28
movl 0x1026f(%rip), %eax     # 0x18d8c
orl $0x80, %eax
movl %eax, 0x10264(%rip)     # 0x18d8c
movl 0x1248e(%rip), %eax     # 0x1afbc
addl -0x14(%rbp), %eax
cltq
cmpq $0x1ff, %rax            # imm = 0x1FF
jb 0x8b40
jmp 0x8e55
movslq 0x12475(%rip), %rax     # 0x1afbc
leaq 0x1226a(%rip), %rdi     # 0x1adb8
addq $0x1, %rdi
addq %rax, %rdi
leaq -0x8(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x54d0
movl -0x14(%rbp), %eax
addl 0x12451(%rip), %eax     # 0x1afbc
movl %eax, 0x1244b(%rip)     # 0x1afbc
jmp 0x8e55
jmp 0x8b78
cmpl $0x0, -0xc(%rbp)
je 0x8b8e
movl -0x4(%rbp), %eax
movzbl %al, %edi
callq 0x8ef0
jmp 0x8e55
movl 0x101fc(%rip), %eax     # 0x18d90
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8c86
movl 0x101ea(%rip), %eax     # 0x18d90
andl $0x2, %eax
cmpl $0x0, %eax
je 0x8c09
movl -0x4(%rbp), %eax
movb %al, %dl
movl 0x1268f(%rip), %eax     # 0x1b248
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x12684(%rip)     # 0x1b248
movslq %eax, %rcx
leaq 0x1247a(%rip), %rax     # 0x1b048
movb %dl, (%rax,%rcx)
movl $0x40, %eax
cmpl -0x4(%rbp), %eax
ja 0x8be1
cmpl $0x7e, -0x4(%rbp)
jbe 0x8bf0
movslq 0x12660(%rip), %rax     # 0x1b248
cmpq $0x1ff, %rax            # imm = 0x1FF
jb 0x8c04
movl $0x0, 0x10196(%rip)     # 0x18d90
callq 0x9080
callq 0x91f0
jmp 0x8e55
movl 0x10181(%rip), %eax     # 0x18d90
andl $0x40, %eax
cmpl $0x0, %eax
je 0x8c24
movl -0x4(%rbp), %eax
movsbl %al, %edi
callq 0x9b30
jmp 0x8c75
movl 0x10166(%rip), %eax     # 0x18d90
andl $0x8, %eax
cmpl $0x0, %eax
je 0x8c3f
movl -0x4(%rbp), %eax
movsbl %al, %edi
callq 0x9b70
jmp 0x8c73
movl 0x1014b(%rip), %eax     # 0x18d90
andl $0x20, %eax
cmpl $0x0, %eax
je 0x8c5a
movl -0x4(%rbp), %eax
movsbl %al, %edi
callq 0x9bf0
jmp 0x8c71
movl -0x4(%rbp), %eax
movzbl %al, %edi
callq 0x9c70
cmpl $0x0, %eax
jne 0x8c6f
jmp 0x8e55
jmp 0x8c71
jmp 0x8c73
jmp 0x8c75
jmp 0x8c77
movl $0x0, 0x1010f(%rip)     # 0x18d90
jmp 0x8e55
jmp 0x8c88
cmpl $-0x1, 0x1009d(%rip)    # 0x18d2c
je 0x8cb2
movl 0x10099(%rip), %eax     # 0x18d30
cmpl 0x100d7(%rip), %eax     # 0x18d74
jg 0x8cb2
movl 0x100cf(%rip), %eax     # 0x18d74
cmpl 0x1008d(%rip), %eax     # 0x18d38
jg 0x8cb2
callq 0x5df0
movq 0x1008f(%rip), %rax     # 0x18d48
movslq 0x100b4(%rip), %rcx     # 0x18d74
movq (%rax,%rcx,8), %rax
movslq 0x100a5(%rip), %rcx     # 0x18d70
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl 0x100b0(%rip), %eax     # 0x18d8c
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8d33
movsbl 0x1008d(%rip), %eax     # 0x18d78
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8d33
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movw %cx, 0x4(%rax)
movl $0x1, %edi
callq 0x9ef0
movq 0x10032(%rip), %rax     # 0x18d48
movslq 0x10057(%rip), %rcx     # 0x18d74
movq (%rax,%rcx,8), %rax
movslq 0x10048(%rip), %rcx     # 0x18d70
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl 0x10053(%rip), %eax     # 0x18d8c
andl $0x2, %eax
cmpl $0x0, %eax
je 0x8d80
movl 0x10029(%rip), %eax     # 0x18d70
addl -0x10(%rbp), %eax
cmpl 0xfff4(%rip), %eax      # 0x18d44
jge 0x8d80
movq -0x20(%rbp), %rdi
movslq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl 0xffd9(%rip), %eax      # 0x18d44
subl 0xffff(%rip), %eax      # 0x18d70
subl -0x10(%rbp), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
callq 0x54d0
movl 0xffea(%rip), %eax      # 0x18d70
addl -0x10(%rbp), %eax
cmpl 0xffb5(%rip), %eax      # 0x18d44
jle 0x8dbf
movl $0x1, %edi
callq 0x9ef0
movq 0xffa6(%rip), %rax      # 0x18d48
movslq 0xffcb(%rip), %rcx      # 0x18d74
movq (%rax,%rcx,8), %rax
movslq 0xffbc(%rip), %rcx      # 0x18d70
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x4(%rbp), %edi
movl 0xffa8(%rip), %edx      # 0x18d70
movl 0xffa6(%rip), %ecx      # 0x18d74
leaq 0xff6b(%rip), %rsi      # 0x18d40
addq $0x20, %rsi
callq 0x9f60
cmpl $0x2, -0x10(%rbp)
jne 0x8e1e
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
movw %cx, 0x4(%rax)
movl 0xff74(%rip), %eax      # 0x18d70
addl $0x1, %eax
cmpl 0xff3f(%rip), %eax      # 0x18d44
jge 0x8e1c
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movw $0x400, 0x14(%rax)      # imm = 0x400
jmp 0x8e1e
movl 0xff4c(%rip), %eax      # 0x18d70
addl -0x10(%rbp), %eax
cmpl 0xff17(%rip), %eax      # 0x18d44
jge 0x8e45
movl 0xff3b(%rip), %edi      # 0x18d70
addl -0x10(%rbp), %edi
movl 0xff36(%rip), %esi      # 0x18d74
callq 0x7cf0
jmp 0x8e55
movsbl 0xff2c(%rip), %eax      # 0x18d78
orl $0x1, %eax
movb %al, 0xff23(%rip)       # 0x18d78
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)