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

```asm
<which>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  mov    -0x58(%rbp),%rax
  mov    $0x2f,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  je     L135
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <is_there@plt>
  test   %rax,%rax
  je     L135
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
  jmp    L121
L135:
  lea    D21(%rip),%rax
  mov    %rax,%rdi
  call   <getenv@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L26
  mov    $0x0,%eax
  jmp    L121
L26:
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
  mov    %rax,-0x48(%rbp)
  mov    -0x48(%rbp),%rax
  mov    %rax,-0x30(%rbp)
  mov    -0x48(%rbp),%rax
  test   %rax,%rax
  jne    L41
  mov    $0x0,%eax
  jmp    L121
L41:
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %ebx,%eax
  add    $0x2,%eax
  cltq
  mov    %rax,-0x28(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L11
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
  jmp    L121
L91:
  mov    -0x40(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L9
  lea    D15(%rip),%rax
  mov    %rax,-0x40(%rbp)
L9:
  mov    -0x58(%rbp),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0x28(%rbp),%rsi
  mov    -0x20(%rbp),%rax
  mov    %rcx,%r8
  mov    %rdx,%rcx
  lea    D10(%rip),%rdx
  mov    %rax,%rdi
  call   <snprintf@plt>
  mov    -0x28(%rbp),%rdx
  cmp    %edx,%eax
  jl     L136
  jmp    L11
L136:
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <is_there@plt>
  test   %rax,%rax
  je     L11
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x20(%rbp),%rax
  jmp    L121
L11:
  lea    -0x48(%rbp),%rax
  lea    D38(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strsep@plt>
  mov    %rax,-0x40(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L91
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
L121:
  mov    -0x18(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L126
  call   <__stack_chk_fail@plt>
L126:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D21
type_infered: string
name: extract_symbolic_data
arguments: data_label: D15
type_infered: string
name: extract_symbolic_data
arguments: data_label: D10
type_infered: string
name: extract_symbolic_data
arguments: data_label: D38
type_infered: string

tool: D21: PATH

tool: D15: .

tool: D10: %s/%s

tool: D38: :

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);
}
```