user: Converte this assembly snippet into its equivalent C code:

```asm
<isUTF8>:
  endbr64
  test   %esi,%esi
  jle    L289
  lea    -0x1(%rsi),%eax
  xor    %r8d,%r8d
  lea    0x1(%rdi,%rax,1),%rcx
  nopw   0x0(%rax,%rax,1)
L311:
  movzbl (%rdi),%eax
  test   %r8d,%r8d
  jne    L269
  test   %al,%al
  jns    L156
  mov    %eax,%edx
  and    $0xffffffe0,%edx
  cmp    $0xc0,%dl
  je     L93
  mov    %eax,%edx
  and    $0xfffffff0,%edx
  cmp    $0xe0,%dl
  je     L261
  mov    %eax,%edx
  and    $0xfffffff8,%edx
  cmp    $0xf0,%dl
  je     L18
  mov    %eax,%edx
  and    $0xfffffffc,%edx
  cmp    $0xf8,%dl
  je     L109
  mov    %eax,%edx
  and    $0xfffffffe,%edx
  cmp    $0xfc,%dl
  je     L144
L191:
  mov    %r8d,%eax
  ret
  nopw   0x0(%rax,%rax,1)
L269:
  mov    %eax,%esi
  and    $0xffffffc0,%esi
  cmp    $0x80,%sil
  jne    L246
  shl    $0x6,%rdx
  and    $0x3f,%eax
  add    %rax,%rdx
  sub    $0x1,%r8d
  jne    L156
  cmp    $0x1,%r9d
  jne    L185
  cmp    $0x7f,%rdx
  jbe    L191
L185:
  cmp    $0x2,%r9d
  jne    L165
  cmp    $0x7ff,%rdx
  jbe    L191
L165:
  cmp    $0x3,%r9d
  jne    L50
  cmp    $0xffff,%rdx
  jbe    L191
L50:
  cmp    $0x4,%r9d
  jne    L150
  cmp    $0x1fffff,%rdx
  jbe    L191
L150:
  cmp    $0x5,%r9d
  jne    L156
  cmp    $0x3ffffff,%rdx
  jbe    L191
  nopw   0x0(%rax,%rax,1)
L156:
  add    $0x1,%rdi
  cmp    %rcx,%rdi
  jne    L311
L289:
  mov    $0x1,%r8d
  mov    %r8d,%eax
  ret
  nopw   0x0(%rax,%rax,1)
L93:
  mov    %rax,%rdx
  add    $0x1,%rdi
  mov    $0x1,%r9d
  mov    $0x1,%r8d
  and    $0x1f,%edx
  cmp    %rcx,%rdi
  jne    L311
  jmp    L289
  nopl   0x0(%rax)
L261:
  mov    %rax,%rdx
  add    $0x1,%rdi
  mov    $0x2,%r9d
  mov    $0x2,%r8d
  and    $0xf,%edx
  cmp    %rcx,%rdi
  jne    L311
  jmp    L289
  nopl   0x0(%rax)
L144:
  mov    %rax,%rdx
  add    $0x1,%rdi
  mov    $0x5,%r9d
  mov    $0x5,%r8d
  and    $0x1,%edx
  cmp    %rcx,%rdi
  jne    L311
  jmp    L289
  nopl   0x0(%rax)
L18:
  mov    %rax,%rdx
  add    $0x1,%rdi
  mov    $0x3,%r9d
  mov    $0x3,%r8d
  and    $0x7,%edx
  cmp    %rcx,%rdi
  jne    L311
  jmp    L289
  nopl   0x0(%rax)
L109:
  mov    %rax,%rdx
  add    $0x1,%rdi
  mov    $0x4,%r9d
  mov    $0x4,%r8d
  and    $0x3,%edx
  cmp    %rcx,%rdi
  jne    L311
  jmp    L289
  nopl   0x0(%rax)
L246:
  xor    %r8d,%r8d
  jmp    L191
```

assistant: ```c
int isUTF8(unsigned char *str, int length) {
  int i, mode = 0, m2;
  unsigned long ucs;
  unsigned char ch;
  for (i = 0; i < length; i++) {
    ch = str[i];
    if (mode == 0) {
      if ((ch & 0x80) == 0)
        continue;
      if ((ch & 0xe0) == 0xc0) {
        mode = m2 = 1;
        ucs = (ch & 0x1f);
        continue;
      }
      if ((ch & 0xf0) == 0xe0) {
        mode = m2 = 2;
        ucs = (ch & 0x0f);
        continue;
      }
      if ((ch & 0xf8) == 0xf0) {
        mode = m2 = 3;
        ucs = (ch & 0x07);
        continue;
      }
      if ((ch & 0xfc) == 0xf8) {
        mode = m2 = 4;
        ucs = (ch & 0x03);
        continue;
      }
      if ((ch & 0xfe) == 0xfc) {
        mode = m2 = 5;
        ucs = (ch & 0x01);
        continue;
      }
      return 0;
    } else {
      if ((ch & 0xc0) != 0x80)
        return 0;
      ucs <<= 6;
      ucs += (ch & 0x3f);
      mode--;
      if (!mode) {
        if (m2 == 1 && ucs < 0x0000080)
          return 0;
        if (m2 == 2 && ucs < 0x0000800)
          return 0;
        if (m2 == 3 && ucs < 0x0010000)
          return 0;
        if (m2 == 4 && ucs < 0x0200000)
          return 0;
        if (m2 == 5 && ucs < 0x4000000)
          return 0;
      }
    }
  }
  return 1;
}
```