// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rdi, 0x18(%rsp)
movq 0x10(%rdi), %r14
testq %r14, %r14
je 0x3da1
movq %r14, %rdi
callq 0x20e0
movq %rax, %r13
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r12
leaq (%rax,%r13), %rdi
addq $0x2, %rdi
callq 0x21d0
testq %rax, %rax
je 0x3f6a
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x21b0
movb $0x2f, (%r15,%r13)
leaq (%r15,%r13), %rdi
incq %rdi
incq %r12
movq %rbx, %rsi
movq %r12, %rdx
callq 0x21b0
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movq %rax, %r12
movq %r15, %rdi
callq 0x2030
jmp 0x3dae
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21a0
movq %rax, %r12
movq %r12, %rdi
callq 0x20d0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x3dd6
cmpb $0x2f, (%r12)
jne 0x3dec
cmpb $0x0, 0x1(%r12)
sete %al
movl %eax, 0xc(%rsp)
jmp 0x3df4
leaq 0x3751(%rip), %rdi      # 0x752e
movq %r12, %rsi
xorl %eax, %eax
callq 0x2ce6
jmp 0x4107
movl $0x0, 0xc(%rsp)
movq %r12, %r15
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
callq 0x21c0
testq %rax, %rax
je 0x3f89
movq %rax, %r13
xorl %r14d, %r14d
movl 0xc(%rsp), %eax
xorb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r12d, %r12d
cmpb $0x2e, 0x13(%r13)
jne 0x3e4f
movb 0x14(%r13), %al
testb %al, %al
je 0x3f52
cmpb $0x2e, %al
setne %al
orb 0xc(%rsp), %al
jne 0x3e4f
cmpb $0x0, 0x15(%r13)
je 0x3f52
addq $0x13, %r13
movq %r15, %rdi
callq 0x20e0
movq %rax, %rbx
movq %r13, %rdi
callq 0x20e0
leaq (%rbx,%rax), %rbp
addq $0x2, %rbp
testq %r12, %r12
sete %al
cmpq %rbp, %r14
setb %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x3e99
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2200
movq %rax, %rbx
testq %rax, %rax
jne 0x3e9f
jmp 0x3f52
movq %r12, %rbx
movq %r14, %rbp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2050
movq %rbx, %rdi
callq 0x20e0
movw $0x2f, (%rbx,%rax)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2280
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2190
testl %eax, %eax
js 0x3f4c
movq %r13, %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x29(%rax), %rdi
callq 0x21d0
testq %rax, %rax
je 0x3f8e
movq %rax, %r12
movq %rax, %rdi
addq $0x28, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x21b0
movb $0x0, 0x28(%r12,%r14)
movl 0x40(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
sete 0x18(%r12)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%r12)
movq $0x0, 0x8(%r12)
movq 0x10(%rsp), %rax
movq %rax, (%r12)
testq %rax, %rax
je 0x3f47
movq %r12, 0x8(%rax)
movq %r12, 0x10(%rsp)
movq %rbx, %r12
movq %rbp, %r14
movq 0x20(%rsp), %rdi
callq 0x21c0
movq %rax, %r13
testq %rax, %rax
jne 0x3e26
jmp 0x3f91
leaq 0x347b(%rip), %rdi      # 0x73ec
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ce6
xorl %r12d, %r12d
jmp 0x3f91
movq %rbx, %r12
movq %r12, %rdi
callq 0x2030
movq 0x20(%rsp), %rdi
callq 0x2120
leaq 0x10(%rsp), %rax
movq $-0x8, %rdi
movq $-0x1, %rcx
movq (%rax), %rax
addq $0x8, %rdi
incq %rcx
testq %rax, %rax
jne 0x3fb6
cmpq $0x1, %rcx
movq %r15, %r12
ja 0x3fd8
movq 0x10(%rsp), %r14
jmp 0x4085
callq 0x21d0
movq 0x10(%rsp), %r14
testq %rax, %rax
je 0x4085
movq %rax, %r15
testq %r14, %r14
je 0x4064
xorl %ebx, %ebx
movq %r14, (%r15,%rbx,8)
incq %rbx
movq (%r14), %r14
testq %r14, %r14
jne 0x3ff5
leaq 0x115(%rip), %rcx       # 0x4120
movl $0x8, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2070
movq %rbx, %rax
subq $0x1, %rax
jb 0x407a
xorl %ecx, %ecx
movq (%r15,%rcx,8), %rsi
movq %rcx, 0x10(%rsi)
leaq 0x1(%rcx), %rdx
cmpq %rbx, %rdx
jae 0x403e
movq 0x8(%r15,%rcx,8), %rdi
jmp 0x4040
xorl %edi, %edi
movq %rdi, (%rsi)
decq %rdx
je 0x404f
movq -0x8(%r15,%rcx,8), %rsi
jmp 0x4051
xorl %esi, %esi
movq (%r15,%rcx,8), %rcx
movq %rsi, 0x8(%rcx)
leaq 0x1(%rdx), %rcx
cmpq %rdx, %rax
jne 0x4026
jmp 0x407a
leaq 0xb5(%rip), %rcx        # 0x4120
movl $0x8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2070
movq (%r15), %r14
movq %r15, %rdi
callq 0x2030
testq %r14, %r14
je 0x4107
xorl %ebx, %ebx
movq %r14, %r15
leaq 0x28(%r15), %rdi
callq 0x37d1
cmpq %rbx, %rax
cmovaq %rax, %rbx
movq (%r15), %r15
testq %r15, %r15
jne 0x408f
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x40ba
callq 0x2030
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x40d8
movq (%rdi), %r15
callq 0x2030
movq %r15, %rdi
testq %r15, %r15
jne 0x40c8
movq 0x18(%rsp), %rax
movq %r12, 0x10(%rax)
movq %r14, 0x18(%rax)
movq %rbx, 0x20(%rax)
movq %r14, 0x28(%rax)
movq $0x0, 0x30(%rax)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2030