// File: /workspace/github_c_makefile_star2_O0/odknt[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 (u < 127 || !IS_SET(MODE_UTF8)) {
		c[0] = u;
		width = len = 1;
	} else {
		len = utf8encode(u, c);
		if (!control && (width = wcwidth(u)) == -1)
			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);
			term.esc |= ESC_STR_END;
			goto check_control_code;
		}

		if (strescseq.len+len >= strescseq.siz) {
			/*
			 * 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();
			 */
			if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2)
				return;
			strescseq.siz *= 2;
			strescseq.buf = xrealloc(strescseq.buf, strescseq.siz);
		}

		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) {
		/* in UTF-8 mode ignore handling C1 control characters */
		if (IS_SET(MODE_UTF8) && ISCONTROLC1(u))
			return;
		tcontrolcode(u);
		/*
		 * control codes are not shown ever
		 */
		if (!term.esc)
			term.lastc = 0;
		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 (selected(term.c.x, term.c.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));
		gp->mode &= ~ATTR_WIDE;
	}

	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);
	term.lastc = u;

	if (width == 2) {
		gp->mode |= ATTR_WIDE;
		if (term.c.x+1 < term.col) {
			if (gp[1].mode == ATTR_WIDE && term.c.x+2 < term.col) {
				gp[2].u = ' ';
				gp[2].mode &= ~ATTR_WDUMMY;
			}
			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 0xa69d
movb $0x1, %al
cmpl $0x1f, -0x4(%rbp)
movb %al, -0x21(%rbp)
jbe 0xa6ca
movb $0x1, %al
cmpl $0x7f, -0x4(%rbp)
movb %al, -0x21(%rbp)
je 0xa6ca
xorl %eax, %eax
movl $0x80, %ecx
cmpl -0x4(%rbp), %ecx
movb %al, -0x22(%rbp)
ja 0xa6c4
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)
cmpl $0x7f, -0x4(%rbp)
jb 0xa6e9
movl 0x159d3(%rip), %eax     # 0x200b4
andl $0x40, %eax
cmpl $0x0, %eax
jne 0xa6ff
movl -0x4(%rbp), %eax
movb %al, -0x8(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xa72d
movl -0x4(%rbp), %edi
leaq -0x8(%rbp), %rsi
callq 0x6d70
movl %eax, -0x14(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xa72b
movl -0x4(%rbp), %edi
callq 0x6780
movl %eax, -0x10(%rbp)
cmpl $-0x1, %eax
jne 0xa72b
movl $0x1, -0x10(%rbp)
jmp 0xa72d
movl 0x15981(%rip), %eax     # 0x200b4
andl $0x20, %eax
cmpl $0x0, %eax
je 0xa748
leaq -0x8(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0xa420
movl 0x1596a(%rip), %eax     # 0x200b8
andl $0x4, %eax
cmpl $0x0, %eax
je 0xa834
cmpl $0x7, -0x4(%rbp)
je 0xa785
cmpl $0x18, -0x4(%rbp)
je 0xa785
cmpl $0x1a, -0x4(%rbp)
je 0xa785
cmpl $0x1b, -0x4(%rbp)
je 0xa785
movl $0x80, %eax
cmpl -0x4(%rbp), %eax
ja 0xa7a8
cmpl $0x9f, -0x4(%rbp)
ja 0xa7a8
movl 0x1592d(%rip), %eax     # 0x200b8
andl $-0x6, %eax
movl %eax, 0x15924(%rip)     # 0x200b8
movl 0x1591e(%rip), %eax     # 0x200b8
orl $0x10, %eax
movl %eax, 0x15915(%rip)     # 0x200b8
jmp 0xa836
movq 0x17961(%rip), %rax     # 0x22110
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
cmpq 0x1794b(%rip), %rax     # 0x22108
jb 0xa802
movabsq $0x7ffffffffffffffd, %rax # imm = 0x7FFFFFFFFFFFFFFD
cmpq %rax, 0x17938(%rip)     # 0x22108
jbe 0xa7d7
jmp 0xab97
movq 0x1792a(%rip), %rax     # 0x22108
shlq %rax
movq %rax, 0x17920(%rip)     # 0x22108
movq 0x17911(%rip), %rdi     # 0x22100
movq 0x17912(%rip), %rsi     # 0x22108
callq 0x6cd0
movq %rax, 0x178fe(%rip)     # 0x22100
movq 0x178f7(%rip), %rdi     # 0x22100
addq 0x17900(%rip), %rdi     # 0x22110
leaq -0x8(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x6630
movslq -0x14(%rbp), %rax
addq 0x178e8(%rip), %rax     # 0x22110
movq %rax, 0x178e1(%rip)     # 0x22110
jmp 0xab97
jmp 0xa836
cmpl $0x0, -0xc(%rbp)
je 0xa885
movl 0x15872(%rip), %eax     # 0x200b4
andl $0x40, %eax
cmpl $0x0, %eax
je 0xa862
movl $0x80, %eax
cmpl -0x4(%rbp), %eax
ja 0xa862
cmpl $0x9f, -0x4(%rbp)
ja 0xa862
jmp 0xab97
movl -0x4(%rbp), %eax
movzbl %al, %edi
callq 0xac30
cmpl $0x0, 0x15844(%rip)     # 0x200b8
jne 0xa880
movl $0x0, 0x15850(%rip)     # 0x200d0
jmp 0xab97
movl 0x1582d(%rip), %eax     # 0x200b8
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa97c
movl 0x1581b(%rip), %eax     # 0x200b8
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa8ff
movl -0x4(%rbp), %eax
movb %al, %dl
movq 0x17aef(%rip), %rcx     # 0x223a0
movq %rcx, %rax
addq $0x1, %rax
movq %rax, 0x17ae1(%rip)     # 0x223a0
leaq 0x178da(%rip), %rax     # 0x221a0
movb %dl, (%rax,%rcx)
movl $0x40, %eax
cmpl -0x4(%rbp), %eax
ja 0xa8d9
cmpl $0x7e, -0x4(%rbp)
jbe 0xa8e6
cmpq $0x1ff, 0x17abc(%rip) # imm = 0x1FF
jb 0xa8fa
movl $0x0, 0x157c8(%rip)     # 0x200b8
callq 0xadd0
callq 0xaf40
jmp 0xab97
movl 0x157b3(%rip), %eax     # 0x200b8
andl $0x40, %eax
cmpl $0x0, %eax
je 0xa91a
movl -0x4(%rbp), %eax
movsbl %al, %edi
callq 0xb910
jmp 0xa96b
movl 0x15798(%rip), %eax     # 0x200b8
andl $0x8, %eax
cmpl $0x0, %eax
je 0xa935
movl -0x4(%rbp), %eax
movsbl %al, %edi
callq 0xb950
jmp 0xa969
movl 0x1577d(%rip), %eax     # 0x200b8
andl $0x20, %eax
cmpl $0x0, %eax
je 0xa950
movl -0x4(%rbp), %eax
movsbl %al, %edi
callq 0xb9d0
jmp 0xa967
movl -0x4(%rbp), %eax
movzbl %al, %edi
callq 0xba50
cmpl $0x0, %eax
jne 0xa965
jmp 0xab97
jmp 0xa967
jmp 0xa969
jmp 0xa96b
jmp 0xa96d
movl $0x0, 0x15741(%rip)     # 0x200b8
jmp 0xab97
jmp 0xa97e
movl 0x15714(%rip), %edi     # 0x20098
movl 0x15712(%rip), %esi     # 0x2009c
callq 0x7380
cmpl $0x0, %eax
je 0xa999
callq 0x6fb0
movq 0x11848(%rip), %rax     # 0x1c1e8
movslq 0x156f5(%rip), %rcx     # 0x2009c
movq (%rax,%rcx,8), %rax
movslq 0x156e6(%rip), %rcx     # 0x20098
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl 0x156f1(%rip), %eax     # 0x200b4
andl $0x1, %eax
cmpl $0x0, %eax
je 0xaa1a
movsbl 0x156ce(%rip), %eax     # 0x200a0
andl $0x1, %eax
cmpl $0x0, %eax
je 0xaa1a
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movw %cx, 0x4(%rax)
movl $0x1, %edi
callq 0xbcd0
movq 0x117eb(%rip), %rax     # 0x1c1e8
movslq 0x15698(%rip), %rcx     # 0x2009c
movq (%rax,%rcx,8), %rax
movslq 0x15689(%rip), %rcx     # 0x20098
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl 0x15694(%rip), %eax     # 0x200b4
andl $0x2, %eax
cmpl $0x0, %eax
je 0xaa79
movl 0x1566a(%rip), %eax     # 0x20098
addl -0x10(%rbp), %eax
cmpl 0x117ad(%rip), %eax     # 0x1c1e4
jge 0xaa79
movq -0x20(%rbp), %rdi
movslq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl 0x11792(%rip), %eax     # 0x1c1e4
subl 0x15640(%rip), %eax     # 0x20098
subl -0x10(%rbp), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
callq 0x6630
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %ecx
andl $0xfffffdff, %ecx       # imm = 0xFFFFFDFF
movw %cx, 0x4(%rax)
movl 0x15619(%rip), %eax     # 0x20098
addl -0x10(%rbp), %eax
cmpl 0x1175c(%rip), %eax     # 0x1c1e4
jle 0xaab8
movl $0x1, %edi
callq 0xbcd0
movq 0x1174d(%rip), %rax     # 0x1c1e8
movslq 0x155fa(%rip), %rcx     # 0x2009c
movq (%rax,%rcx,8), %rax
movslq 0x155eb(%rip), %rcx     # 0x20098
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x4(%rbp), %edi
movl 0x155d7(%rip), %edx     # 0x20098
movl 0x155d5(%rip), %ecx     # 0x2009c
leaq 0x11712(%rip), %rsi     # 0x1c1e0
addq $0x3ea8, %rsi           # imm = 0x3EA8
callq 0xbd40
movl -0x4(%rbp), %eax
movl %eax, 0x155ed(%rip)     # 0x200d0
cmpl $0x2, -0x10(%rbp)
jne 0xab60
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
movw %cx, 0x4(%rax)
movl 0x15597(%rip), %eax     # 0x20098
addl $0x1, %eax
cmpl 0x116da(%rip), %eax     # 0x1c1e4
jge 0xab5e
movq -0x20(%rbp), %rax
movzwl 0x14(%rax), %eax
cmpl $0x200, %eax            # imm = 0x200
jne 0xab49
movl 0x15577(%rip), %eax     # 0x20098
addl $0x2, %eax
cmpl 0x116ba(%rip), %eax     # 0x1c1e4
jge 0xab49
movq -0x20(%rbp), %rax
movl $0x20, 0x20(%rax)
movq -0x20(%rbp), %rax
movzwl 0x24(%rax), %ecx
andl $0xfffffbff, %ecx       # imm = 0xFFFFFBFF
movw %cx, 0x24(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movw $0x400, 0x14(%rax)      # imm = 0x400
jmp 0xab60
movl 0x15532(%rip), %eax     # 0x20098
addl -0x10(%rbp), %eax
cmpl 0x11675(%rip), %eax     # 0x1c1e4
jge 0xab87
movl 0x15521(%rip), %edi     # 0x20098
addl -0x10(%rbp), %edi
movl 0x1551c(%rip), %esi     # 0x2009c
callq 0x97e0
jmp 0xab97
movsbl 0x15512(%rip), %eax     # 0x200a0
orl $0x1, %eax
movb %al, 0x15509(%rip)      # 0x200a0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)