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     L270
  cmpb   $0x0,(%rdi)
  mov    %rdi,%r9
  je     L270
  movq   $0x1,(%rdx)
  movsbl (%rdi),%eax
  mov    %rsi,%r8
  cmp    $0x5c,%al
  je     L187
  cmp    $0x5b,%al
  je     L59
  cmp    $0x2a,%al
  je     L173
  cmp    $0x3f,%al
  je     L472
  xor    %ebp,%ebp
L47:
  test   %al,%al
  jns    L253
  lea    0x4(%rsp),%rdi
  mov    %r8,%rdx
  mov    %r9,%rsi
  call   <mbtowc@plt>
  test   %eax,%eax
  js     L204
  add    %eax,%ebp
  mov    0x4(%rsp),%eax
  movslq %ebp,%rbp
  mov    %rbp,(%rbx)
  jmp    L253
  nop
L270:
  movq   $0x0,(%rbx)
  xor    %eax,%eax
L253:
  mov    0x8(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L380
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  ret
  nopl   0x0(%rax)
L59:
  mov    $0x5b,%eax
  cmp    $0x1,%rsi
  je     L253
  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    L233
  movzbl 0x1(%rdi,%rcx,1),%eax
  cmp    $0x5d,%al
  je     L278
L18:
  movabs $0x2400400000000000,%rdi
  cs nopw 0x0(%rax,%rax,1)
L107:
  cmp    $0x5d,%al
  je     L256
  test   %al,%al
  je     L256
  lea    0x1(%rdx),%rcx
  cmp    %r8,%rcx
  jb     L409
L219:
  mov    $0x5b,%eax
  cmp    %r8,%rcx
  je     L253
  cmpb   $0x0,(%r9,%rcx,1)
  je     L253
  add    $0x1,%rcx
  mov    $0xfffffffd,%eax
  mov    %rcx,(%rbx)
  jmp    L253
  nopl   0x0(%rax,%rax,1)
L278:
  lea    0x2(%rcx),%rdx
  cmp    %rdx,%rsi
  jbe    L256
  movzbl 0x2(%rdi,%rcx,1),%eax
  jmp    L18
  nopl   0x0(%rax)
L409:
  movzbl 0x1(%r9,%rdx,1),%esi
  cmp    $0x5b,%al
  jne    L309
  test   %sil,%sil
  jne    L192
L309:
  mov    %esi,%eax
  mov    %rcx,%rdx
  jmp    L107
  cs nopw 0x0(%rax,%rax,1)
L192:
  cmp    $0x3d,%sil
  ja     L122
  bt     %rsi,%rdi
  jb     L97
L122:
  mov    %rcx,%rdx
L128:
  movzbl (%r9,%rdx,1),%eax
  jmp    L107
  nopl   0x0(%rax)
L187:
  cmpb   $0x0,0x1(%rdi)
  je     L253
  mov    D3(%rip),%rdx
  and    (%rdx),%ecx
  jne    L253
  movq   $0x2,(%rbx)
  add    $0x1,%r9
  movsbl 0x1(%rdi),%eax
  mov    $0x1,%ebp
  jmp    L47
  nopw   0x0(%rax,%rax,1)
L97:
  lea    0x2(%rdx),%rax
  cmp    %rax,%r8
  jbe    L70
  cmpb   $0x0,0x2(%r9,%rdx,1)
  je     L211
  lea    0x3(%rdx),%rax
  cmp    %rax,%r8
  ja     L211
  jmp    L70
  nopl   0x0(%rax)
L221:
  cmp    %sil,-0x1(%r9,%rax,1)
  jne    L136
  cmp    $0x5d,%dl
  je     L478
L136:
  add    $0x1,%rax
  cmp    %rax,%r8
  je     L242
L211:
  movzbl (%r9,%rax,1),%edx
  test   %dl,%dl
  jne    L221
L70:
  cmp    %rax,%r8
  je     L242
  cmpb   $0x0,(%r9,%rax,1)
  je     L242
L433:
  lea    0x1(%rax),%rdx
  cmp    %rdx,%r8
  ja     L128
  nop
L256:
  mov    %rdx,%rcx
  jmp    L219
  nopl   0x0(%rax,%rax,1)
L204:
  movq   $0x0,(%rbx)
  mov    $0xfffffffe,%eax
  jmp    L253
  nopl   0x0(%rax)
L233:
  mov    $0x2,%ecx
  jmp    L219
L478:
  cmp    %rax,%r8
  jne    L433
L242:
  mov    $0x5b,%eax
  jmp    L253
L472:
  mov    $0xfffffffc,%eax
  jmp    L253
L173:
  mov    $0xfffffffb,%eax
  jmp    L253
L380:
  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];
}
```