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

```asm
<which>:
  endbr64
  push   %r15
  mov    $0x2f,%esi
  push   %r14
  push   %r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <strchr@plt>
  test   %rax,%rax
  je     L5
  mov    %r12,%rdi
  call   <is_there@plt>
  test   %rax,%rax
  jne    L127
L5:
  lea    D3(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rdi
  test   %rax,%rax
  je     L44
  call   <strdup@plt>
  mov    %rax,0x8(%rsp)
  mov    %rax,0x10(%rsp)
  test   %rax,%rax
  je     L44
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %r12,%rdi
  mov    %eax,%ebx
  call   <strlen@plt>
  lea    0x2(%rbx,%rax,1),%eax
  movslq %eax,%rbx
  mov    %eax,(%rsp)
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L4
  lea    0x10(%rsp),%r14
  lea    D34(%rip),%r13
  lea    D38(%rip),%r15
  nopl   0x0(%rax,%rax,1)
L90:
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <strsep@plt>
  mov    %rax,%rcx
  test   %rax,%rax
  je     L73
  cmpb   $0x0,(%rcx)
  mov    %r12,%r8
  jne    L123
  lea    D12(%rip),%rcx
L123:
  mov    %r15,%rdx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <snprintf@plt>
  cmp    %eax,(%rsp)
  jle    L90
  mov    %rbp,%rdi
  call   <is_there@plt>
  test   %rax,%rax
  je     L90
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    %rbp,%rcx
L24:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L129
  add    $0x28,%rsp
  mov    %rcx,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L73:
  mov    0x10(%rsp),%rdi
  mov    %rax,(%rsp)
  call   <free@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  mov    (%rsp),%rcx
  jmp    L24
  nopl   0x0(%rax)
L127:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L129
  add    $0x28,%rsp
  mov    %r12,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1170 <strdup@plt>
L4:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  nopl   0x0(%rax,%rax,1)
L44:
  xor    %ecx,%ecx
  jmp    L24
L129:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_tag: D3
type_infered: string
name: unpack_data
arguments: data_tag: D34
type_infered: string
name: unpack_data
arguments: data_tag: D38
type_infered: string
name: unpack_data
arguments: data_tag: D12
type_infered: string

tool: D3: PATH

tool: D34: :

tool: D38: %s/%s

tool: D12: .

assistant: ```c
char *which(char *filename) {
  size_t max_candidate;
  char *candidate, *path, *spath;
  const char *d, *p;
  if (strchr(filename, '/') != NULL && is_there(filename))
    return (strdup(filename));
  if ((p = getenv("PATH")) == NULL)
    return (NULL);
  spath = path = strdup(p);
  if (path == NULL)
    return (NULL);
  max_candidate = strlen(path) + strlen(filename) + 2;
  if ((candidate = malloc(max_candidate)) == NULL) {
    free(spath);
    return NULL;
  }
  while ((d = strsep(&path, ":")) != NULL) {
    if (*d == '\0')
      d = ".";
    if (snprintf(candidate, max_candidate, "%s/%s", d, filename) >= (int)max_candidate)
      continue;
    if (is_there(candidate)) {
      free(spath);
      return (candidate);
    }
  }
  free(path);
  free(candidate);
  return (NULL);
}
```