user: Please show me the C implementation that matches the assembly code listed below:

```asm
<fast_validate_len>:
  endbr64
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  mov    %rdi,%rbx
  mov    $0x1,%edi
  sub    $0x8,%rsp
  call   <assert@plt>
  mov    %rbx,%rax
  test   %rbp,%rbp
  je     L9
  xor    %ecx,%ecx
  jmp    L133
  nopw   0x0(%rax,%rax,1)
L103:
  add    $0x1,%rax
  mov    %rax,%rcx
  sub    %rbx,%rcx
  cmp    %rbp,%rcx
  jae    L9
L133:
  movzbl (%rax),%edx
  test   %dl,%dl
  je     L9
  jns    L103
  mov    %edx,%esi
  and    $0xffffffe0,%esi
  cmp    $0xc0,%sil
  je     L84
  mov    %edx,%esi
  and    $0xfffffff0,%esi
  cmp    $0xe0,%sil
  je     L144
  mov    %edx,%esi
  and    $0xfffffff8,%esi
  cmp    $0xf0,%sil
  jne    L9
  mov    %rbp,%rsi
  sub    %rcx,%rsi
  cmp    $0x3,%rsi
  jbe    L9
  movzbl 0x1(%rax),%ecx
  and    $0x7,%edx
  lea    0x1(%rax),%rsi
  mov    %ecx,%edi
  and    $0xffffffc0,%edi
  cmp    $0x80,%dil
  jne    L9
  shl    $0x6,%edx
  and    $0x3f,%ecx
  mov    $0x10000,%r8d
  or     %edx,%ecx
L228:
  movzbl 0x1(%rsi),%edx
  mov    %edx,%edi
  and    $0xffffffc0,%edi
  cmp    $0x80,%dil
  jne    L9
  and    $0x3f,%edx
  shl    $0x6,%ecx
  or     %edx,%ecx
  movzbl 0x2(%rsi),%edx
  mov    %edx,%edi
  and    $0xffffffc0,%edi
  cmp    $0x80,%dil
  jne    L9
  shl    $0x6,%ecx
  and    $0x3f,%edx
  or     %ecx,%edx
  cmp    %edx,%r8d
  ja     L9
  cmp    $0x10ffff,%edx
  ja     L9
  mov    %edx,%ecx
  and    $0xfffff800,%ecx
  cmp    $0xd800,%ecx
  je     L9
  lea    -0xfdd0(%rdx),%ecx
  cmp    $0x1f,%ecx
  jbe    L9
  and    $0xfffe,%edx
  cmp    $0xfffe,%edx
  je     L9
  lea    0x2(%rsi),%rax
  jmp    L103
  cs nopw 0x0(%rax,%rax,1)
L84:
  mov    %rbp,%rsi
  sub    %rcx,%rsi
  cmp    $0x1,%rsi
  je     L9
  and    $0x1e,%edx
  je     L9
  movzbl 0x1(%rax),%edx
  and    $0xffffffc0,%edx
  cmp    $0x80,%dl
  je     L39
L9:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  ret
  nopl   0x0(%rax)
L39:
  add    $0x1,%rax
  jmp    L103
  nopl   0x0(%rax)
L144:
  mov    %rbp,%rsi
  sub    %rcx,%rsi
  cmp    $0x2,%rsi
  jbe    L9
  mov    %edx,%ecx
  mov    %rax,%rsi
  mov    $0x800,%r8d
  and    $0xf,%ecx
  jmp    L228
```

assistant: ```c
const char *fast_validate_len(const char *str, size_t max_len) {
  unsigned int val = 0;
  unsigned int min = 0;
  const char *p;
  assert(max_len >= 0);
  for (p = str; ((size_t)(p - str) < max_len) && *p; p++) {
    if (*(unsigned char *)p < 128)
      ;
    else {
      const char *last;
      last = p;
      if ((*(unsigned char *)p & 0xe0) == 0xc0) {
        if (max_len - (p - str) < 2)
          goto error;
        if ((*(unsigned char *)p & 0x1e) == 0)
          goto error;
        p++;
        if ((*(unsigned char *)p & 0xc0) != 0x80)
          goto error;
      } else {
        if ((*(unsigned char *)p & 0xf0) == 0xe0) {
          if (max_len - (p - str) < 3)
            goto error;
          min = (1 << 11);
          val = *(unsigned char *)p & 0x0f;
          goto TWO_REMAINING;
        } else if ((*(unsigned char *)p & 0xf8) == 0xf0) {
          if (max_len - (p - str) < 4)
            goto error;
          min = (1 << 16);
          val = *(unsigned char *)p & 0x07;
        } else
          goto error;
        p++;
        do {
          if ((*(unsigned char *)p & 0xc0) != 0x80)
            goto error;
          val <<= 6;
          val |= (*(unsigned char *)p) & 0x3f;
        } while (0);
      TWO_REMAINING:
        p++;
        do {
          if ((*(unsigned char *)p & 0xc0) != 0x80)
            goto error;
          val <<= 6;
          val |= (*(unsigned char *)p) & 0x3f;
        } while (0);
        p++;
        do {
          if ((*(unsigned char *)p & 0xc0) != 0x80)
            goto error;
          val <<= 6;
          val |= (*(unsigned char *)p) & 0x3f;
        } while (0);
        if (val < min)
          goto error;
        if (!((val) < 0x110000 && (((val)&0xFFFFF800) != 0xD800) && ((val) < 0xFDD0 || (val) > 0xFDEF) && ((val)&0xFFFE) != 0xFFFE))
          goto error;
      }
      continue;
    error:
      return last;
    }
  }
  return p;
}
```