// File: /workspace/github_cpp_makefile_star2_O2/Linkerist[P]xs/src/io.cc
// Function: list_from_dir(char const*)
void
list_from_dir(const char * name)
{
 string previous_dir = "";
 if (!strcmp(name, ".."))
  previous_dir = get_cwd_as_string();

 // Checking, Changing and Reading
 if (chdir(name) < 0) {
  string msg = "couldn't change to dir: ";
  msg += name;
  message(msg.c_str());
 }
   
 DIR * THISDIR;
 string cwd = get_cwd_as_string();
 THISDIR = opendir(cwd.c_str());

 if (THISDIR == NULL) {
  string msg = "couldn't read dir: ";
  msg += cwd;
  message(msg.c_str());
  sleep(1);
  abort_xs();
 }
 yoffset = 0;
 shorties_offset = 1;
 struct dirent * en;
 struct stat buf;

 // cleanup
 cur_list.clear();

 CurrPosition = 1;

 // put the current directory on top ef every listing
 string desc = ".";
 cur_list.push_back(make_pair(desc,cwd));

 // read home dir
 while ((en = readdir(THISDIR)) != NULL) {
  /* filter dirs */
  if (dont_show(en->d_name))
   continue;
  string fullname;
  fullname = cwd + string("/") + string(en->d_name);

  fullname = canonify_filename(fullname);

  stat(fullname.c_str(), &buf);
  if (!S_ISDIR(buf.st_mode))
   continue;

  string lastdir = last_dirname(fullname);
  cur_list.push_back(make_pair(lastdir, fullname));
 }
 // empty directory listing: .. and .
 desc = "..";
 string path=get_cwd_as_string();
 if(cur_list.size() == 1) {
  path = path.substr(0, path.find(last_dirname(path)));
  cur_list.push_back(make_pair(desc,path));
 }

 sort(cur_list.begin(), cur_list.end());

 // have we remembered a current position for this dir?
 if (LastPositions.count(cwd.c_str()))
  CurrPosition = LastPositions[cwd.c_str()];
 else {
  //CurrPosition = 1;
  if(previous_dir.length() > 0) {
   int count = 0;
   for(listit it = cur_list.begin(); it != cur_list.end(); ++it, count++) {
    if(it->second == previous_dir) {
     CurrPosition = count;
     break;
    }
   }
  }
 }

 if(!visible(CurrPosition))
  yoffset = CurrPosition - 1;

 closedir(THISDIR);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
leaq 0x4906(%rip), %rsi      # 0x9396
leaq 0xd8(%rsp), %rdi
leaq 0x118(%rsp), %rdx
callq 0x43c8
cmpb $0x2e, (%rbx)
jne 0x4ae3
cmpb $0x2e, 0x1(%rbx)
jne 0x4ae3
cmpb $0x0, 0x2(%rbx)
jne 0x4ae3
leaq 0x118(%rsp), %rdi
callq 0x3cc8
leaq 0xd8(%rsp), %rdi
leaq 0x118(%rsp), %r14
movq %r14, %rsi
callq 0x33e0
movq %r14, %rdi
callq 0x36a8
movq %rbx, %rdi
callq 0x34c0
testl %eax, %eax
jns 0x4b32
leaq 0x46c0(%rip), %rsi      # 0x91b6
leaq 0x118(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x43c8
leaq 0x118(%rsp), %rdi
movq %rbx, %rsi
callq 0x3620
movq 0x118(%rsp), %rdi
callq 0x7931
leaq 0x118(%rsp), %rdi
callq 0x36a8
leaq 0x38(%rsp), %rdi
callq 0x3cc8
movq 0x38(%rsp), %rdi
callq 0x3500
movq %rax, 0x30(%rsp)
testq %rax, %rax
jne 0x4ba2
leaq 0x4678(%rip), %rsi      # 0x91cf
leaq 0x118(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x43c8
leaq 0x118(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3660
movq 0x118(%rsp), %rdi
callq 0x7931
pushq $0x1
popq %rdi
callq 0x3270
callq 0x3c40
leaq 0x118(%rsp), %rdi
callq 0x36a8
leaq 0x99c3(%rip), %rax      # 0xe56c
andl $0x0, (%rax)
leaq 0x99c1(%rip), %rax      # 0xe574
pushq $0x1
popq %rbx
movl %ebx, (%rax)
leaq 0x98a9(%rip), %rdi      # 0xe468
callq 0x5888
leaq 0x98d9(%rip), %rax      # 0xe4a4
movl %ebx, (%rax)
leaq 0x45e0(%rip), %rsi      # 0x91b4
leaq 0xb8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x43c8
leaq 0x58(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x5978
leaq 0x9864(%rip), %rdi      # 0xe468
leaq 0x58(%rsp), %rsi
callq 0x59ea
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x460a
leaq 0x98(%rsp), %r14
leaq 0x10(%rsp), %r12
leaq 0x1c8(%rsp), %rbx
movq 0x30(%rsp), %rdi
callq 0x3510
movq %rax, %r13
testq %rax, %rax
je 0x4da5
addq $0x13, %r13
movq %r13, %rdi
callq 0x4a10
testb %al, %al
jne 0x4c30
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
leaq 0x1a8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x43bb(%rip), %rsi      # 0x9038
leaq 0xf(%rsp), %rdx
callq 0x43c8
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
movq %rbp, %rdx
callq 0x58cf
leaq 0x208(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
leaq 0xe(%rsp), %rdx
callq 0x43c8
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4403
movq %r12, %rdi
movq %r15, %rsi
callq 0x33e0
movq %r15, %rdi
callq 0x36a8
movq %rbp, %rdi
callq 0x36a8
movq %r14, %rdi
callq 0x36a8
leaq 0x1a8(%rsp), %rdi
callq 0x36a8
leaq 0x1e8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3450
movq %r15, %rdi
movq %r13, %rsi
callq 0x393c
movq %r12, %rdi
movq %r15, %rsi
callq 0x33e0
movq %r15, %rdi
callq 0x36a8
movq %r13, %rdi
callq 0x36a8
movq 0x10(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x32f0
movl 0x130(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x4d98
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3450
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7def
movq %rbx, %rdi
callq 0x36a8
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x5978
leaq 0x96e8(%rip), %rdi      # 0xe468
movq %r15, %rsi
callq 0x59ea
movq %r15, %rdi
callq 0x460a
movq %r14, %rdi
callq 0x36a8
movq %r12, %rdi
callq 0x36a8
jmp 0x4c30
leaq 0x4407(%rip), %rsi      # 0x91b3
leaq 0xb8(%rsp), %rdi
callq 0x3630
leaq 0x10(%rsp), %rdi
callq 0x3cc8
leaq 0x96da(%rip), %r15      # 0xe4a4
leaq 0x9697(%rip), %rax      # 0xe468
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq %rsi, %rax
subq %rdi, %rax
cmpq $0x40, %rax
jne 0x4ea9
leaq 0xf8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3450
leaq 0x98(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x7def
leaq 0x10(%rsp), %rbx
leaq 0x98(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3690
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x3340
leaq 0x10(%rsp), %rbx
leaq 0x58(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33e0
movq %r14, %rdi
callq 0x36a8
leaq 0x98(%rsp), %rdi
callq 0x36a8
leaq 0xf8(%rsp), %rdi
callq 0x36a8
leaq 0x58(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
movq %rbx, %rdx
callq 0x5978
leaq 0x95dd(%rip), %rbx      # 0xe468
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x59ea
leaq 0x58(%rsp), %rdi
callq 0x460a
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x5bdb
movq 0x38(%rsp), %rax
leaq 0x58(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x95e6(%rip), %rdi      # 0xe4a8
callq 0x58f4
testq %rax, %rax
je 0x4f52
movq 0x38(%rsp), %rax
leaq 0x58(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x95c4(%rip), %rdi      # 0xe4a8
callq 0x590e
movl (%rax), %eax
movl %eax, (%r15)
movl (%r15), %edi
callq 0x3fe2
testb %al, %al
jne 0x4f08
movl (%r15), %eax
decl %eax
leaq 0x9666(%rip), %rcx      # 0xe56c
movl %eax, (%rcx)
movq 0x30(%rsp), %rdi
callq 0x3580
leaq 0x10(%rsp), %rdi
callq 0x36a8
leaq 0xb8(%rsp), %rdi
callq 0x36a8
leaq 0x38(%rsp), %rdi
callq 0x36a8
leaq 0xd8(%rsp), %rdi
callq 0x36a8
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0xe0(%rsp)
je 0x4eee
leaq 0x9504(%rip), %rax      # 0xe468
movq (%rax), %rbx
xorl %ebp, %ebp
leaq 0xd8(%rsp), %r14
leaq 0x94f0(%rip), %rax      # 0xe468
cmpq 0x8(%rax), %rbx
je 0x4eee
addq $0x20, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5890
testb %al, %al
jne 0x4f9d
incl %ebp
addq $0x20, %rbx
jmp 0x4f71
movl %ebp, (%r15)
jmp 0x4eee
jmp 0x502c
jmp 0x5024
jmp 0x502c
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x460a
jmp 0x50b9
jmp 0x5078
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x36a8
jmp 0x4fda
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x50b4
jmp 0x5078
jmp 0x5078
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x50da
jmp 0x5078
jmp 0x50c5
jmp 0x50c5
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x460a
jmp 0x50c8
jmp 0x50c5
movq %rax, %rbx
jmp 0x50d5
movq %rax, %rbx
jmp 0x50df
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x50d0
jmp 0x5078
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x460a
jmp 0x5058
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x50b4
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
jmp 0x50b4
jmp 0x5078
jmp 0x5078
movq %rax, %rbx
jmp 0x5092
movq %rax, %rbx
jmp 0x50b9
movq %rax, %rbx
jmp 0x509f
movq %rax, %rbx
leaq 0x208(%rsp), %rdi
callq 0x36a8
leaq 0x98(%rsp), %rdi
callq 0x36a8
leaq 0x1a8(%rsp), %rdi
jmp 0x50b4
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0x36a8
leaq 0x10(%rsp), %rdi
callq 0x36a8
jmp 0x50c8
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x36a8
leaq 0x38(%rsp), %rdi
callq 0x36a8
leaq 0xd8(%rsp), %rdi
callq 0x36a8
movq %rbx, %rdi
callq 0x35d0