// File: 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
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movq %rdi, -0x8(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x450(%rbp)
callq 0x4740
movq -0x450(%rbp), %rdx
leaq 0x90fd(%rip), %rsi      # 0x1037a
leaq -0x28(%rbp), %rdi
callq 0x5e40
jmp 0x7288
leaq -0x29(%rbp), %rdi
callq 0x4450
movq -0x8(%rbp), %rdi
leaq 0x8efb(%rip), %rsi      # 0x10197
callq 0x45a0
cmpl $0x0, %eax
jne 0x72f4
leaq -0x60(%rbp), %rdi
callq 0x51b0
jmp 0x72b1
leaq -0x28(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x44f0
leaq -0x60(%rbp), %rdi
callq 0x4828
jmp 0x72f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x4450
jmp 0x7d11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7d08
movq -0x8(%rbp), %rdi
callq 0x4600
cmpl $0x0, %eax
jge 0x73a2
leaq -0x81(%rbp), %rdi
movq %rdi, -0x458(%rbp)
callq 0x4740
movq -0x458(%rbp), %rdx
leaq 0x8e73(%rip), %rsi      # 0x1019a
leaq -0x80(%rbp), %rdi
callq 0x5e40
jmp 0x7332
leaq -0x81(%rbp), %rdi
callq 0x4450
movq -0x8(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x43b0
jmp 0x734d
leaq -0x80(%rbp), %rdi
callq 0x41a0
movq %rax, %rdi
callq 0xe7a0
jmp 0x7360
leaq -0x80(%rbp), %rdi
callq 0x4828
jmp 0x73a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x81(%rbp), %rdi
callq 0x4450
jmp 0x7d08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4828
jmp 0x7d08
leaq -0xb0(%rbp), %rdi
callq 0x51b0
jmp 0x73b0
leaq -0xb0(%rbp), %rdi
callq 0x41a0
movq %rax, %rdi
callq 0x4650
movq %rax, -0x460(%rbp)
jmp 0x73cd
movq -0x460(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x74bb
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x468(%rbp)
callq 0x4740
movq -0x468(%rbp), %rdx
leaq 0x8da9(%rip), %rsi      # 0x101b3
leaq -0xd0(%rbp), %rdi
callq 0x5e40
jmp 0x7418
leaq -0xd1(%rbp), %rdi
callq 0x4450
leaq -0xd0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4530
jmp 0x7439
leaq -0xd0(%rbp), %rdi
callq 0x41a0
movq %rax, %rdi
callq 0xe7a0
jmp 0x744f
movl $0x1, %edi
callq 0x4300
jmp 0x745b
callq 0x50f0
jmp 0x7462
leaq -0xd0(%rbp), %rdi
callq 0x4828
jmp 0x74bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7cfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd1(%rbp), %rdi
callq 0x4450
jmp 0x7cfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x4828
jmp 0x7cfc
leaq 0x1016a(%rip), %rax     # 0x1762c
movl $0x0, (%rax)
leaq 0x10165(%rip), %rax     # 0x17634
movl $0x1, (%rax)
leaq 0x1004c(%rip), %rdi     # 0x17528
callq 0x8a00
leaq 0x1007c(%rip), %rax     # 0x17564
movl $0x1, (%rax)
leaq -0x191(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x4740
movq -0x470(%rbp), %rdx
leaq 0x8c89(%rip), %rsi      # 0x10198
leaq -0x190(%rbp), %rdi
callq 0x5e40
jmp 0x751d
leaq -0x191(%rbp), %rdi
callq 0x4450
leaq -0x1d8(%rbp), %rdi
leaq -0x190(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x8b10
jmp 0x7545
leaq 0xffdc(%rip), %rdi      # 0x17528
leaq -0x1d8(%rbp), %rsi
callq 0x8ae0
jmp 0x755a
leaq -0x1d8(%rbp), %rdi
callq 0x6850
movq -0x90(%rbp), %rdi
callq 0x4660
movq %rax, -0x478(%rbp)
jmp 0x757b
movq -0x478(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0x7963
movq -0xe0(%rbp), %rdi
addq $0x13, %rdi
callq 0x71a0
movb %al, -0x479(%rbp)
jmp 0x75ab
movb -0x479(%rbp), %al
testb $0x1, %al
jne 0x75b7
jmp 0x7604
jmp 0x7566
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x191(%rbp), %rdi
callq 0x4450
jmp 0x7cfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7cf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x6850
jmp 0x7cf0
leaq -0x1f8(%rbp), %rdi
callq 0x4590
leaq -0x259(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x4740
movq -0x488(%rbp), %rdx
leaq 0x89eb(%rip), %rsi      # 0x1001c
leaq -0x258(%rbp), %rdi
callq 0x5e40
jmp 0x763f
leaq -0x238(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x258(%rbp), %rdx
callq 0x8b90
jmp 0x765b
movq -0xe0(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x498(%rbp)
leaq -0x281(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x4740
movq -0x498(%rbp), %rsi
movq -0x490(%rbp), %rdx
leaq -0x280(%rbp), %rdi
callq 0x5e40
jmp 0x769c
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0x280(%rbp), %rdx
callq 0x5ef0
jmp 0x76b8
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
leaq -0x218(%rbp), %rsi
movq %rsi, -0x4a8(%rbp)
callq 0x44f0
movq -0x4a8(%rbp), %rdi
callq 0x4828
leaq -0x280(%rbp), %rdi
callq 0x4828
leaq -0x281(%rbp), %rdi
callq 0x4450
leaq -0x238(%rbp), %rdi
callq 0x4828
leaq -0x258(%rbp), %rdi
callq 0x4828
leaq -0x259(%rbp), %rdi
callq 0x4450
movq -0x4a0(%rbp), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x41b0
jmp 0x7736
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x4bd0
jmp 0x774b
leaq -0x1f8(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x44f0
leaq -0x2a8(%rbp), %rdi
callq 0x4828
leaq -0x2c8(%rbp), %rdi
callq 0x4828
leaq -0x1f8(%rbp), %rdi
callq 0x41a0
movq %rax, %rdi
leaq -0x170(%rbp), %rsi
callq 0x43a0
movl -0x158(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
je 0x785b
movl $0x2, -0x2cc(%rbp)
jmp 0x78e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x781c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7810
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x77f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x4828
leaq -0x281(%rbp), %rdi
callq 0x4450
leaq -0x238(%rbp), %rdi
callq 0x4828
leaq -0x258(%rbp), %rdi
callq 0x4828
leaq -0x259(%rbp), %rdi
callq 0x4450
jmp 0x7952
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7952
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x4828
jmp 0x7952
leaq -0x310(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x41b0
jmp 0x7870
leaq -0x2f0(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0xef10
jmp 0x7885
leaq -0x310(%rbp), %rdi
callq 0x4828
leaq -0x350(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
leaq -0x1f8(%rbp), %rdx
callq 0x8b10
jmp 0x78ad
leaq 0xfc74(%rip), %rdi      # 0x17528
leaq -0x350(%rbp), %rsi
callq 0x8ae0
jmp 0x78c2
leaq -0x350(%rbp), %rdi
callq 0x6850
leaq -0x2f0(%rbp), %rdi
callq 0x4828
movl $0x0, -0x2cc(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4828
movl -0x2cc(%rbp), %eax
testl %eax, %eax
je 0x7901
jmp 0x78fc
jmp 0x7566
jmp 0x7566
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x4828
jmp 0x7952
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7946
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x6850
leaq -0x2f0(%rbp), %rdi
callq 0x4828
leaq -0x1f8(%rbp), %rdi
callq 0x4828
jmp 0x7cf0
leaq 0x882d(%rip), %rsi      # 0x10197
leaq -0x190(%rbp), %rdi
callq 0x4580
jmp 0x7978
leaq -0x370(%rbp), %rdi
callq 0x51b0
jmp 0x7986
leaq 0xfb9b(%rip), %rdi      # 0x17528
callq 0x61f0
cmpq $0x1, %rax
jne 0x7af3
leaq -0x3d0(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0x41b0
jmp 0x79b1
leaq -0x3b0(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0xef10
jmp 0x79c6
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x4b0(%rbp)
leaq -0x370(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
leaq -0x3b0(%rbp), %rsi
callq 0x4810
movq -0x4b8(%rbp), %rsi
movq -0x4b0(%rbp), %rdx
movq %rax, %rcx
leaq -0x390(%rbp), %rdi
callq 0x4400
jmp 0x7a0a
leaq -0x370(%rbp), %rdi
movq %rdi, -0x4c0(%rbp)
leaq -0x390(%rbp), %rsi
movq %rsi, -0x4c8(%rbp)
callq 0x44f0
movq -0x4c8(%rbp), %rdi
callq 0x4828
leaq -0x3b0(%rbp), %rdi
callq 0x4828
leaq -0x3d0(%rbp), %rdi
callq 0x4828
movq -0x4c0(%rbp), %rdx
leaq -0x410(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x8b10
jmp 0x7a6b
leaq 0xfab6(%rip), %rdi      # 0x17528
leaq -0x410(%rbp), %rsi
callq 0x8ae0
jmp 0x7a80
leaq -0x410(%rbp), %rdi
callq 0x6850
jmp 0x7af3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7ce4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7ac5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x3b0(%rbp), %rdi
callq 0x4828
leaq -0x3d0(%rbp), %rdi
callq 0x4828
jmp 0x7ce4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x410(%rbp), %rdi
callq 0x6850
jmp 0x7ce4
leaq 0xfa2e(%rip), %rdi      # 0x17528
movq %rdi, -0x4d0(%rbp)
callq 0x8c20
movq -0x4d0(%rbp), %rdi
movq %rax, -0x418(%rbp)
callq 0x8c50
movq %rax, -0x420(%rbp)
movq -0x418(%rbp), %rdi
movq -0x420(%rbp), %rsi
callq 0x8be0
jmp 0x7b35
leaq -0xb0(%rbp), %rdi
callq 0x41a0
movq %rax, -0x428(%rbp)
leaq 0xfa19(%rip), %rdi      # 0x17568
leaq -0x428(%rbp), %rsi
callq 0x8c80
movq %rax, -0x4d8(%rbp)
jmp 0x7b64
movq -0x4d8(%rbp), %rax
cmpq $0x0, %rax
je 0x7bb7
leaq -0xb0(%rbp), %rdi
callq 0x41a0
movq %rax, -0x430(%rbp)
leaq 0xf9dd(%rip), %rdi      # 0x17568
leaq -0x430(%rbp), %rsi
callq 0x8ce0
movq %rax, -0x4e0(%rbp)
jmp 0x7ba0
movq -0x4e0(%rbp), %rax
movl (%rax), %ecx
leaq 0xf9b4(%rip), %rax      # 0x17564
movl %ecx, (%rax)
jmp 0x7c69
leaq -0x28(%rbp), %rdi
callq 0x4640
cmpq $0x0, %rax
jbe 0x7c67
movl $0x0, -0x434(%rbp)
leaq 0xf94d(%rip), %rdi      # 0x17528
callq 0x8c20
movq %rax, -0x440(%rbp)
leaq 0xf93a(%rip), %rdi      # 0x17528
callq 0x8c50
movq %rax, -0x448(%rbp)
leaq -0x440(%rbp), %rdi
leaq -0x448(%rbp), %rsi
callq 0x8dc0
testb $0x1, %al
jne 0x7c13
jmp 0x7c65
leaq -0x440(%rbp), %rdi
callq 0x8e00
movq %rax, %rdi
addq $0x20, %rdi
leaq -0x28(%rbp), %rsi
callq 0x8a20
testb $0x1, %al
jne 0x7c35
jmp 0x7c46
movl -0x434(%rbp), %ecx
leaq 0xf922(%rip), %rax      # 0x17564
movl %ecx, (%rax)
jmp 0x7c65
jmp 0x7c48
leaq -0x440(%rbp), %rdi
callq 0x8e20
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
jmp 0x7be7
jmp 0x7c67
jmp 0x7c69
leaq 0xf8f4(%rip), %rax      # 0x17564
movl (%rax), %edi
callq 0x5740
movb %al, -0x4e1(%rbp)
jmp 0x7c7f
movb -0x4e1(%rbp), %al
testb $0x1, %al
jne 0x7ca0
jmp 0x7c8b
leaq 0xf8d2(%rip), %rax      # 0x17564
movl (%rax), %ecx
subl $0x1, %ecx
leaq 0xf98e(%rip), %rax      # 0x1762c
movl %ecx, (%rax)
movq -0x90(%rbp), %rdi
callq 0x46c0
jmp 0x7cae
leaq -0x370(%rbp), %rdi
callq 0x4828
leaq -0x190(%rbp), %rdi
callq 0x4828
leaq -0xb0(%rbp), %rdi
callq 0x4828
leaq -0x28(%rbp), %rdi
callq 0x4828
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
leaq -0x370(%rbp), %rdi
callq 0x4828
leaq -0x190(%rbp), %rdi
callq 0x4828
leaq -0xb0(%rbp), %rdi
callq 0x4828
leaq -0x28(%rbp), %rdi
callq 0x4828
movq -0x38(%rbp), %rdi
callq 0x4730
nopw (%rax,%rax)