user: What is the c source code of the assembly code below?

```asm
<pathsearch>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %edx,-0x44(%rbp)
  mov    -0x38(%rbp),%rax
  mov    $0x2f,%esi
  mov    %rax,%rdi
  call   <strrchr@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  je     L49
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  mov    %al,-0x29(%rbp)
  mov    -0x18(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,%rbx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %rbx,%rax
  add    $0x2,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  je     L63
  mov    -0x40(%rbp),%rcx
  mov    -0x38(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  lea    D19(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
L63:
  mov    -0x18(%rbp),%rax
  movzbl -0x29(%rbp),%edx
  mov    %dl,(%rax)
  jmp    L109
L49:
  lea    D1(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <getenv@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L61
  lea    D58(%rip),%rax
  mov    %rax,-0x28(%rbp)
L61:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,%rbx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %rbx,%rax
  add    $0x2,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  je     L109
  jmp    L3
L111:
  mov    -0x28(%rbp),%rax
  mov    $0x3a,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L46
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    -0x28(%rbp),%rdx
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
L46:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  mov    %al,-0x29(%rbp)
  mov    -0x18(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x40(%rbp),%rcx
  mov    -0x28(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  lea    D19(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    -0x18(%rbp),%rax
  movzbl -0x29(%rbp),%edx
  mov    %dl,(%rax)
  cmpb   $0x0,-0x29(%rbp)
  jne    L94
  lea    D33(%rip),%rax
  mov    %rax,-0x28(%rbp)
  jmp    L99
L94:
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,-0x28(%rbp)
L99:
  mov    -0x44(%rbp),%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <access@plt>
  test   %eax,%eax
  je     L21
L3:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L111
  jmp    L109
L21:
  nop
L109:
  mov    -0x20(%rbp),%rax
  mov    %rax,%rsi
  lea    D40(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x20(%rbp),%rax
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: unpack_data
arguments: tag: D19
datatype: string
name: unpack_data
arguments: tag: D1
datatype: string
name: unpack_data
arguments: tag: D58
datatype: string
name: unpack_data
arguments: tag: D33
datatype: string
name: unpack_data
arguments: tag: D40
datatype: string

tool: D19: %s/%s

tool: D1: PATH

tool: D58: .:/bin:/usr/bin

tool: 

tool: D40: pathsearch %s


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