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

```asm
<pathsearch>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  mov    %edx,%r13d
  push   %r12
  mov    %rsi,%r12
  mov    $0x2f,%esi
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  call   <strrchr@plt>
  test   %rax,%rax
  je     L37
  movzbl (%rax),%r13d
  movb   $0x0,(%rax)
  mov    %r14,%rdi
  mov    %rax,%rbx
  call   <strlen@plt>
  mov    %r12,%rdi
  mov    %rax,%rbp
  call   <strlen@plt>
  lea    0x2(%rbp,%rax,1),%edi
  call   <malloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  jne    L111
L48:
  mov    %r13b,(%rbx)
L41:
  add    $0x18,%rsp
  mov    %r15,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L111:
  mov    %r12,%rcx
  mov    %r14,%rdx
  lea    D27(%rip),%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  jmp    L48
  nopw   0x0(%rax,%rax,1)
L37:
  lea    D16(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L2
  mov    %rax,%rdi
  call   <strlen@plt>
  lea    0x1(%rax),%edi
L114:
  call   <malloc@plt>
  mov    %rbp,%rdi
  mov    %rax,0x8(%rsp)
  mov    %rax,%r14
  call   <strlen@plt>
  mov    %r12,%rdi
  mov    %rax,%rbx
  call   <strlen@plt>
  lea    0x2(%rbx,%rax,1),%edi
  call   <malloc@plt>
  mov    %rax,%r15
  test   %r14,%r14
  je     L41
  test   %rax,%rax
  je     L41
  mov    %rbp,%rsi
  mov    %r14,%rdi
  mov    %r14,%rbp
  call   <strcpy@plt>
  jmp    L39
  nopl   0x0(%rax)
L52:
  movb   $0x0,0x0(%rbp)
L18:
  mov    %r13d,%esi
  mov    %r15,%rdi
  call   <access@plt>
  test   %rax,%rax
  je     L15
L39:
  cmpb   $0x0,0x0(%rbp)
  je     L15
  mov    $0x3a,%esi
  mov    %rbp,%rdi
  call   <strchr@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L45
L98:
  movzbl (%rbx),%r14d
  movb   $0x0,(%rbx)
  mov    %r12,%rcx
  mov    %rbp,%rdx
  lea    D27(%rip),%rsi
  mov    %r15,%rdi
  call   <sprintf@plt>
  mov    %r14b,(%rbx)
  test   %r14b,%r14b
  je     L52
  lea    0x1(%rbx),%rbp
  jmp    L18
  nopl   0x0(%rax)
L45:
  mov    %rbp,%rdi
  call   <strlen@plt>
  movslq %eax,%rbx
  add    %rbp,%rbx
  jmp    L98
  nopl   0x0(%rax,%rax,1)
L15:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  jmp    L41
  nop
L2:
  mov    $0x10,%edi
  lea    D37(%rip),%rbp
  jmp    L114
```

tool_calls: name: retrieve_data
arguments: data_tag: D27
type: string
name: retrieve_data
arguments: data_tag: D16
type: string
name: retrieve_data
arguments: data_tag: D37
type: string

tool: D27: %s/%s

tool: D16: PATH

tool: D37: .:/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;
}
```