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

```asm
<rangematch>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbx
  mov    %edx,%r15d
  mov    %rcx,0x8(%rsp)
  mov    %esi,%r13d
  movzbl (%rdi),%eax
  cmp    $0x21,%al
  sete   %dl
  cmp    $0x5e,%al
  sete   %al
  or     %eax,%edx
  mov    %dl,0x7(%rsp)
  cmp    $0x1,%dl
  sbb    $0xffffffffffffffff,%rbx
  mov    %r15d,%r14d
  and    $0x10,%r14d
  jne    L165
L172:
  lea    0x1(%rbx),%rbp
  movzbl (%rbx),%ebx
  mov    $0x0,%r12d
  mov    %r15d,%eax
  and    $0x2,%eax
  mov    %eax,(%rsp)
  jmp    L199
L165:
  movzbl %sil,%edi
  call   <tolower@plt>
  mov    %eax,%r13d
  jmp    L172
L16:
  test   $0x1,%r15b
  jne    L288
  movzbl 0x0(%rbp),%ebx
  lea    0x1(%rbp),%rbp
  jmp    L3
L288:
  test   %r14d,%r14d
  jne    L208
L114:
  movzbl 0x0(%rbp),%edx
  cmp    $0x2d,%dl
  je     L80
  cmp    %bl,%r13b
  mov    $0x1,%eax
  cmove  %eax,%r12d
L265:
  lea    0x1(%rbp),%rax
  movzbl 0x0(%rbp),%ebx
  cmp    $0x5d,%bl
  je     L225
L184:
  mov    %rax,%rbp
L199:
  cmp    $0x5c,%bl
  je     L16
L3:
  test   %bl,%bl
  je     L68
  cmp    $0x2f,%bl
  jne    L288
  cmpl   $0x0,(%rsp)
  je     L288
  mov    $0x0,%eax
  jmp    L148
L208:
  movzbl %bl,%edi
  call   <tolower@plt>
  mov    %eax,%ebx
  jmp    L114
L80:
  movzbl 0x1(%rbp),%eax
  cmp    $0x5d,%al
  je     L286
  test   %al,%al
  jne    L136
L286:
  cmp    %bl,%r13b
  je     L210
  lea    0x1(%rbp),%rax
  movzbl 0x0(%rbp),%ebx
  jmp    L184
L136:
  lea    0x2(%rbp),%rdx
  cmp    $0x5c,%al
  je     L43
L247:
  mov    %rdx,%rbp
L15:
  test   %r14d,%r14d
  jne    L283
L78:
  cmp    %bl,%r13b
  jl     L265
  cmp    %al,%r13b
  mov    $0x1,%eax
  cmovle %eax,%r12d
  jmp    L265
L43:
  test   $0x1,%r15b
  jne    L247
  lea    0x3(%rbp),%rdx
  movzbl 0x2(%rbp),%eax
  test   %al,%al
  je     L144
  mov    %rdx,%rbp
  jmp    L15
L283:
  movzbl %al,%edi
  call   <tolower@plt>
  jmp    L78
L225:
  mov    0x8(%rsp),%rcx
  mov    %rax,(%rcx)
  movzbl 0x7(%rsp),%eax
  cmp    %r12d,%eax
  setne  %al
  movzbl %al,%eax
  jmp    L148
L68:
  mov    $0xffffffff,%eax
L148:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L144:
  mov    $0xffffffff,%eax
  jmp    L148
L210:
  lea    0x1(%rbp),%rax
  mov    %edx,%ebx
  mov    $0x1,%r12d
  jmp    L184
```

assistant: ```c
int rangematch(const char *pattern, char test, int flags, char **newp) {
  int negate, ok;
  char c, c2;
  if ((negate = (*pattern == '!' || *pattern == '^')))
    ++pattern;
  if (flags & 0x10)
    test = tolower((unsigned char)test);
  ok = 0;
  c = *pattern++;
  do {
    if (c == '\\' && !(flags & 0x01))
      c = *pattern++;
    if (c == '\0')
      return ((-1));
    if (c == '/' && (flags & 0x02))
      return (0);
    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 ((-1));
      if (flags & 0x10)
        c2 = tolower((unsigned char)c2);
      if (c <= test && test <= c2)
        ok = 1;
    } else if (c == test)
      ok = 1;
  } while ((c = *pattern++) != ']');
  *newp = (char *)pattern;
  return (ok == negate ? 0 : 1);
}
```