user: What would the C source look like for the assembly code provided here?

```asm
<utf_last_valid2>:
  endbr64
  movslq %esi,%rdx
  add    %rdi,%rdx
  cmp    %rdx,%rdi
  jae    L242
  movzbl (%rdi),%ecx
  lea    0x1(%rdi),%rax
  mov    %rdi,%r8
  test   %cl,%cl
  js     L141
L301:
  cmp    %rax,%rdx
  jbe    L247
  movzbl (%rax),%ecx
  mov    %rax,%r8
  add    $0x1,%rax
  test   %cl,%cl
  jns    L301
L141:
  cmp    $0xc1,%cl
  jbe    L202
  cmp    $0xdf,%cl
  jbe    L146
  cmp    $0xe0,%cl
  je     L250
  cmp    $0xec,%cl
  jbe    L112
  cmp    $0xed,%cl
  je     L273
  cmp    $0xef,%cl
  jbe    L112
  cmp    $0xf0,%cl
  je     L332
  cmp    $0xf3,%cl
  ja     L31
  cmp    %rax,%rdx
  jbe    L202
  movzbl (%rax),%esi
  lea    -0x80(%rsi),%ecx
  cmp    $0x3f,%cl
  ja     L202
L338:
  lea    0x1(%rax),%rcx
  cmp    %rcx,%rdx
  jbe    L202
  lea    0x2(%rax),%rcx
  movzbl 0x1(%rax),%eax
L265:
  add    $0xffffff80,%eax
  cmp    $0x3f,%al
  ja     L202
  cmp    %rcx,%rdx
  jbe    L202
  lea    0x1(%rcx),%rax
  movzbl (%rcx),%ecx
  add    $0xffffff80,%ecx
  cmp    $0x3f,%cl
  jbe    L301
L202:
  mov    %r8,%rax
  ret
  nopl   0x0(%rax)
L146:
  cmp    %rax,%rdx
  jbe    L202
  movzbl (%rax),%ecx
  add    $0x1,%rax
  nopl   0x0(%rax)
L65:
  add    $0xffffff80,%ecx
  cmp    $0x3f,%cl
  jbe    L301
  mov    %r8,%rax
  ret
L242:
  mov    %rdi,%r8
  jmp    L202
L250:
  cmp    %rax,%rdx
  jbe    L202
  movzbl (%rax),%esi
  lea    0x60(%rsi),%ecx
  cmp    $0x1f,%cl
  ja     L202
L231:
  lea    0x1(%rax),%rcx
  cmp    %rcx,%rdx
  jbe    L202
  movzbl 0x1(%rax),%ecx
  add    $0x2,%rax
  jmp    L65
L247:
  mov    %rax,%r8
  jmp    L202
L112:
  cmp    %rax,%rdx
  jbe    L202
  lea    0x1(%rax),%rcx
  movzbl (%rax),%eax
  jmp    L265
L273:
  cmp    %rax,%rdx
  jbe    L202
  movzbl (%rax),%esi
  lea    -0x80(%rsi),%ecx
  cmp    $0x1f,%cl
  jbe    L231
  mov    %r8,%rax
  ret
L31:
  cmp    %rax,%rdx
  jbe    L202
  cmp    $0xf4,%cl
  jne    L202
  movzbl (%rax),%esi
  lea    -0x80(%rsi),%ecx
  cmp    $0xf,%cl
  jbe    L338
  mov    %r8,%rax
  ret
L332:
  cmp    %rax,%rdx
  jbe    L202
  movzbl (%rax),%esi
  lea    0x70(%rsi),%ecx
  cmp    $0x2f,%cl
  jbe    L338
  mov    %r8,%rax
  ret
```

assistant: ```c
const char *utf_last_valid2(const char *data, int len) {
  const char *start = data, *end = data + len;
  int state = 0;
  while (data < end) {
    unsigned char octet = *data++;
    switch (state) {
    case 0:
      if (octet <= 0x7F)
        break;
      else if (octet <= 0xC1)
        state = 8;
      else if (octet <= 0xDF)
        state = 1;
      else if (octet == 0xE0)
        state = 2;
      else if (octet <= 0xEC)
        state = 3;
      else if (octet == 0xED)
        state = 4;
      else if (octet <= 0xEF)
        state = 3;
      else if (octet == 0xF0)
        state = 5;
      else if (octet <= 0xF3)
        state = 6;
      else if (octet <= 0xF4)
        state = 7;
      else
        state = 8;
      break;
    case 1:
      if (octet >= 0x80 && octet <= 0xBF)
        state = 0;
      else
        state = 8;
      break;
    case 2:
      if (octet >= 0xA0 && octet <= 0xBF)
        state = 1;
      else
        state = 8;
      break;
    case 3:
      if (octet >= 0x80 && octet <= 0xBF)
        state = 1;
      else
        state = 8;
      break;
    case 4:
      if (octet >= 0x80 && octet <= 0x9F)
        state = 1;
      else
        state = 8;
      break;
    case 5:
      if (octet >= 0x90 && octet <= 0xBF)
        state = 3;
      else
        state = 8;
      break;
    case 6:
      if (octet >= 0x80 && octet <= 0xBF)
        state = 3;
      else
        state = 8;
      break;
    case 7:
      if (octet >= 0x80 && octet <= 0x8F)
        state = 3;
      else
        state = 8;
      break;
    default:
    case 8:
      return start;
    }
    if (state == 0)
      start = data;
  }
  return start;
}
```