// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
movq 0x10(%rdi), %r12
testq %r12, %r12
je 0x3bee
movq %r12, %rdi
callq 0x20e0
movq %rax, %rbp
movq %r14, %rdi
callq 0x20e0
movq %rax, %r13
leaq (%rax,%rbp), %rdi
addq $0x2, %rdi
callq 0x21d0
testq %rax, %rax
je 0x3dd9
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x21b0
movb $0x2f, (%r15,%rbp)
leaq (%r15,%rbp), %rdi
incq %rdi
incq %r13
movq %r14, %rsi
movq %r13, %rdx
callq 0x21b0
movq %r15, %rdi
callq 0x3edb
movq %rax, %r13
movq %r15, %rdi
callq 0x2030
jmp 0x3bf9
movq %r14, %rdi
callq 0x3edb
movq %rax, %r13
movq %r13, %rdi
callq 0x20d0
testq %rax, %rax
je 0x3c1f
movq %rax, %r15
cmpb $0x2f, (%r13)
movq %r13, 0x10(%rsp)
jne 0x3c35
cmpb $0x0, 0x1(%r13)
sete %al
jmp 0x3c37
leaq 0x3908(%rip), %rdi      # 0x752e
movq %r13, %rsi
xorl %eax, %eax
callq 0x2bb0
jmp 0x3e7f
xorl %eax, %eax
andq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
xorb $0x1, %al
movl %eax, 0x1c(%rsp)
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x21c0
testq %rax, %rax
je 0x3d74
movq %rax, %rbp
cmpb $0x2e, 0x13(%rax)
jne 0x3c7b
movb 0x14(%rbp), %al
testb %al, %al
je 0x3c49
cmpb $0x2e, %al
setne %al
orb 0x1c(%rsp), %al
jne 0x3c7b
cmpb $0x0, 0x15(%rbp)
je 0x3c49
addq $0x13, %rbp
testq %r12, %r12
sete %r13b
movq 0x10(%rsp), %rdi
callq 0x20e0
movq %rax, %rbx
movq %rbp, %rdi
callq 0x20e0
addq %rax, %rbx
addq $0x2, %rbx
cmpq %rbx, %r14
setb %al
orb %r13b, %al
cmpb $0x1, %al
jne 0x3cc5
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2200
testq %rax, %rax
je 0x3c49
movq %rax, %r12
movq %rbx, %r14
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x2050
movq %r12, %rdi
callq 0x20e0
movw $0x2f, (%r12,%rax)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2280
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2190
testl %eax, %eax
js 0x3c49
movq %rbp, %rdi
callq 0x20e0
movq %rax, %rbx
leaq 0x29(%rax), %rdi
callq 0x21d0
testq %rax, %rax
je 0x3d74
movq %rax, %r13
movq %rax, %rdi
addq $0x28, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x21b0
movb $0x0, 0x28(%r13,%rbx)
movl 0x40(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
sete 0x18(%r13)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%r13)
andq $0x0, 0x8(%r13)
movq 0x8(%rsp), %rax
movq %rax, (%r13)
testq %rax, %rax
je 0x3d6a
movq %r13, 0x8(%rax)
movq %r13, 0x8(%rsp)
jmp 0x3c49
movq %r12, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2120
leaq 0x8(%rsp), %rax
pushq $-0x8
popq %rdi
pushq $-0x1
popq %rcx
movq 0x10(%rsp), %r13
movq (%rax), %rax
addq $0x8, %rdi
incq %rcx
testq %rax, %rax
jne 0x3d94
cmpq $0x2, %rcx
jb 0x3dcf
callq 0x21d0
testq %rax, %rax
je 0x3dcf
movq %rax, %r15
leaq 0x8(%rsp), %rax
xorl %r12d, %r12d
movq (%rax), %rax
testq %rax, %rax
je 0x3df8
movq %rax, (%r15,%r12,8)
incq %r12
jmp 0x3dbe
movq 0x8(%rsp), %rbx
jmp 0x3e5a
leaq 0x360c(%rip), %rdi      # 0x73ec
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2bb0
leaq 0xf8(%rip), %rcx        # 0x3ef7
pushq $0x8
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2070
xorl %eax, %eax
cmpq %rax, %r12
je 0x3e4f
movq (%r15,%rax,8), %rdx
movq %rax, 0x10(%rdx)
leaq 0x1(%rax), %rcx
cmpq %r12, %rcx
jae 0x3e2c
movq 0x8(%r15,%rax,8), %rsi
jmp 0x3e2e
xorl %esi, %esi
movq %rsi, (%rdx)
decq %rcx
je 0x3e3d
movq -0x8(%r15,%rax,8), %rdx
jmp 0x3e3f
xorl %edx, %edx
movq (%r15,%rax,8), %rax
movq %rdx, 0x8(%rax)
incq %rcx
movq %rcx, %rax
jmp 0x3e0f
movq (%r15), %rbx
movq %r15, %rdi
callq 0x2030
testq %rbx, %rbx
je 0x3e7f
xorl %r14d, %r14d
movq %rbx, %r15
testq %r15, %r15
je 0x3e98
leaq 0x28(%r15), %rdi
callq 0x3671
cmpq %r14, %rax
cmovaq %rax, %r14
movq (%r15), %r15
jmp 0x3e65
movq %r13, %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2030
movq 0x20(%rsp), %r15
movq 0x10(%r15), %rdi
callq 0x2030
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x3eb4
callq 0x3ee2
movq %r13, 0x10(%r15)
movq %rbx, 0x18(%r15)
movq %r14, 0x20(%r15)
movq %rbx, 0x28(%r15)
andq $0x0, 0x30(%r15)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq