user: Converte this assembly snippet into its equivalent C code:

```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     L15
  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     L42
  mov    -0x40(%rbp),%rcx
  mov    -0x38(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  lea    D15(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
L42:
  mov    -0x18(%rbp),%rax
  movzbl -0x29(%rbp),%edx
  mov    %dl,(%rax)
  jmp    L12
L15:
  lea    D49(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <getenv@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L114
  lea    D9(%rip),%rax
  mov    %rax,-0x28(%rbp)
L114:
  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     L12
  jmp    L36
L32:
  mov    -0x28(%rbp),%rax
  mov    $0x3a,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L81
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    -0x28(%rbp),%rdx
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
L81:
  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    D15(%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    L59
  lea    D44(%rip),%rax
  mov    %rax,-0x28(%rbp)
  jmp    L104
L59:
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,-0x28(%rbp)
L104:
  mov    -0x44(%rbp),%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <access@plt>
  test   %eax,%eax
  je     L49
L36:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L32
  jmp    L12
L49:
  nop
L12:
  mov    -0x20(%rbp),%rax
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: label: D15
data_type: string
name: retrieve_data
arguments: label: D49
data_type: string
name: retrieve_data
arguments: label: D9
data_type: string
name: retrieve_data
arguments: label: D44
data_type: string

tool: D15: %s/%s

tool: D49: PATH

tool: D9: .:/bin:/usr/bin

tool: 

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;
      }
    }
  }
  return path;
}
```