// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x478, %rsp            # imm = 0x478
movq %rdi, 0x468(%rsp)
movq %rsi, 0x460(%rsp)
movl %edx, 0x45c(%rsp)
movq 0x460(%rsp), %rdi
callq 0x50c0
movq %rax, 0x450(%rsp)
movq $0x0, 0x438(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x45c(%rsp)
jge 0xee3e
movq 0x460(%rsp), %rax
movq %rax, 0x438(%rsp)
jmp 0xf051
movq 0x468(%rsp), %rdi
callq 0xf4a0
movq %rax, 0x448(%rsp)
cmpq $0x0, %rax
je 0xf04f
jmp 0xee5f
movq 0x448(%rsp), %rdi
callq 0xf4b0
movq %rax, 0x440(%rsp)
cmpq $0x0, %rax
je 0xf042
movq 0x440(%rsp), %rdi
movq 0x460(%rsp), %rsi
movq 0x450(%rsp), %rdx
callq 0x5050
cmpl $0x0, %eax
jne 0xf03d
movq 0x440(%rsp), %rdi
movq 0x460(%rsp), %rsi
callq 0x5130
cmpl $0x0, %eax
jne 0xeedd
cmpl $0x0, 0x45c(%rsp)
jne 0xeedd
movq 0x440(%rsp), %rax
movq %rax, 0x438(%rsp)
jmp 0xf042
movq 0x440(%rsp), %rax
movq 0x450(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0xf039
movq 0x440(%rsp), %rax
movq 0x450(%rsp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xf039
movq 0x440(%rsp), %rax
movq 0x450(%rsp), %rcx
addq $0x1, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq %rdi, %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
callq 0x5220
movl %eax, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movq 0x20(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x7(%rsp)
je 0xef7b
movq 0x20(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0xef85
jmp 0xef95
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0xef56
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rsp)
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0xefbc
movq 0x20(%rsp), %rdi
callq 0x5220
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x45c(%rsp)
je 0xefd3
movl 0x45c(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jne 0xf037
movl 0x1c(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jg 0xeff1
movl 0x1c(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jne 0xf035
movl 0x18(%rsp), %eax
cmpl 0x28(%rsp), %eax
jle 0xf035
movq 0x440(%rsp), %rdi
callq 0x50c0
cmpq $0x3ff, %rax            # imm = 0x3FF
jae 0xf035
leaq 0x30(%rsp), %rax
movq %rax, 0x438(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
movq 0x440(%rsp), %rsi
callq 0x5060
jmp 0xf037
jmp 0xf039
jmp 0xf03b
jmp 0xf03d
jmp 0xee5f
movq 0x448(%rsp), %rdi
callq 0xf4f0
jmp 0xf051
cmpq $0x0, 0x438(%rsp)
je 0xf0b0
movq 0x468(%rsp), %rsi
movq 0x438(%rsp), %rdx
leaq 0x3514d(%rip), %rdi     # 0x441c0
movl $0x400, %ecx            # imm = 0x400
callq 0xf3c0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0xf0ae
movq 0x8(%rsp), %rdi
callq 0x7570
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0xf0ac
movq 0x10(%rsp), %rax
movq %rax, 0x470(%rsp)
jmp 0xf0bc
jmp 0xf0ae
jmp 0xf0b0
movq $0x0, 0x470(%rsp)
movq 0x470(%rsp), %rax
addq $0x478, %rsp            # imm = 0x478
retq
nopl (%rax)