user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<pat_next>:
  endbr64
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  test   %rsi,%rsi
  je     L318
  cmpb   $0x0,(%rdi)
  mov    %rdi,%r9
  je     L318
  movq   $0x1,(%rdx)
  movsbl (%rdi),%eax
  mov    %rsi,%r8
  cmp    $0x5c,%al
  je     L146
  cmp    $0x5b,%al
  je     L32
  cmp    $0x2a,%al
  je     L251
  cmp    $0x3f,%al
  je     L113
  xor    %ebp,%ebp
L225:
  test   %al,%al
  jns    L100
  lea    0x4(%rsp),%rdi
  mov    %r8,%rdx
  mov    %r9,%rsi
  call   <mbtowc@plt>
  test   %eax,%eax
  js     L74
  add    %eax,%ebp
  mov    0x4(%rsp),%eax
  movslq %ebp,%rbp
L468:
  mov    %rbp,(%rbx)
  jmp    L100
  nop
L318:
  movq   $0x0,(%rbx)
  xor    %eax,%eax
L100:
  mov    0x8(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L350
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  ret
  nopl   0x0(%rax)
L32:
  mov    $0x5b,%eax
  cmp    $0x1,%rsi
  je     L100
  movzbl 0x1(%rdi),%eax
  cmp    $0x5e,%al
  sete   %cl
  cmp    $0x21,%al
  sete   %al
  or     %eax,%ecx
  movzbl %cl,%ecx
  lea    0x1(%rcx),%rdx
  cmp    %rdx,%rsi
  jbe    L132
  movzbl 0x1(%rdi,%rcx,1),%eax
  cmp    $0x5d,%al
  je     L231
L353:
  movabs $0x2400400000000000,%rdi
  cs nopw 0x0(%rax,%rax,1)
L334:
  cmp    $0x5d,%al
  je     L447
  test   %al,%al
  je     L447
  lea    0x1(%rdx),%rcx
  cmp    %r8,%rcx
  jb     L80
L81:
  mov    $0x5b,%eax
  cmp    %r8,%rcx
  je     L100
  cmpb   $0x0,(%r9,%rcx,1)
  je     L100
  add    $0x1,%rcx
  mov    $0xfffffffd,%eax
  mov    %rcx,(%rbx)
  jmp    L100
  nopl   0x0(%rax,%rax,1)
L231:
  lea    0x2(%rcx),%rdx
  cmp    %rdx,%rsi
  jbe    L447
  movzbl 0x2(%rdi,%rcx,1),%eax
  jmp    L353
  nopl   0x0(%rax)
L80:
  movzbl 0x1(%r9,%rdx,1),%esi
  cmp    $0x5b,%al
  jne    L387
  test   %sil,%sil
  jne    L273
L387:
  mov    %esi,%eax
  mov    %rcx,%rdx
  jmp    L334
  cs nopw 0x0(%rax,%rax,1)
L273:
  cmp    $0x3d,%sil
  ja     L261
  bt     %rsi,%rdi
  jb     L355
L261:
  mov    %rcx,%rdx
L75:
  movzbl (%r9,%rdx,1),%eax
  jmp    L334
  nopl   0x0(%rax)
L146:
  cmpb   $0x0,0x1(%rdi)
  je     L100
  mov    D1(%rip),%rdx
  and    (%rdx),%ecx
  jne    L100
  movq   $0x2,(%rbx)
  add    $0x1,%r9
  movsbl 0x1(%rdi),%eax
  mov    $0x1,%ebp
  jmp    L225
  nopw   0x0(%rax,%rax,1)
L355:
  lea    0x2(%rdx),%rax
  cmp    %rax,%r8
  jbe    L216
  cmpb   $0x0,0x2(%r9,%rdx,1)
  je     L366
  lea    0x3(%rdx),%rax
  cmp    %rax,%r8
  ja     L366
  jmp    L216
  nopl   0x0(%rax)
L191:
  cmp    %sil,-0x1(%r9,%rax,1)
  jne    L252
  cmp    $0x5d,%dl
  je     L178
L252:
  add    $0x1,%rax
  cmp    %rax,%r8
  je     L390
L366:
  movzbl (%r9,%rax,1),%edx
  test   %dl,%dl
  jne    L191
L216:
  cmp    %rax,%r8
  je     L390
  cmpb   $0x0,(%r9,%rax,1)
  je     L390
L411:
  lea    0x1(%rax),%rdx
  cmp    %rdx,%r8
  ja     L75
  nop
L447:
  mov    %rdx,%rcx
  jmp    L81
  nopl   0x0(%rax,%rax,1)
L74:
  xor    %ebp,%ebp
  mov    $0xfffffffe,%eax
  jmp    L468
  nopl   0x0(%rax)
L132:
  mov    $0x2,%ecx
  jmp    L81
L178:
  cmp    %rax,%r8
  jne    L411
L390:
  mov    $0x5b,%eax
  jmp    L100
L113:
  mov    $0xfffffffc,%eax
  jmp    L100
L251:
  mov    $0xfffffffb,%eax
  jmp    L100
L350:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int pat_next(const char *pat, size_t m, size_t *step, int flags) {
  int esc = 0;
  if (!m || !*pat) {
    *step = 0;
    return 0;
  }
  *step = 1;
  if (pat[0] == '\\' && pat[1] && !(flags & FNM_NOESCAPE)) {
    *step = 2;
    pat++;
    esc = 1;
    goto escaped;
  }
  if (pat[0] == '[') {
    size_t k = 1;
    if (k < m)
      if (pat[k] == '^' || pat[k] == '!')
        k++;
    if (k < m)
      if (pat[k] == ']')
        k++;
    for (; k < m && pat[k] && pat[k] != ']'; k++) {
      if (k + 1 < m && pat[k + 1] && pat[k] == '[' && (pat[k + 1] == ':' || pat[k + 1] == '.' || pat[k + 1] == '=')) {
        int z = pat[k + 1];
        k += 2;
        if (k < m && pat[k])
          k++;
        while (k < m && pat[k] && (pat[k - 1] != z || pat[k] != ']'))
          k++;
        if (k == m || !pat[k])
          break;
      }
    }
    if (k == m || !pat[k]) {
      *step = 1;
      return '[';
    }
    *step = k + 1;
    return -3;
  }
  if (pat[0] == '*')
    return -5;
  if (pat[0] == '?')
    return -4;
escaped:
  if (pat[0] >= 128U) {
    wchar_t wc;
    int k = mbtowc(&wc, pat, m);
    if (k < 0) {
      *step = 0;
      return -2;
    }
    *step = k + esc;
    return wc;
  }
  return pat[0];
}
```