// File: /workspace/github_c_makefile_star2_O1/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 0xa67d
movq %rax, %r12
movq %rbx, %rdi
callq 0xa7d8
testq %rax, %rax
je 0xa656
movq %rax, %r15
movq %rbx, 0x20(%rsp)
movq %rax, %rdi
callq 0xa7dd
movq $0x0, 0x18(%rsp)
testq %rax, %rax
je 0xa65b
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 0xa640
movq %r13, %rdi
movq %r14, %rsi
callq 0x5160
orl %ebp, %eax
je 0xa666
cmpb $0x2e, (%r13,%r12)
jne 0xa640
leaq (%r12,%r13), %rdi
cmpb $0x0, 0x1(%rdi)
je 0xa640
incq %rdi
callq 0x5240
movl %eax, %ebx
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %rdi
movzbl -0x1(%rdi), %eax
testl %eax, %eax
je 0xa5ee
cmpl $0x2e, %eax
je 0xa5e7
incq %rdi
jmp 0xa5d5
callq 0x5240
jmp 0xa5f0
xorl %eax, %eax
testl %ebp, %ebp
je 0xa5f8
cmpl %ebp, %ebx
jne 0xa640
cmpl 0x18(%rsp), %ebx
jg 0xa606
jne 0xa640
cmpl 0x4(%rsp), %eax
jle 0xa640
movl %eax, 0x14(%rsp)
movq %r13, %rdi
callq 0x50e0
cmpq $0x3fe, %rax            # imm = 0x3FE
ja 0xa640
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 0xa7dd
movq %rax, %r13
testq %rax, %rax
jne 0xa583
jmp 0xa66b
xorl %r14d, %r14d
jmp 0xa67d
movq $0x0, 0x8(%rsp)
jmp 0xa66b
movq %r13, 0x8(%rsp)
movq %r15, %rdi
callq 0xa7f0
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %rbx
testq %r14, %r14
je 0xa6b5
leaq 0x28767(%rip), %rdi     # 0x32df0
movl $0x400, %ecx            # imm = 0x400
movq %rbx, %rsi
movq %r14, %rdx
callq 0xa75c
testq %rax, %rax
je 0xa6af
movq %rax, %rdi
callq 0x679f
testq %rax, %rax
je 0xa6af
xorl %ecx, %ecx
jmp 0xa6b1
movb $0x1, %cl
testb %cl, %cl
je 0xa6b7
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq