// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/linker.c
// Function: scan_directory
static char *scan_directory(char *dirname,char *libname,int so_ver)
{
  size_t lnlen=strlen(libname);
  char *dd,*scan,*fname=NULL;
  char maxname[FNAMEBUFSIZE];
  int maxver=0,maxsubver=-1;

  if (so_ver < 0) {
    /* no need to scan the directory */
    fname = libname;
  }
  else {
    if (dd = open_dir(dirname)) {
      while (scan = read_dir(dd)) {
        if (!strncmp(scan,libname,lnlen)) {
          /* found a library archive/shared object name! */
          if (!strcmp(scan,libname) && so_ver==0) {  /* perfect match */
            fname = scan;
            break;
          }
          else {  /* find highest version */
            if (scan[lnlen]=='.' && scan[lnlen+1]) {
              char *p = &scan[lnlen+1];
              int ver = atoi(p++);
              int subver = 0;

              while (*p!='\0' && *p!='.')
                p++;
              if (*p++ == '.')
                subver = atoi(p);

              if (so_ver==0 || so_ver==ver) {
                if ((ver>maxver || (ver==maxver && subver>maxsubver)) &&
                    strlen(scan)<(FNAMEBUFSIZE-1)) {
                  fname = maxname;
                  maxver = ver;
                  maxsubver = subver;
                  strcpy(maxname,scan);
                }
              }
            }
          }
        }
      }
      close_dir(dd);
    }
  }

  if (fname) {
    char *p,*fullpath;

    if (fullpath = path_append(namebuf,dirname,fname,FNAMEBUFSIZE)) {
      if (p = mapfile(fullpath))
        return (p);
    }
  }
  return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x50e0
testl %ebp, %ebp
js 0xa026
movq %rax, %r13
movq %rbx, %rdi
callq 0xa1cc
movq %rax, %r12
xorl %eax, %eax
testq %r12, %r12
je 0xa056
movq $0x0, 0x18(%rsp)
leaq 0x3(%r13), %rax
movq %rax, 0x28(%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
movq %r12, %rdi
callq 0xa1d1
testq %rax, %rax
je 0xa00f
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x5070
testl %eax, %eax
jne 0x9f29
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5160
orl %ebp, %eax
je 0xa016
cmpb $0x2e, (%rbx,%r13)
jne 0x9f29
leaq (%rbx,%r13), %rdi
cmpb $0x0, 0x1(%rdi)
je 0x9f29
incq %rdi
callq 0x5250
movl %eax, %r15d
movq %rbx, %rdi
addq 0x28(%rsp), %rdi
movzbl -0x1(%rdi), %eax
testl %eax, %eax
je 0x9f9f
cmpl $0x2e, %eax
je 0x9f98
incq %rdi
jmp 0x9f86
callq 0x5250
jmp 0x9fa1
xorl %eax, %eax
testl %ebp, %ebp
je 0x9fae
cmpl %ebp, %r15d
jne 0x9f29
cmpl 0x18(%rsp), %r15d
jg 0x9fc5
jne 0x9f29
cmpl 0x8(%rsp), %eax
jle 0x9f29
movq %rbx, %rdi
movl %eax, 0xc(%rsp)
callq 0x50e0
movl %r15d, %ecx
cmpq $0x3fe, %rax            # imm = 0x3FE
movl 0xc(%rsp), %r15d
ja 0x9f29
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
movl %ecx, %ebx
callq 0x5080
movl %r15d, 0x8(%rsp)
movl %ebx, %eax
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x9f29
movq 0x10(%rsp), %r14
jmp 0xa019
movq %rbx, %r14
movq %r12, %rdi
callq 0xa1e4
movq 0x20(%rsp), %rbx
testq %r14, %r14
je 0xa054
leaq 0x291ae(%rip), %rdi     # 0x331e0
movl $0x400, %ecx            # imm = 0x400
movq %rbx, %rsi
movq %r14, %rdx
callq 0xa150
testq %rax, %rax
je 0xa054
movq %rax, %rdi
callq 0x6456
testq %rax, %rax
jne 0xa056
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq