user: 请从给定的汇编指令推导出C源代码:

```asm
<__strnlen>:
  endbr64
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rsi,%rbx
  test   %rsi,%rsi
  jne    L89
L73:
  mov    %rbx,%rax
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  ret
L89:
  mov    %rdi,%rbp
  mov    %rdi,%rax
  add    %rsi,%rax
  setb   %dil
  movzbl %dil,%edi
  mov    $0x0,%esi
  call   <__builtin_expect@plt>
  add    %rbp,%rbx
  test   %rax,%rax
  mov    $0xffffffffffffffff,%rax
  cmovne %rax,%rbx
  test   $0x7,%bpl
  je     L93
  mov    %rbp,%rax
L107:
  cmpb   $0x0,(%rax)
  je     L169
  add    $0x1,%rax
  test   $0x7,%al
  jne    L107
L130:
  cmp    %rax,%rbx
  jbe    L52
  movabs $0xfefefefefefefeff,%rdi
  movabs $0x8080808080808080,%rsi
  jmp    L18
L169:
  cmp    %rax,%rbx
  cmova  %rax,%rbx
  sub    %rbp,%rbx
  jmp    L73
L93:
  mov    %rbp,%rax
  jmp    L130
L39:
  lea    -0x7(%rax),%rcx
  jmp    L197
L240:
  lea    -0x6(%rax),%rcx
  jmp    L197
L90:
  lea    -0x5(%rax),%rcx
  jmp    L197
L175:
  lea    -0x4(%rax),%rcx
  jmp    L197
L28:
  lea    -0x3(%rax),%rcx
  jmp    L197
L36:
  lea    -0x2(%rax),%rcx
  jmp    L197
L115:
  cmp    %rax,%rbx
  jbe    L19
L18:
  mov    %rax,%rcx
  add    $0x8,%rax
  mov    %rdi,%rdx
  add    -0x8(%rax),%rdx
  test   %rsi,%rdx
  je     L115
  cmpb   $0x0,-0x8(%rax)
  je     L197
  cmpb   $0x0,-0x7(%rax)
  je     L39
  cmpb   $0x0,-0x6(%rax)
  je     L240
  cmpb   $0x0,-0x5(%rax)
  je     L90
  cmpb   $0x0,-0x4(%rax)
  je     L175
  cmpb   $0x0,-0x3(%rax)
  je     L28
  cmpb   $0x0,-0x2(%rax)
  je     L36
  cmpb   $0x0,-0x1(%rax)
  jne    L115
  lea    -0x1(%rax),%rcx
  jmp    L197
L19:
  mov    %rbx,%rcx
L197:
  cmp    %rbx,%rcx
  cmovbe %rcx,%rbx
  sub    %rbp,%rbx
  jmp    L73
L52:
  mov    %rax,%rcx
  jmp    L197
```

assistant: ```c
size_t __strnlen(const char *str, size_t maxlen) {
  const char *char_ptr, *end_ptr = str + maxlen;
  const unsigned long int *longword_ptr;
  unsigned long int longword, himagic, lomagic;
  if (maxlen == 0)
    return 0;
  if (__builtin_expect(end_ptr < str, 0))
    end_ptr = (const char *)~0UL;
  for (char_ptr = str; ((unsigned long int)char_ptr & (sizeof(longword) - 1)) != 0; ++char_ptr)
    if (*char_ptr == '\0') {
      if (char_ptr > end_ptr)
        char_ptr = end_ptr;
      return char_ptr - str;
    }
  longword_ptr = (unsigned long int *)char_ptr;
  himagic = 0x80808080L;
  lomagic = 0x01010101L;
  if (sizeof(longword) > 4) {
    himagic = ((himagic << 16) << 16) | himagic;
    lomagic = ((lomagic << 16) << 16) | lomagic;
  }
  if (sizeof(longword) > 8)
    abort();
  while (longword_ptr < (unsigned long int *)end_ptr) {
    longword = *longword_ptr++;
    if ((longword - lomagic) & himagic) {
      const char *cp = (const char *)(longword_ptr - 1);
      char_ptr = cp;
      if (cp[0] == 0)
        break;
      char_ptr = cp + 1;
      if (cp[1] == 0)
        break;
      char_ptr = cp + 2;
      if (cp[2] == 0)
        break;
      char_ptr = cp + 3;
      if (cp[3] == 0)
        break;
      if (sizeof(longword) > 4) {
        char_ptr = cp + 4;
        if (cp[4] == 0)
          break;
        char_ptr = cp + 5;
        if (cp[5] == 0)
          break;
        char_ptr = cp + 6;
        if (cp[6] == 0)
          break;
        char_ptr = cp + 7;
        if (cp[7] == 0)
          break;
      }
    }
    char_ptr = end_ptr;
  }
  if (char_ptr > end_ptr)
    char_ptr = end_ptr;
  return char_ptr - str;
}
```