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

```asm
<pathsearch>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r13
  mov    %rsi,%r12
  mov    %edx,%r14d
  mov    $0x2f,%esi
  call   <strrchr@plt>
  test   %rax,%rax
  je     L154
  mov    %rax,%rbx
  movzbl (%rax),%r14d
  movb   $0x0,(%rax)
  mov    %r13,%rdi
  call   <strlen@plt>
  mov    %rax,%rbp
  mov    %r12,%rdi
  call   <strlen@plt>
  lea    0x2(%rbp,%rax,1),%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L45
L4:
  mov    %r14b,(%rbx)
L76:
  mov    %rbp,%rax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L45:
  mov    %r12,%rcx
  mov    %r13,%rdx
  lea    D35(%rip),%rsi
  mov    %rax,%rdi
  call   <lemon_sprintf@plt>
  jmp    L4
L154:
  lea    D31(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  lea    D28(%rip),%rax
  cmove  %rax,%rbx
  mov    %rbx,%rdi
  call   <strlen@plt>
  lea    0x1(%rax),%edi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    %rax,0x8(%rsp)
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    %rax,%rbp
  mov    %r12,%rdi
  call   <strlen@plt>
  lea    0x2(%rbp,%rax,1),%edi
  call   <malloc@plt>
  mov    %rax,%r13
  mov    %rax,%rbp
  test   %r15,%r15
  je     L143
  test   %rax,%rax
  jne    L35
L101:
  mov    $0x0,%eax
  call   <memory_error@plt>
  jmp    L76
L143:
  mov    $0x0,%eax
  call   <memory_error@plt>
  test   %r13,%r13
  jne    L76
  jmp    L101
L133:
  mov    %r13,%rdi
  call   <strlen@plt>
  movslq %eax,%rbx
  add    %r13,%rbx
  jmp    L87
L10:
  lea    0x1(%rbx),%r13
L97:
  mov    %r14d,%esi
  mov    %rbp,%rdi
  call   <access@plt>
  test   %rax,%rax
  je     L9
L67:
  cmpb   $0x0,0x0(%r13)
  je     L9
  mov    $0x3a,%esi
  mov    %r13,%rdi
  call   <strchr@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L133
L87:
  movzbl (%rbx),%r15d
  movb   $0x0,(%rbx)
  mov    %r12,%rcx
  mov    %r13,%rdx
  lea    D35(%rip),%rsi
  mov    %rbp,%rdi
  call   <lemon_sprintf@plt>
  mov    %r15b,(%rbx)
  test   %r15b,%r15b
  jne    L10
  movb   $0x0,0x0(%r13)
  jmp    L97
L9:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  jmp    L76
L35:
  mov    %rbx,%rsi
  mov    0x8(%rsp),%r13
  mov    %r13,%rdi
  call   <lemon_strcpy@plt>
  jmp    L67
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D35
type_infered: string
name: extract_symbolic_data
arguments: data_tag: D31
type_infered: string
name: extract_symbolic_data
arguments: data_tag: D28
type_infered: string

tool: D35: %s/%s

tool: D31: PATH

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