// File: ambersun1234[P]AVL_Tree/./googletest/googletest/src/gtest-printers.cc
// Function: testing::internal::(anonymous namespace)::IsValidUTF8(char const*, unsigned long)
bool IsValidUTF8(const char* str, size_t length) {
  const unsigned char *s = reinterpret_cast<const unsigned char *>(str);

  for (size_t i = 0; i < length;) {
    unsigned char lead = s[i++];

    if (lead <= 0x7f) {
      continue;  // single-byte character (ASCII) 0..7F
    }
    if (lead < 0xc2) {
      return false;  // trail byte or non-shortest form
    } else if (lead <= 0xdf && (i + 1) <= length && IsUTF8TrailByte(s[i])) {
      ++i;  // 2-byte character
    } else if (0xe0 <= lead && lead <= 0xef && (i + 2) <= length &&
               IsUTF8TrailByte(s[i]) &&
               IsUTF8TrailByte(s[i + 1]) &&
               // check for non-shortest form and surrogate
               (lead != 0xe0 || s[i] >= 0xa0) &&
               (lead != 0xed || s[i] < 0xa0)) {
      i += 2;  // 3-byte character
    } else if (0xf0 <= lead && lead <= 0xf4 && (i + 3) <= length &&
               IsUTF8TrailByte(s[i]) &&
               IsUTF8TrailByte(s[i + 1]) &&
               IsUTF8TrailByte(s[i + 2]) &&
               // check for non-shortest form
               (lead != 0xf0 || s[i] >= 0x90) &&
               (lead != 0xf4 || s[i] < 0x90)) {
      i += 3;  // 4-byte character
    } else {
      return false;
    }
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x36785
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movb (%rax,%rcx), %al
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0x7f, %eax
jg 0x365b2
jmp 0x36580
movzbl -0x29(%rbp), %eax
cmpl $0xc2, %eax
jge 0x365c6
movb $0x0, -0x1(%rbp)
jmp 0x36789
movzbl -0x29(%rbp), %eax
cmpl $0xdf, %eax
jg 0x36607
movq -0x28(%rbp), %rax
addq $0x1, %rax
cmpq -0x18(%rbp), %rax
ja 0x36607
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x367a0
testb $0x1, %al
jne 0x365f6
jmp 0x36607
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3677e
movzbl -0x29(%rbp), %ecx
movl $0xe0, %eax
cmpl %ecx, %eax
jg 0x366b1
movzbl -0x29(%rbp), %eax
cmpl $0xef, %eax
jg 0x366b1
movq -0x28(%rbp), %rax
addq $0x2, %rax
cmpq -0x18(%rbp), %rax
ja 0x366b1
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x367a0
testb $0x1, %al
jne 0x3664c
jmp 0x366b1
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edi
callq 0x367a0
testb $0x1, %al
jne 0x36664
jmp 0x366b1
movzbl -0x29(%rbp), %eax
cmpl $0xe0, %eax
jne 0x36682
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xa0, %eax
jl 0x366b1
movzbl -0x29(%rbp), %eax
cmpl $0xed, %eax
jne 0x366a0
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xa0, %eax
jge 0x366b1
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x3677c
movzbl -0x29(%rbp), %ecx
movl $0xf0, %eax
cmpl %ecx, %eax
jg 0x36774
movzbl -0x29(%rbp), %eax
cmpl $0xf4, %eax
jg 0x36774
movq -0x28(%rbp), %rax
addq $0x3, %rax
cmpq -0x18(%rbp), %rax
ja 0x36774
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x367a0
testb $0x1, %al
jne 0x366fa
jmp 0x36774
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edi
callq 0x367a0
testb $0x1, %al
jne 0x36712
jmp 0x36774
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl 0x2(%rax,%rcx), %edi
callq 0x367a0
testb $0x1, %al
jne 0x3672a
jmp 0x36774
movzbl -0x29(%rbp), %eax
cmpl $0xf0, %eax
jne 0x36748
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x90, %eax
jl 0x36774
movzbl -0x29(%rbp), %eax
cmpl $0xf4, %eax
jne 0x36766
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x90, %eax
jge 0x36774
movq -0x28(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x3677a
movb $0x0, -0x1(%rbp)
jmp 0x36789
jmp 0x3677c
jmp 0x3677e
jmp 0x36780
jmp 0x36580
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)