// File: /workspace/github_c_makefile_star2_O3/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 0xa582
movq %rax, %r12
movq %rbx, %rdi
callq 0xa6d4
testq %rax, %rax
je 0xa5b0
movq %rax, %r15
movq %rbx, 0x20(%rsp)
movq %rax, %rdi
callq 0xa6d9
movq $0x0, 0x18(%rsp)
testq %rax, %rax
je 0xa560
movq %rax, %r13
leaq 0x3(%r12), %rax
movq %rax, 0x28(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq $0x0, 0x8(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x5070
testl %eax, %eax
jne 0xa54a
movq %r13, %rdi
movq %r14, %rsi
callq 0x5160
orl %ebp, %eax
je 0xa56b
cmpb $0x2e, (%r13,%r12)
jne 0xa54a
leaq (%r12,%r13), %rdi
cmpb $0x0, 0x1(%rdi)
je 0xa54a
incq %rdi
callq 0x5240
movl %eax, %ebx
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %rdi
movzbl -0x1(%rdi), %eax
testl %eax, %eax
je 0xa4f8
cmpl $0x2e, %eax
je 0xa4f1
incq %rdi
jmp 0xa4df
callq 0x5240
jmp 0xa4fa
xorl %eax, %eax
testl %ebp, %ebp
je 0xa502
cmpl %ebp, %ebx
jne 0xa54a
cmpl 0x18(%rsp), %ebx
jg 0xa510
jne 0xa54a
cmpl 0x4(%rsp), %eax
jle 0xa54a
movl %eax, 0x14(%rsp)
movq %r13, %rdi
callq 0x50e0
cmpq $0x3fe, %rax            # imm = 0x3FE
ja 0xa54a
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x5080
movl 0x14(%rsp), %eax
movl %eax, 0x4(%rsp)
movl %ebx, %eax
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0xa6d9
movq %rax, %r13
testq %rax, %rax
jne 0xa48d
jmp 0xa570
movq $0x0, 0x8(%rsp)
jmp 0xa570
movq %r13, 0x8(%rsp)
movq %r15, %rdi
callq 0xa6ec
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %rbx
testq %r14, %r14
je 0xa5b0
leaq 0x28862(%rip), %rdi     # 0x32df0
movl $0x400, %ecx            # imm = 0x400
movq %rbx, %rsi
movq %r14, %rdx
callq 0xa658
testq %rax, %rax
je 0xa5b0
movq %rax, %rdi
callq 0x676b
testq %rax, %rax
jne 0xa5b2
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq