// File: /workspace/github_c_makefile_star2_O0/mmayer[P]pcal/src/pcalutil.c
// Function: find_executable
char *find_executable (char *prog)
{
   char *pathvar, *p, *pnext;
   struct stat st;
   static char filepath[STRSIZ];
   
   /* if 'prog' is an absolute/relative path name or environment variable
      'PATH' does not exist, return 'prog'; otherwise, search the directories
      specified in 'PATH' for the executable
   */
   if (strchr(prog, END_PATH) == 0 && (p = getenv(PATH_ENV_VAR)) != 0) {
      pathvar = alloc(strlen(p) + 1);
      strcpy(pathvar, p);

      /* assumes PATH is of form "dir1:dir2:...:dirN"; strtok() would be handy
         here, but not everybody has it yet
      */
      for (p = pathvar; *p; p = pnext) {
         if ((pnext = strchr(p, ':')) != NULL) *pnext++ = '\0';
         else pnext = p + strlen(p);

         /* assume the executable lives in the path, and construct its
            complete file name
         */
         filepath[0] = '\0';
         if (strcmp(p, ".") != 0) {
            strcat(filepath, p);
            strcat(filepath, "/");
         }
         strcat(filepath, prog);
         
         /* check that file a) exists, b) is a "normal" file, and c) is
            executable - if so, return its full path
          */
         if (stat(filepath, &st) >= 0 &&
             (st.st_mode & S_IFMT) == S_IFREG &&
             access(filepath, X_OK) == 0) {
            free(pathvar);
            return filepath;
         }
      }
      free(pathvar);
   }
   
   return prog;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2f, %esi
callq 0x5100
cmpq $0x0, %rax
jne 0xd939
leaq 0x16e8d(%rip), %rdi     # 0x2466b
callq 0x5030
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0xd939
movq -0x20(%rbp), %rdi
callq 0x50e0
addq $0x1, %rax
movl %eax, %edi
callq 0xb2b0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x5080
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0xd930
movq -0x20(%rbp), %rdi
movl $0x3a, %esi
callq 0x5100
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0xd857
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb $0x0, (%rax)
jmp 0xd87c
movq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x50e0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movb $0x0, 0x25f2d(%rip)     # 0x337b0
movq -0x20(%rbp), %rdi
leaq 0xe83f(%rip), %rsi      # 0x1c0cd
callq 0x51a0
cmpl $0x0, %eax
je 0xd8bb
movq -0x20(%rbp), %rsi
leaq 0x25f0d(%rip), %rdi     # 0x337b0
callq 0x5290
leaq 0x25f01(%rip), %rdi     # 0x337b0
leaq 0x16db3(%rip), %rsi     # 0x24669
callq 0x5290
movq -0x10(%rbp), %rsi
leaq 0x25eea(%rip), %rdi     # 0x337b0
callq 0x5290
leaq 0x25ede(%rip), %rdi     # 0x337b0
leaq -0xb8(%rbp), %rsi
callq 0x51c0
cmpl $0x0, %eax
jl 0xd921
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0xd921
leaq 0x25eb4(%rip), %rdi     # 0x337b0
movl $0x1, %esi
callq 0x5230
cmpl $0x0, %eax
jne 0xd921
movq -0x18(%rbp), %rdi
callq 0x5040
leaq 0x25e95(%rip), %rax     # 0x337b0
movq %rax, -0x8(%rbp)
jmp 0xd941
jmp 0xd923
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xd81e
movq -0x18(%rbp), %rdi
callq 0x5040
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nop