// File: Davidc2525[P]Leaf/parser/Scanner.cpp
// Function: UTF8Buffer::Read()
int UTF8Buffer::Read() {
	int ch;
	do {
		ch = Buffer::Read();
		// until we find a utf8 start (0xxxxxxx or 11xxxxxx)
	} while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EoF));
	if (ch < 128 || ch == EoF) {
		// nothing to do, first 127 chars are the same in ascii and utf8
		// 0xxxxxxx or end of file character
	} else if ((ch & 0xF0) == 0xF0) {
		// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
		int c1 = ch & 0x07; ch = Buffer::Read();
		int c2 = ch & 0x3F; ch = Buffer::Read();
		int c3 = ch & 0x3F; ch = Buffer::Read();
		int c4 = ch & 0x3F;
		ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
	} else if ((ch & 0xE0) == 0xE0) {
		// 1110xxxx 10xxxxxx 10xxxxxx
		int c1 = ch & 0x0F; ch = Buffer::Read();
		int c2 = ch & 0x3F; ch = Buffer::Read();
		int c3 = ch & 0x3F;
		ch = (((c1 << 6) | c2) << 6) | c3;
	} else if ((ch & 0xC0) == 0xC0) {
		// 110xxxxx 10xxxxxx
		int c1 = ch & 0x1F; ch = Buffer::Read();
		int c2 = ch & 0x3F;
		ch = (c1 << 6) | c2;
	}
	return ch;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xf800
movl %eax, -0xc(%rbp)
xorl %eax, %eax
cmpl $0x80, -0xc(%rbp)
movb %al, -0x39(%rbp)
jl 0xfc71
movl -0xc(%rbp), %ecx
andl $0xc0, %ecx
xorl %eax, %eax
cmpl $0xc0, %ecx
movb %al, -0x39(%rbp)
je 0xfc71
cmpl $0x10000, -0xc(%rbp)    # imm = 0x10000
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0xfc34
cmpl $0x80, -0xc(%rbp)
jl 0xfc8a
cmpl $0x10000, -0xc(%rbp)    # imm = 0x10000
jne 0xfc8f
jmp 0xfd98
movl -0xc(%rbp), %eax
andl $0xf0, %eax
cmpl $0xf0, %eax
jne 0xfd03
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x10(%rbp)
callq 0xf800
movq -0x38(%rbp), %rdi
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x14(%rbp)
callq 0xf800
movq -0x38(%rbp), %rdi
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x18(%rbp)
callq 0xf800
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %eax
shll $0x6, %eax
orl -0x14(%rbp), %eax
shll $0x6, %eax
orl -0x18(%rbp), %eax
shll $0x6, %eax
orl -0x1c(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0xfd96
movl -0xc(%rbp), %eax
andl $0xe0, %eax
cmpl $0xe0, %eax
jne 0xfd59
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x20(%rbp)
callq 0xf800
movq -0x38(%rbp), %rdi
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x24(%rbp)
callq 0xf800
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
shll $0x6, %eax
orl -0x24(%rbp), %eax
shll $0x6, %eax
orl -0x28(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0xfd94
movl -0xc(%rbp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0xfd92
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %eax
andl $0x1f, %eax
movl %eax, -0x2c(%rbp)
callq 0xf800
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
shll $0x6, %eax
orl -0x30(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0xfd94
jmp 0xfd96
jmp 0xfd98
movl -0xc(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)