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

```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     L12
  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    L151
L179:
  mov    %r13b,(%rbx)
L13:
  add    $0x18,%rsp
  mov    %r15,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L151:
  mov    %r12,%rcx
  mov    %r14,%rdx
  lea    D7(%rip),%rsi
  mov    %rax,%rdi
  call   <lemon_sprintf@plt>
  jmp    L179
  nopw   0x0(%rax,%rax,1)
L12:
  lea    D5(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L123
  mov    %rax,%rdi
  call   <strlen@plt>
  lea    0x1(%rax),%edi
L30:
  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     L109
  test   %rax,%rax
  jne    L79
L3:
  xor    %eax,%eax
  xor    %r15d,%r15d
  call   <memory_error@plt>
  jmp    L13
  nopl   0x0(%rax)
L79:
  mov    %rbp,%rsi
  mov    0x8(%rsp),%rbp
  mov    %rbp,%rdi
  call   <lemon_strcpy@plt>
  jmp    L91
  nopw   0x0(%rax,%rax,1)
L159:
  movb   $0x0,0x0(%rbp)
L149:
  mov    %r13d,%esi
  mov    %r15,%rdi
  call   <access@plt>
  test   %rax,%rax
  je     L121
L91:
  cmpb   $0x0,0x0(%rbp)
  je     L121
  mov    $0x3a,%esi
  mov    %rbp,%rdi
  call   <strchr@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L49
L168:
  movzbl (%rbx),%r14d
  movb   $0x0,(%rbx)
  mov    %r12,%rcx
  mov    %rbp,%rdx
  lea    D7(%rip),%rsi
  mov    %r15,%rdi
  call   <lemon_sprintf@plt>
  mov    %r14b,(%rbx)
  test   %r14b,%r14b
  je     L159
  lea    0x1(%rbx),%rbp
  jmp    L149
  nopl   0x0(%rax)
L49:
  mov    %rbp,%rdi
  call   <strlen@plt>
  movslq %eax,%rbx
  add    %rbp,%rbx
  jmp    L168
  nopl   0x0(%rax,%rax,1)
L121:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  jmp    L13
  nop
L109:
  xor    %eax,%eax
  call   <memory_error@plt>
  test   %r15,%r15
  jne    L13
  jmp    L3
  nopl   (%rax)
L123:
  mov    $0x10,%edi
  lea    D35(%rip),%rbp
  jmp    L30
```

tool_calls: name: retrieve_data
arguments: data_label: D7
type_guessed: string
name: retrieve_data
arguments: data_label: D5
type_guessed: string
name: retrieve_data
arguments: data_label: D35
type_guessed: string

tool: D7: %s/%s

tool: D5: PATH

tool: D35: .:/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)
      lemon_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) {
      extern void memory_error();
      memory_error();
    };
    if ((path) == 0) {
      extern void memory_error();
      memory_error();
    };
    if ((pathbuf != 0) && (path != 0)) {
      pathbufptr = pathbuf;
      lemon_strcpy(pathbuf, pathlist);
      while (*pathbuf) {
        cp = strchr(pathbuf, ':');
        if (cp == 0)
          cp = &pathbuf[((int)strlen(pathbuf))];
        c = *cp;
        *cp = 0;
        lemon_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;
}
```