// File: /workspace/github_c_makefile_star2_O0/moefh[P]hed/src/file_sel.c
// Function: change_dir
static int change_dir(struct file_sel *fs, const char *dir_name)
{
  char *new_dir_name;
  if (fs->dir_name) {
    size_t fs_dir_name_len = strlen(fs->dir_name);
    size_t dir_name_len = strlen(dir_name);
    char *full_dir_name = malloc(fs_dir_name_len + 1 + dir_name_len + 1);
    if (! full_dir_name)
      return show_msg("ERROR: out of memory");
    memcpy(full_dir_name, fs->dir_name, fs_dir_name_len);
    full_dir_name[fs_dir_name_len] = '/';
    memcpy(full_dir_name + fs_dir_name_len + 1, dir_name, dir_name_len + 1);
    new_dir_name = get_absolute_dir(full_dir_name);
    free(full_dir_name);
  } else
    new_dir_name = get_absolute_dir(dir_name);

  struct file_item *dir_list = read_dir_list(new_dir_name);
  if (! dir_list) {
    free(new_dir_name);
    return -1;
  }
  size_t num_files = 0;
  size_t max_filename_len = 0;
  for (struct file_item *f = dir_list; f != NULL; f = f->next) {
    size_t filename_len = utf8_len(f->filename);
    if (filename_len > max_filename_len)
      max_filename_len = filename_len;
    num_files++;
  }

  if (fs->dir_name)
    free(fs->dir_name);
  if (fs->dir_list)
    free_dir_list(fs->dir_list);
  fs->dir_name = new_dir_name;
  fs->dir_list = dir_list;
  fs->max_filename_len = max_filename_len;

  fs->sel = fs->dir_list;
  fs->top_line = 0;
  return 0;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x58(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x50bd
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x20d0
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rdi
callq 0x20d0
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
addq $0x1, %rdi
addq 0x38(%rsp), %rdi
addq $0x1, %rdi
callq 0x21c0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x505b
leaq 0x634d(%rip), %rdi      # 0xb398
movb $0x0, %al
callq 0x3610
movl %eax, 0x64(%rsp)
jmp 0x51e9
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x40(%rsp), %rdx
callq 0x21a0
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
movb $0x2f, (%rax,%rcx)
movq 0x30(%rsp), %rdi
addq 0x40(%rsp), %rdi
addq $0x1, %rdi
movq 0x50(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq $0x1, %rdx
callq 0x21a0
movq 0x30(%rsp), %rdi
callq 0x5710
movq %rax, 0x48(%rsp)
movq 0x30(%rsp), %rdi
callq 0x2030
jmp 0x50cc
movq 0x50(%rsp), %rdi
callq 0x5710
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x5740
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x50fa
movq 0x48(%rsp), %rdi
callq 0x2030
movl $0xffffffff, 0x64(%rsp) # imm = 0xFFFFFFFF
jmp 0x51e9
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x5164
movq 0x10(%rsp), %rdi
addq $0x28, %rdi
callq 0x4da0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x18(%rsp), %rax
jbe 0x5147
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x5116
movq 0x58(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x517e
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x2030
movq 0x58(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x5198
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x5980
movq 0x48(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x58(%rsp), %rax
movq $0x0, 0x30(%rax)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)