// File: /workspace/github_c_makefile_star2_O1/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 0x2cfe
movq %rax, %r15
movq %rbx, %rdi
callq 0x10e0
addl $-0x4, %eax
movslq %eax, %rdi
addq %rbx, %rdi
leaq 0x6c28(%rip), %r14      # 0xb485
movq %r14, %rsi
callq 0x1190
testl %eax, %eax
leaq 0x6c1c(%rip), %rsi      # 0xb48a
cmoveq %r14, %rsi
movq %r15, %r14
movq %rbx, %rdi
callq 0x2d58
movq %rax, %r15
movq %rax, %rdi
callq 0x10e0
testq %r15, %r15
je 0x4a64
testq %r14, %r14
je 0x4a64
movq %rax, %rbx
movq %r14, %rdi
callq 0x10d0
testq %rax, %rax
je 0x4a55
movq %rax, %r12
movq %rbx, 0x20(%rsp)
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
leaq 0x7093(%rip), %rbx      # 0xb95a
movq 0x8(%rsp), %rbp
movq %r12, %rdi
callq 0x11e0
movq %rax, %r13
movb $0x1, %r14b
testq %rax, %rax
je 0x492e
leaq 0x13(%r13), %r15
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
leaq 0x6b97(%rip), %rcx      # 0xb48a
callq 0x4215
movq %r15, %rdi
movq %rax, %rsi
callq 0x1190
testl %eax, %eax
je 0x492e
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
leaq 0x6b6e(%rip), %rcx      # 0xb485
callq 0x4215
movq %r15, %rdi
movq %rax, %rsi
callq 0x1190
testl %eax, %eax
jne 0x48cc
xorl %r14d, %r14d
testq %r13, %r13
je 0x4a1d
testb %r14b, %r14b
leaq 0x6b44(%rip), %rcx      # 0xb485
leaq 0x6b42(%rip), %rax      # 0xb48a
cmovneq %rax, %rcx
leaq 0x6b38(%rip), %rax      # 0xb48b
leaq 0x6b2c(%rip), %rbx      # 0xb486
cmovneq %rax, %rbx
leaq 0x6b29(%rip), %rsi      # 0xb48e
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rdx
callq 0x4215
movq %rax, %rdi
movq %rbx, %rsi
callq *0x18(%rsp)
movq %r12, %rdi
callq 0x1150
movq %r12, %rdi
callq 0x11e0
testq %rax, %rax
je 0x4a11
movq %rax, %rbp
movq 0x20(%rsp), %rax
movl %eax, %ebx
incl %ebx
movslq %eax, %r13
movslq %ebx, %r15
cmpb $0x2e, 0x13(%rbp)
jne 0x4a01
leaq 0x13(%rbp), %rdi
callq 0x10e0
cmpl %eax, %ebx
jge 0x4a01
addq $0x14, %rbp
cmpb $0x2e, (%rbp,%r13)
jne 0x4a01
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x1070
testl %eax, %eax
jne 0x4a01
movq %r14, %rdi
leaq 0x6b08(%rip), %rsi      # 0xb4ed
movq %rbp, %rdx
leaq 0x6f6b(%rip), %rcx      # 0xb95a
callq 0x4215
addq %r15, %rbp
movq %rax, %rdi
movq %rbp, %rsi
callq *0x18(%rsp)
movq %r12, %rdi
callq 0x11e0
movq %rax, %rbp
testq %rax, %rax
jne 0x49a8
movq %r12, %rdi
callq 0x1160
xorl %ebx, %ebx
jmp 0x4a2f
movq %r12, %rdi
callq 0x1160
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
movq %r14, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x15fc
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4a34
movq %r14, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movl $0x1, %edi
callq 0x1270