// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
callq 0x2c75
movq %rax, %r13
movq %rbx, %rdi
callq 0x10e0
addl $-0x4, %eax
movslq %eax, %rdi
addq %rbx, %rdi
leaq 0x6c04(%rip), %r15      # 0xb4e5
movq %r15, %rsi
callq 0x1190
testl %eax, %eax
leaq 0x6bf8(%rip), %rbp      # 0xb4ea
movq %rbp, %rsi
cmoveq %r15, %rsi
movq %rbx, %rdi
callq 0x2ccf
movq %rax, %r14
movq %rax, %rdi
callq 0x10e0
movq %rax, 0x10(%rsp)
testq %r14, %r14
je 0x4aa8
testq %r13, %r13
je 0x4aa8
movq %r13, %rdi
callq 0x10d0
testq %rax, %rax
je 0x4a99
movq %rax, %r12
movq %r13, (%rsp)
leaq 0x7078(%rip), %rbx      # 0xb9ba
movq %r12, %rdi
callq 0x11e0
testq %rax, %rax
je 0x49a2
movq %rax, %r13
addq $0x13, %r13
movq %rbx, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x427d
movq %r13, %rdi
movq %rax, %rsi
callq 0x1190
testl %eax, %eax
je 0x49b4
movq %rbx, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x427d
movq %r13, %rdi
movq %rax, %rsi
callq 0x1190
testl %eax, %eax
jne 0x4942
movq %r15, %rbp
leaq 0x6b46(%rip), %rbx      # 0xb4e6
jmp 0x49bb
movq %r12, %rdi
callq 0x1160
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4a74
leaq 0x6b30(%rip), %rbx      # 0xb4eb
leaq 0x6b2c(%rip), %rsi      # 0xb4ee
movq (%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x427d
movq %rax, %rdi
movq %rbx, %rsi
callq *0x8(%rsp)
movq %r12, %rdi
callq 0x1150
movq %r12, %rdi
callq 0x11e0
testq %rax, %rax
je 0x4a6a
movq %rax, %r15
movq 0x10(%rsp), %rax
movl %eax, %ebx
incl %ebx
movslq %eax, %r13
movslq %ebx, %rbp
cmpb $0x2e, 0x13(%r15)
jne 0x4a5a
leaq 0x13(%r15), %rdi
callq 0x10e0
cmpl %eax, %ebx
jge 0x4a5a
addq $0x14, %r15
cmpb $0x2e, (%r15,%r13)
jne 0x4a5a
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1070
testl %eax, %eax
jne 0x4a5a
movq (%rsp), %rdi
leaq 0x6b0f(%rip), %rsi      # 0xb54d
movq %r15, %rdx
leaq 0x6f72(%rip), %rcx      # 0xb9ba
callq 0x427d
addq %rbp, %r15
movq %rax, %rdi
movq %r15, %rsi
callq *0x8(%rsp)
movq %r12, %rdi
callq 0x11e0
movq %rax, %r15
testq %rax, %rax
jne 0x4a02
movq %r12, %rdi
callq 0x1160
xorl %ebx, %ebx
movq (%rsp), %r13
movq %r13, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x15fc
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4a78
movq %r13, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movl $0x1, %edi
callq 0x1270