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

```asm
<rangematch>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %esi,%eax
  mov    %edx,-0x20(%rbp)
  mov    %al,-0x1c(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x21,%al
  je     L158
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x5e,%al
  jne    L100
L158:
  mov    $0x1,%eax
  jmp    L113
L100:
  mov    $0x0,%eax
L113:
  mov    %eax,-0x4(%rbp)
  cmpl   $0x0,-0x4(%rbp)
  je     L142
  addq   $0x1,-0x18(%rbp)
L142:
  mov    -0x20(%rbp),%eax
  and    $0x10,%eax
  test   %eax,%eax
  je     L117
  movzbl -0x1c(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <tolower@plt>
  mov    %al,-0x1c(%rbp)
L117:
  movl   $0x0,-0x8(%rbp)
  jmp    L94
L16:
  cmpb   $0x5c,-0xa(%rbp)
  jne    L104
  mov    -0x20(%rbp),%eax
  and    $0x1,%eax
  test   %eax,%eax
  jne    L104
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl (%rax),%eax
  mov    %al,-0xa(%rbp)
L104:
  cmpb   $0x0,-0xa(%rbp)
  jne    L225
  mov    $0x0,%eax
  jmp    L129
L225:
  mov    -0x20(%rbp),%eax
  and    $0x10,%eax
  test   %eax,%eax
  je     L40
  movzbl -0xa(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <tolower@plt>
  mov    %al,-0xa(%rbp)
L40:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2d,%al
  jne    L140
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  mov    %al,-0x9(%rbp)
  cmpb   $0x0,-0x9(%rbp)
  je     L140
  cmpb   $0x5d,-0x9(%rbp)
  je     L140
  addq   $0x2,-0x18(%rbp)
  cmpb   $0x5c,-0x9(%rbp)
  jne    L253
  mov    -0x20(%rbp),%eax
  and    $0x1,%eax
  test   %eax,%eax
  jne    L253
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl (%rax),%eax
  mov    %al,-0x9(%rbp)
L253:
  cmpb   $0x0,-0x9(%rbp)
  jne    L196
  mov    $0x0,%eax
  jmp    L129
L196:
  mov    -0x20(%rbp),%eax
  and    $0x10,%eax
  test   %eax,%eax
  je     L107
  movzbl -0x9(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <tolower@plt>
  mov    %al,-0x9(%rbp)
L107:
  movzbl -0xa(%rbp),%edx
  movzbl -0x1c(%rbp),%eax
  cmp    %al,%dl
  ja     L94
  movzbl -0x1c(%rbp),%edx
  movzbl -0x9(%rbp),%eax
  cmp    %al,%dl
  ja     L94
  movl   $0x1,-0x8(%rbp)
  jmp    L94
L140:
  movzbl -0xa(%rbp),%eax
  cmp    -0x1c(%rbp),%al
  jne    L94
  movl   $0x1,-0x8(%rbp)
L94:
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl (%rax),%eax
  mov    %al,-0xa(%rbp)
  cmpb   $0x5d,-0xa(%rbp)
  jne    L16
  mov    -0x8(%rbp),%eax
  cmp    -0x4(%rbp),%eax
  je     L51
  mov    -0x18(%rbp),%rax
  jmp    L129
L51:
  mov    $0x0,%eax
L129:
  leave
  ret
```

assistant: ```c
const char *rangematch(const char *pattern, char test, int flags) {
  int negate, ok;
  char c, c2;
  if ((negate = (*pattern == '!' || *pattern == '^')))
    ++pattern;
  if (flags & 0x10)
    test = tolower((unsigned char)test);
  for (ok = 0; (c = *pattern++) != ']';) {
    if (c == '\\' && !(flags & 0x01))
      c = *pattern++;
    if (c == '\0')
      return (NULL);
    if (flags & 0x10)
      c = tolower((unsigned char)c);
    if (*pattern == '-' && (c2 = *(pattern + 1)) != '\0' && c2 != ']') {
      pattern += 2;
      if (c2 == '\\' && !(flags & 0x01))
        c2 = *pattern++;
      if (c2 == '\0')
        return (NULL);
      if (flags & 0x10)
        c2 = tolower((unsigned char)c2);
      if ((unsigned char)c <= (unsigned char)test && (unsigned char)test <= (unsigned char)c2)
        ok = 1;
    } else if (c == test)
      ok = 1;
  }
  return (ok == negate ? NULL : pattern);
}
```