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

```asm
<pathsearch>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%r14
  mov    %edx,0xc(%rsp)
  mov    $0x2f,%esi
  call   <strrchr@plt>
  test   %rax,%rax
  je     L70
  mov    %rax,%rbx
  movzbl (%rax),%r13d
  movb   $0x0,(%rax)
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %rax,%r12
  mov    %r14,%rdi
  call   <strlen@plt>
  lea    0x2(%r12,%rax,1),%edi
  movslq %edi,%rdi
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L1
  mov    %r14,%rcx
  mov    %rbp,%rdx
  lea    D7(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
L1:
  mov    %r13b,(%rbx)
L46:
  mov    %r12,%rax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L70:
  lea    D3(%rip),%rdi
  mov    $0x0,%eax
  call   <getenv@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  lea    D37(%rip),%rax
  cmove  %rax,%rbp
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %rax,%rbx
  mov    %r14,%rdi
  call   <strlen@plt>
  lea    0x2(%rbx,%rax,1),%edi
  movslq %edi,%rdi
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L46
  lea    D42(%rip),%r15
  jmp    L54
L49:
  mov    %rbp,%rdi
  call   <strlen@plt>
  movslq %eax,%rbx
  add    %rbp,%rbx
L8:
  movzbl (%rbx),%r13d
  movb   $0x0,(%rbx)
  mov    %r14,%rcx
  mov    %rbp,%rdx
  lea    D7(%rip),%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    %r13b,(%rbx)
  add    $0x1,%rbx
  test   %r13b,%r13b
  cmove  %r15,%rbx
  mov    %rbx,%rbp
  mov    0xc(%rsp),%esi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <access@plt>
  test   %eax,%eax
  je     L46
L54:
  cmpb   $0x0,0x0(%rbp)
  je     L46
  mov    $0x3a,%esi
  mov    %rbp,%rdi
  call   <strchr@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  jne    L8
  jmp    L49
```

tool_calls: name: unpack_data
arguments: label: D7
type_guessed: string
name: unpack_data
arguments: label: D3
type_guessed: string
name: unpack_data
arguments: label: D37
type_guessed: string
name: unpack_data
arguments: label: D42
type_guessed: string

tool: D7: %s/%s

tool: D3: PATH

tool: D37: .:/bin:/usr/bin

tool: 

assistant: ```c
char *pathsearch(argv0, name, modemask)
char *argv0;
char *name;
int modemask;
{
  char *pathlist;
  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 {
    extern char *getenv();
    pathlist = getenv("PATH");
    if (pathlist == 0)
      pathlist = ".:/bin:/usr/bin";
    path = (char *)malloc(((int)strlen(pathlist)) + ((int)strlen(name)) + 2);
    if (path != 0) {
      while (*pathlist) {
        cp = strchr(pathlist, ':');
        if (cp == 0)
          cp = &pathlist[((int)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;
}
```