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

```asm
<expath>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x68,%rsp
  mov    $0x7e,%ecx
  pxor   %xmm0,%xmm0
  mov    %rsi,0x30(%rsp)
  mov    %rdi,%rbp
  lea    0x460(%rsp),%rdi
  lea    D32(%rip),%rsi
  mov    %edx,0x3c(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x1058(%rsp)
  xor    %eax,%eax
  movaps %xmm0,0x450(%rsp)
  rep stos %rax,%es:(%rdi)
  mov    %edx,%ecx
  mov    $0x3,%edi
  mov    %rbp,%rdx
  call   <trace@plt>
  mov    $0x2f,%esi
  mov    %rbp,%rdi
  call   <strrchr@plt>
  test   %rax,%rax
  je     L25
L188:
  lea    0x1(%rax),%rcx
  sub    %rbp,%rax
  lea    0x450(%rsp),%rdi
  mov    %rbp,%rsi
  mov    %rax,%rbx
  lea    0x1(%rax),%edx
  mov    %rcx,0x28(%rsp)
  call   <strncpy@plt>
  movb   $0x0,0x451(%rsp,%rbx,1)
L214:
  cmpb   $0x0,0x450(%rsp)
  lea    D9(%rip),%rax
  lea    0x450(%rsp),%rdi
  cmove  %rax,%rdi
  call   <opendir@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L235
  movq   $0x0,0x20(%rsp)
  lea    D16(%rip),%r12
L59:
  mov    0x20(%rsp),%rax
  mov    %eax,0x38(%rsp)
  mov    %eax,0xc(%rsp)
  lea    0x850(%rsp),%rax
  mov    %rax,0x18(%rsp)
  lea    0xc50(%rsp),%rax
  mov    %rax,0x10(%rsp)
L221:
  mov    %r13,%rdi
  call   <readdir@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L146
  mov    (%rbx),%rdx
  cmpb   $0x2e,(%rdx)
  je     L221
  mov    0x18(%rsp),%rbp
  lea    D12(%rip),%rsi
  xor    %eax,%eax
  mov    %rbp,%rdi
  call   <sprintf@plt>
  mov    0x28(%rsp),%rdx
  mov    0x10(%rsp),%rdi
  xor    %eax,%eax
  lea    D12(%rip),%rsi
  call   <sprintf@plt>
  movzbl 0x850(%rsp),%eax
  test   %al,%al
  je     L50
  nopl   0x0(%rax,%rax,1)
L115:
  movsbl %al,%edi
  add    $0x1,%rbp
  call   <tolower@plt>
  mov    %al,-0x1(%rbp)
  movzbl 0x0(%rbp),%eax
  test   %al,%al
  jne    L115
L50:
  movzbl 0xc50(%rsp),%eax
  mov    0x10(%rsp),%rbp
  test   %al,%al
  je     L174
  nopl   0x0(%rax,%rax,1)
L153:
  movsbl %al,%edi
  add    $0x1,%rbp
  call   <tolower@plt>
  mov    %al,-0x1(%rbp)
  movzbl 0x0(%rbp),%eax
  test   %al,%al
  jne    L153
L174:
  mov    0x10(%rsp),%rdi
  lea    0x48(%rsp),%rbp
  mov    %r12,%rsi
  mov    %rbp,%rdx
  call   <strtok_r@plt>
  mov    0x18(%rsp),%r15
  mov    %rax,%r14
  test   %rax,%rax
  je     L78
  nopl   0x0(%rax)
L223:
  mov    %r15,%rdi
  mov    %r14,%rsi
  call   <strstr@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L221
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %rbp,%rdx
  mov    %r12,%rsi
  xor    %edi,%edi
  cltq
  add    %rax,%r15
  call   <strtok_r@plt>
  mov    %rax,%r14
  test   %rax,%rax
  jne    L223
L78:
  mov    0x20(%rsp),%ecx
  cmp    %ecx,0x3c(%rsp)
  jle    L221
  mov    0x30(%rsp),%rax
  mov    0x20(%rsp),%r15
  lea    0x450(%rsp),%rdx
  lea    D7(%rip),%rsi
  mov    (%rbx),%rcx
  mov    (%rax,%r15,8),%rdi
  xor    %eax,%eax
  add    $0x1,%r15
  call   <sprintf@plt>
  mov    %r15,0x20(%rsp)
  jmp    L59
  nopl   0x0(%rax)
L146:
  mov    %r13,%rdi
  call   <closedir@plt>
  cmpl   $0x1,0xc(%rsp)
  jle    L135
  mov    0x38(%rsp),%edx
  mov    0x30(%rsp),%rcx
  mov    $0x1,%r13d
  lea    0x50(%rsp),%r12
  lea    -0x2(%rdx),%eax
  lea    0x8(%rcx),%r14
  add    $0x2,%rax
  lea    -0x1(%rdx),%r15d
  mov    %rax,0x10(%rsp)
  lea    0x10(%rcx),%rax
  mov    %rax,0x18(%rsp)
  nopl   0x0(%rax)
L108:
  cmp    %r13d,0xc(%rsp)
  jle    L5
  mov    %r15d,%eax
  mov    0x18(%rsp),%rcx
  mov    %r14,%rbx
  sub    %r13d,%eax
  lea    -0x1(%r13,%rax,1),%rax
  lea    (%rcx,%rax,8),%rbp
  cs nopw 0x0(%rax,%rax,1)
L57:
  mov    -0x8(%r14),%rdi
  mov    (%rbx),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jle    L161
  mov    -0x8(%r14),%rsi
  mov    %r12,%rdi
  call   <strcpy@plt>
  mov    -0x8(%r14),%rdi
  mov    (%rbx),%rsi
  call   <strcpy@plt>
  mov    (%rbx),%rdi
  mov    %r12,%rsi
  call   <strcpy@plt>
L161:
  add    $0x8,%rbx
  cmp    %rbp,%rbx
  jne    L57
L5:
  add    $0x1,%r13
  add    $0x8,%r14
  cmp    0x10(%rsp),%r13
  jne    L108
L135:
  mov    0xc(%rsp),%eax
  test   %eax,%eax
  je     L226
  mov    0x38(%rsp),%eax
  mov    0x30(%rsp),%rbx
  lea    D64(%rip),%rbp
  sub    $0x1,%eax
  lea    0x8(%rbx,%rax,8),%r12
  nopl   0x0(%rax)
L101:
  mov    (%rbx),%rdx
  mov    %rbp,%rsi
  mov    $0x3,%edi
  xor    %eax,%eax
  add    $0x8,%rbx
  call   <trace@plt>
  cmp    %rbx,%r12
  jne    L101
L226:
  mov    0x1058(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L143
  mov    0xc(%rsp),%eax
  add    $0x1068,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L25:
  mov    $0x5c,%esi
  mov    %rbp,%rdi
  call   <strrchr@plt>
  mov    %rbp,0x28(%rsp)
  test   %rax,%rax
  jne    L188
  jmp    L214
L235:
  movl   $0x0,0xc(%rsp)
  jmp    L226
L143:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D32
data_type: string
name: unpack_data
arguments: tag: D9
data_type: string
name: unpack_data
arguments: tag: D16
data_type: string
name: unpack_data
arguments: tag: D12
data_type: string
name: unpack_data
arguments: tag: D7
data_type: string
name: unpack_data
arguments: tag: D64
data_type: string

tool: D32: expath  : path=%s nmax=%d


tool: D9: .

tool: D16: *

tool: D12: ^%s$

tool: D7: %s%s

tool: D64: expath  : file=%s


assistant: ```c
extern int expath(const char *path, char *paths[], int nmax) {
  int i, j, n = 0;
  char tmp[1024];
  struct dirent *d;
  DIR *dp;
  const char *file = path;
  char dir[1024] = "", s1[1024], s2[1024], *p, *q, *r;
  trace(3, "expath  : path=%s nmax=%d\n", path, nmax);
  if ((p = strrchr(path, '/')) || (p = strrchr(path, '\\'))) {
    file = p + 1;
    strncpy(dir, path, p - path + 1);
    dir[p - path + 1] = '\0';
  }
  if (!(dp = opendir(*dir ? dir : ".")))
    return 0;
  while ((d = readdir(dp))) {
    if (*(d->d_name) == '.')
      continue;
    sprintf(s1, "^%s$", d->d_name);
    sprintf(s2, "^%s$", file);
    for (p = s1; *p; p++)
      *p = (char)tolower((int)*p);
    for (p = s2; *p; p++)
      *p = (char)tolower((int)*p);
    for (p = s1, q = strtok_r(s2, "*", &r); q; q = strtok_r(NULL, "*", &r)) {
      if ((p = strstr(p, q)))
        p += strlen(q);
      else
        break;
    }
    if (p && n < nmax)
      sprintf(paths[n++], "%s%s", dir, d->d_name);
  }
  closedir(dp);
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (strcmp(paths[i], paths[j]) > 0) {
        strcpy(tmp, paths[i]);
        strcpy(paths[i], paths[j]);
        strcpy(paths[j], tmp);
      }
    }
  }
  for (i = 0; i < n; i++)
    trace(3, "expath  : file=%s\n", paths[i]);
  return n;
}
```