// File: /workspace/github_cpp_makefile_star2_O1/dmonaldo[P]simple-network-file-system/FileSys.cpp
// Function: FileSys::ls()
void FileSys::ls()
{
  char bufferStart[] = "200 OK\r\n";
  string buffer = "";
  char msg[2048];
  char msgLength[80];
  dirblock_t curr_block_ptr;
  char curr_file_name[MAX_FNAME_SIZE + 1];
  //read the data held at the current directory from the disk
  bfs.read_block(curr_dir, (void*)&curr_block_ptr);
  for (unsigned int i = 0; i < MAX_DIR_ENTRIES; i++){
    if(curr_block_ptr.dir_entries[i].block_num > 0){
      if(is_directory(curr_block_ptr.dir_entries[i].block_num)){
        string temp(curr_block_ptr.dir_entries[i].name);
        buffer += temp;
        buffer += "/ ";
      }
      else{
        string temp2(curr_block_ptr.dir_entries[i].name);
        buffer += temp2;
        buffer += " ";
      }
    }
  }
  strcpy(msg, bufferStart);
  sprintf(msgLength, "Length: %d", sizeof(buffer.c_str()));
  strcat(msg, msgLength);
  strcat(msg, "\r\n\r\n");
  strcat(msg, buffer.c_str());
  send(fs_sock, msg, sizeof(msg), 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x978, %rsp            # imm = 0x978
movq %rdi, %rbx
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x6022(%rip), %rdx      # 0xa0ea
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x5d16
movswl 0x4(%rbx), %esi
leaq 0xa0(%rsp), %rdx
movq %rbx, %rdi
callq 0x3924
leaq 0xa8(%rsp), %r14
leaq 0x30(%rsp), %r13
movl $0x12, %ebp
leaq 0x20(%rsp), %r15
movq %rsp, %r12
movzwl 0xa0(%rsp,%rbp), %eax
testw %ax, %ax
jle 0x41ba
movswl %ax, %esi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3924
cmpl $-0x1, 0x20(%rsp)
je 0x4166
movq %r13, 0x20(%rsp)
movq %r14, %rdi
callq 0x3160
leaq (%rax,%r14), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5d16
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r12, %rdi
callq 0x30e0
movq %r12, %rdi
leaq 0x6034(%rip), %rsi      # 0xa193
callq 0x3490
jmp 0x41a3
movq %r13, 0x20(%rsp)
movq %r14, %rdi
callq 0x3160
leaq (%rax,%r14), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5d16
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r12, %rdi
callq 0x30e0
movq %r12, %rdi
leaq 0x5ff4(%rip), %rsi      # 0xa192
callq 0x3490
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x41ba
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32c0
addq $0xc, %r14
addq $0xc, %rbp
cmpq $0x8a, %rbp
jne 0x4101
movabsq $0xa0d4b4f20303032, %rax # imm = 0xA0D4B4F20303032
leaq 0x170(%rsp), %r14
movq %rax, (%r14)
xorl %ebp, %ebp
movb %bpl, 0x8(%r14)
leaq 0x5fa4(%rip), %rsi      # 0xa195
leaq 0x120(%rsp), %r15
movl $0x8, %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0x3080
movq %r14, %rdi
movq %r15, %rsi
callq 0x3450
movq %r14, %rdi
callq 0x3160
movb %bpl, 0x174(%rsp,%rax)
movl $0xa0d0a0d, 0x170(%rsp,%rax) # imm = 0xA0D0A0D
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x3450
movl 0x8(%rbx), %edi
movl $0x800, %edx            # imm = 0x800
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x3180
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4267
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32c0
addq $0x978, %rsp            # imm = 0x978
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4281
jmp 0x4281
jmp 0x4281
jmp 0x4286
movq %rax, %rbx
jmp 0x42a0
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x42a0
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32c0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x42bb
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3440
nop