user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<pathsearch>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %edx,-0x54(%rbp)
  mov    -0x48(%rbp),%rax
  mov    $0x2f,%esi
  mov    %rax,%rdi
  call   <strrchr@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  je     L4
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  mov    %al,-0x39(%rbp)
  mov    -0x20(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %ebx,%eax
  add    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  je     L38
  mov    -0x50(%rbp),%rcx
  mov    -0x48(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  lea    D29(%rip),%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
L38:
  mov    -0x20(%rbp),%rax
  movzbl -0x39(%rbp),%edx
  mov    %dl,(%rax)
  jmp    L78
L4:
  lea    D10(%rip),%rax
  mov    %rax,%rdi
  call   <getenv@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L61
  lea    D24(%rip),%rax
  mov    %rax,-0x38(%rbp)
L61:
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x30(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %ebx,%eax
  add    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  je     L78
  cmpq   $0x0,-0x28(%rbp)
  je     L78
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x38(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  jmp    L35
L86:
  mov    -0x30(%rbp),%rax
  mov    $0x3a,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L37
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  movslq %eax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x20(%rbp)
L37:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  mov    %al,-0x39(%rbp)
  mov    -0x20(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x50(%rbp),%rcx
  mov    -0x30(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  lea    D29(%rip),%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  mov    -0x20(%rbp),%rax
  movzbl -0x39(%rbp),%edx
  mov    %dl,(%rax)
  cmpb   $0x0,-0x39(%rbp)
  jne    L73
  mov    -0x30(%rbp),%rax
  movb   $0x0,(%rax)
  jmp    L8
L73:
  mov    -0x20(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,-0x30(%rbp)
L8:
  mov    -0x54(%rbp),%edx
  mov    -0x28(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <access@plt>
  test   %rax,%rax
  je     L119
L35:
  mov    -0x30(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L86
  jmp    L112
L119:
  nop
L112:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L78:
  mov    -0x28(%rbp),%rax
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D29
type_guessed: string
name: retrieve_data
arguments: data_label: D10
type_guessed: string
name: retrieve_data
arguments: data_label: D24
type_guessed: string

tool: D29: %s/%s

tool: D10: PATH

tool: D24: .:/bin:/usr/bin

assistant: ```c
char *pathsearch(char *argv0, char *name, int modemask) {
  const char *pathlist;
  char *pathbufptr;
  char *pathbuf;
  char *path, *cp;
  char c;
  cp = strrchr(argv0, '/');
  if (cp) {
    c = *cp;
    *cp = 0;
    path = (char *)malloc(((int)strlen(argv0)) + ((int)strlen(name)) + 2);
    if (path)
      sprintf(path, "%s/%s", argv0, name);
    *cp = c;
  } else {
    pathlist = getenv("PATH");
    if (pathlist == 0)
      pathlist = ".:/bin:/usr/bin";
    pathbuf = (char *)malloc(((int)strlen(pathlist)) + 1);
    path = (char *)malloc(((int)strlen(pathlist)) + ((int)strlen(name)) + 2);
    if ((pathbuf != 0) && (path != 0)) {
      pathbufptr = pathbuf;
      strcpy(pathbuf, pathlist);
      while (*pathbuf) {
        cp = strchr(pathbuf, ':');
        if (cp == 0)
          cp = &pathbuf[((int)strlen(pathbuf))];
        c = *cp;
        *cp = 0;
        sprintf(path, "%s/%s", pathbuf, name);
        *cp = c;
        if (c == 0)
          pathbuf[0] = 0;
        else
          pathbuf = &cp[1];
        if (access(path, modemask) == 0)
          break;
      }
      free(pathbufptr);
    }
  }
  return path;
}
```