// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/DB.c
// Function: List_DB_Files
int List_DB_Files(char *path, void actor(char *path, char *extension))
{ int            status, plen, rlen, dlen;
  char          *root, *pwd, *name;
  int            isdam;
  DIR           *dirp;
  struct dirent *dp;

  status = 0;
  pwd    = PathTo(path);
  plen   = strlen(path);
  if (strcmp(path+(plen-4),".dam") == 0)
    root = Root(path,".dam");
  else
    root = Root(path,".db");
  rlen = strlen(root);

  if (root == NULL || pwd == NULL)
    { free(pwd);
      free(root);
      EXIT(1);
    }

  if ((dirp = opendir(pwd)) == NULL)
    { EPRINTF(EPLACE,"%s: Cannot open directory %s (List_DB_Files)\n",Prog_Name,pwd);
      status = -1;
      goto error;
    }

  isdam = 0;
  while ((dp = readdir(dirp)) != NULL)     //   Get case dependent root name (if necessary)
    { name = dp->d_name;
      if (strcmp(name,MyCatenate("","",root,".db")) == 0)
        break;
      if (strcmp(name,MyCatenate("","",root,".dam")) == 0)
        { isdam = 1;
          break;
        }
    }
  if (dp == NULL)
    { status = -1;
      closedir(dirp);
      goto error;
    }

  if (isdam)
    actor(MyCatenate(pwd,"/",root,".dam"),"dam");
  else
    actor(MyCatenate(pwd,"/",root,".db"),"db");

  rewinddir(dirp);                         //   Report each auxiliary file
  while ((dp = readdir(dirp)) != NULL)
    { name = dp->d_name;
      dlen = strlen(name);
#ifdef HIDE_FILES
      if (name[0] != '.')
        continue;
      dlen -= 1;
      name += 1;
#endif
      if (dlen < rlen+1)
        continue;
      if (name[rlen] != '.')
        continue;
      if (strncmp(name,root,rlen) != 0)
        continue;
      actor(MyCatenate(pwd,PATHSEP,name,""),name+(rlen+1));
    }
  closedir(dirp);

error:
  free(pwd);
  free(root);
  return (status);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
callq 0x1d2b
movq %rax, %r13
movq %rbx, %rdi
callq 0x10e0
addl $-0x4, %eax
movslq %eax, %rdi
addq %rbx, %rdi
leaq 0x5c69(%rip), %r15      # 0x9485
movq %r15, %rsi
callq 0x1190
testl %eax, %eax
leaq 0x5c5d(%rip), %rbp      # 0x948a
movq %rbp, %rsi
cmoveq %r15, %rsi
movq %rbx, %rdi
callq 0x1d83
movq %rax, %r14
movq %rax, %rdi
callq 0x10e0
testq %r14, %r14
je 0x39fa
testq %r13, %r13
je 0x39fa
movq %rax, %rbx
movq %r13, %rdi
callq 0x10d0
testq %rax, %rax
je 0x39d3
movq %rax, %r12
movq %r13, 0x8(%rsp)
movq %rbx, %rax
movq %rbx, 0x20(%rsp)
movl %eax, 0x14(%rsp)
leaq 0x60d2(%rip), %r13      # 0x995a
movq %r12, %rdi
callq 0x11e0
testq %rax, %rax
je 0x38e8
movq %rax, %rbx
addq $0x13, %rbx
movq %r13, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x31cf
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1190
testl %eax, %eax
je 0x38f8
movq %r13, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x31cf
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1190
testl %eax, %eax
jne 0x3888
movq %r15, %rbp
leaq 0x5ba0(%rip), %rbx      # 0x9486
jmp 0x38ff
movq %r12, %rdi
callq 0x1160
pushq $-0x1
popq %rbx
jmp 0x39ad
leaq 0x5b8c(%rip), %rbx      # 0x948b
leaq 0x5b88(%rip), %rsi      # 0x948e
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x31cf
movq %rax, %rdi
movq %rbx, %rsi
callq *0x18(%rsp)
movq %r12, %rdi
callq 0x1150
movl 0x14(%rsp), %eax
incl %eax
movslq 0x20(%rsp), %r15
movl %eax, %ebp
movslq %eax, %rbx
movq %r12, %rdi
callq 0x11e0
testq %rax, %rax
je 0x39a3
movq %rax, %r13
cmpb $0x2e, 0x13(%rax)
jne 0x3938
leaq 0x13(%r13), %rdi
callq 0x10e0
cmpl %eax, %ebp
jge 0x3938
addq $0x14, %r13
cmpb $0x2e, (%r13,%r15)
jne 0x3938
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1070
testl %eax, %eax
jne 0x3938
movq 0x8(%rsp), %rdi
leaq 0x5b68(%rip), %rsi      # 0x94ed
movq %r13, %rdx
leaq 0x5fcb(%rip), %rcx      # 0x995a
callq 0x31cf
addq %rbx, %r13
movq %rax, %rdi
movq %r13, %rsi
callq *0x18(%rsp)
jmp 0x3938
movq %r12, %rdi
callq 0x1160
xorl %ebx, %ebx
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa61e(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xcf04(%rip), %rdx      # 0x108e8
leaq 0x5c1e(%rip), %rsi      # 0x9609
movq %r13, %rcx
xorl %eax, %eax
callq 0x11a0
pushq $-0x1
popq %rbx
jmp 0x39b2
movq %r13, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
pushq $0x1
popq %rdi
callq 0x1270