// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./parse.h
// Function: utf8_charset
void utf8_charset(struct terminal_t *term, uint8_t ch)
{
	if (0x80 <= ch && ch <= 0xBF) {
		/* check illegal UTF-8 sequence
			* ? byte sequence: first byte must be between 0xC2 ~ 0xFD
			* 2 byte sequence: first byte must be between 0xC2 ~ 0xDF
			* 3 byte sequence: second byte following 0xE0 must be between 0xA0 ~ 0xBF
			* 4 byte sequence: second byte following 0xF0 must be between 0x90 ~ 0xBF
			* 5 byte sequence: second byte following 0xF8 must be between 0x88 ~ 0xBF
			* 6 byte sequence: second byte following 0xFC must be between 0x84 ~ 0xBF
		*/
		if ((term->charset.following_byte == 0)
			|| (term->charset.following_byte == 1 && term->charset.count == 0 && term->charset.code <= 1)
			|| (term->charset.following_byte == 2 && term->charset.count == 0 && term->charset.code == 0 && ch < 0xA0)
			|| (term->charset.following_byte == 3 && term->charset.count == 0 && term->charset.code == 0 && ch < 0x90)
			|| (term->charset.following_byte == 4 && term->charset.count == 0 && term->charset.code == 0 && ch < 0x88)
			|| (term->charset.following_byte == 5 && term->charset.count == 0 && term->charset.code == 0 && ch < 0x84))
			term->charset.is_valid = false;

		term->charset.code <<= 6;
		term->charset.code += ch & 0x3F;
		term->charset.count++;
	} else if (0xC0 <= ch && ch <= 0xDF) {
		term->charset.code = ch & 0x1F;
		term->charset.following_byte = 1;
		term->charset.count = 0;
		return;
	} else if (0xE0 <= ch && ch <= 0xEF) {
		term->charset.code = ch & 0x0F;
		term->charset.following_byte = 2;
		term->charset.count = 0;
		return;
	} else if (0xF0 <= ch && ch <= 0xF7) {
		term->charset.code = ch & 0x07;
		term->charset.following_byte = 3;
		term->charset.count = 0;
		return;
	} else if (0xF8 <= ch && ch <= 0xFB) {
		term->charset.code = ch & 0x03;
		term->charset.following_byte = 4;
		term->charset.count = 0;
		return;
	} else if (0xFC <= ch && ch <= 0xFD) {
		term->charset.code = ch & 0x01;
		term->charset.following_byte = 5;
		term->charset.count = 0;
		return;
	} else { /* 0xFE - 0xFF: not used in UTF-8 */
		addch(term, REPLACEMENT_CHAR);
		reset_charset(term);
		return;
	}

	if (term->charset.count >= term->charset.following_byte) {
		/*	illegal code point (ref: http://www.unicode.org/reports/tr27/tr27-4.html)
			0xD800   ~ 0xDFFF : surrogate pair
			0xFDD0   ~ 0xFDEF : noncharacter
			0xnFFFE  ~ 0xnFFFF: noncharacter (n: 0x00 ~ 0x10)
			0x110000 ~        : invalid (unicode U+0000 ~ U+10FFFF)
		*/
		if (!term->charset.is_valid
			|| (0xD800 <= term->charset.code && term->charset.code <= 0xDFFF)
			|| (0xFDD0 <= term->charset.code && term->charset.code <= 0xFDEF)
			|| ((term->charset.code & 0xFFFF) == 0xFFFE || (term->charset.code & 0xFFFF) == 0xFFFF)
			|| (term->charset.code > 0x10FFFF))
			addch(term, REPLACEMENT_CHAR);
		else
			addch(term, term->charset.code);

		reset_charset(term);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movzbl -0x9(%rbp), %ecx
movl $0x80, %eax
cmpl %ecx, %eax
jg 0x926e
movzbl -0x9(%rbp), %eax
cmpl $0xbf, %eax
jg 0x926e
movq -0x8(%rbp), %rax
cmpl $0x0, 0x58(%rax)
je 0x9236
movq -0x8(%rbp), %rax
cmpl $0x1, 0x58(%rax)
jne 0x9192
movq -0x8(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x9192
movq -0x8(%rbp), %rax
cmpl $0x1, 0x54(%rax)
jbe 0x9236
movq -0x8(%rbp), %rax
cmpl $0x2, 0x58(%rax)
jne 0x91bb
movq -0x8(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x91bb
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x91bb
movzbl -0x9(%rbp), %eax
cmpl $0xa0, %eax
jl 0x9236
movq -0x8(%rbp), %rax
cmpl $0x3, 0x58(%rax)
jne 0x91e4
movq -0x8(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x91e4
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x91e4
movzbl -0x9(%rbp), %eax
cmpl $0x90, %eax
jl 0x9236
movq -0x8(%rbp), %rax
cmpl $0x4, 0x58(%rax)
jne 0x920d
movq -0x8(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x920d
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x920d
movzbl -0x9(%rbp), %eax
cmpl $0x88, %eax
jl 0x9236
movq -0x8(%rbp), %rax
cmpl $0x5, 0x58(%rax)
jne 0x923e
movq -0x8(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x923e
movq -0x8(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x923e
movzbl -0x9(%rbp), %eax
cmpl $0x84, %eax
jge 0x923e
movq -0x8(%rbp), %rax
movb $0x0, 0x60(%rax)
movq -0x8(%rbp), %rax
movl 0x54(%rax), %ecx
shll $0x6, %ecx
movl %ecx, 0x54(%rax)
movzbl -0x9(%rbp), %ecx
andl $0x3f, %ecx
movq -0x8(%rbp), %rax
addl 0x54(%rax), %ecx
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x93cf
movzbl -0x9(%rbp), %ecx
movl $0xc0, %eax
cmpl %ecx, %eax
jg 0x92af
movzbl -0x9(%rbp), %eax
cmpl $0xdf, %eax
jg 0x92af
movzbl -0x9(%rbp), %ecx
andl $0x1f, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x5c(%rax)
jmp 0x947f
movzbl -0x9(%rbp), %ecx
movl $0xe0, %eax
cmpl %ecx, %eax
jg 0x92f0
movzbl -0x9(%rbp), %eax
cmpl $0xef, %eax
jg 0x92f0
movzbl -0x9(%rbp), %ecx
andl $0xf, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x2, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x5c(%rax)
jmp 0x947f
movzbl -0x9(%rbp), %ecx
movl $0xf0, %eax
cmpl %ecx, %eax
jg 0x9331
movzbl -0x9(%rbp), %eax
cmpl $0xf7, %eax
jg 0x9331
movzbl -0x9(%rbp), %ecx
andl $0x7, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x3, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x5c(%rax)
jmp 0x947f
movzbl -0x9(%rbp), %ecx
movl $0xf8, %eax
cmpl %ecx, %eax
jg 0x9372
movzbl -0x9(%rbp), %eax
cmpl $0xfb, %eax
jg 0x9372
movzbl -0x9(%rbp), %ecx
andl $0x3, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x4, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x5c(%rax)
jmp 0x947f
movzbl -0x9(%rbp), %ecx
movl $0xfc, %eax
cmpl %ecx, %eax
jg 0x93b3
movzbl -0x9(%rbp), %eax
cmpl $0xfd, %eax
jg 0x93b3
movzbl -0x9(%rbp), %ecx
andl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x5, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x5c(%rax)
jmp 0x947f
movq -0x8(%rbp), %rdi
movl $0x3f, %esi
callq 0x4fb0
movq -0x8(%rbp), %rdi
callq 0x5380
jmp 0x947f
movq -0x8(%rbp), %rax
movl 0x5c(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jl 0x947f
movq -0x8(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0x9456
movq -0x8(%rbp), %rcx
movl $0xd800, %eax           # imm = 0xD800
cmpl 0x54(%rcx), %eax
ja 0x9408
movq -0x8(%rbp), %rax
cmpl $0xdfff, 0x54(%rax)     # imm = 0xDFFF
jbe 0x9456
movq -0x8(%rbp), %rcx
movl $0xfdd0, %eax           # imm = 0xFDD0
cmpl 0x54(%rcx), %eax
ja 0x9423
movq -0x8(%rbp), %rax
cmpl $0xfdef, 0x54(%rax)     # imm = 0xFDEF
jbe 0x9456
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cmpl $0xfffe, %eax           # imm = 0xFFFE
je 0x9456
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x9456
movq -0x8(%rbp), %rax
cmpl $0x10ffff, 0x54(%rax)   # imm = 0x10FFFF
jbe 0x9466
movq -0x8(%rbp), %rdi
movl $0x3f, %esi
callq 0x4fb0
jmp 0x9476
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x54(%rax), %esi
callq 0x4fb0
movq -0x8(%rbp), %rdi
callq 0x5380
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)