// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movq 0x10(%rdi), %r15
testq %r15, %r15
je 0x3eed
movq %r15, %rdi
callq 0x20e0
movq %rax, %r13
movq %r14, %rdi
callq 0x20e0
movq %rax, %r12
leaq (%rax,%r13), %rdi
addq $0x2, %rdi
callq 0x21d0
movq %rax, %rbx
testq %rax, %rax
je 0x3efc
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x21b0
movb $0x2f, (%rbx,%r13)
leaq (%rbx,%r13), %rdi
incq %rdi
incq %r12
movq %r14, %rsi
movq %r12, %rdx
callq 0x21b0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21a0
movq %rax, %r12
movq %rbx, %rdi
callq 0x2030
jmp 0x3f0a
movq %r14, %rdi
xorl %esi, %esi
callq 0x21a0
movq %rax, %r12
jmp 0x3f13
leaq 0x34c1(%rip), %rdi      # 0x73c4
xorl %eax, %eax
callq 0x2d46
testq %rbx, %rbx
je 0x4209
movq %r12, %rdi
callq 0x20d0
testq %rax, %rax
je 0x4123
movq %rax, %rbx
movq %rbp, 0x20(%rsp)
leaq 0x35ed(%rip), %rsi      # 0x7520
movq %r12, %rdi
callq 0x2150
movl %eax, 0x1c(%rsp)
movq $0x0, (%rsp)
xorl %r14d, %r14d
movq $0x0, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0x21c0
movb $0x1, %bpl
testq %rax, %rax
je 0x40a9
movq %rax, %r13
addq $0x13, %r13
movq %r13, %rdi
leaq 0x35a6(%rip), %rsi      # 0x7523
callq 0x2150
testl %eax, %eax
je 0x3fd4
cmpl $0x0, 0x1c(%rsp)
jne 0x3fa0
movq %r13, %rdi
leaq 0x358b(%rip), %rsi      # 0x7522
callq 0x2150
testl %eax, %eax
je 0x3fd4
movq %r12, %r15
movq %r12, %rdi
callq 0x20e0
movq %rax, %rbx
movq %r13, %rdi
callq 0x20e0
leaq (%rbx,%rax), %r12
addq $0x2, %r12
testq %r14, %r14
je 0x3fdb
cmpq %r12, 0x10(%rsp)
jb 0x3fdb
movq %r14, %rbx
movq 0x10(%rsp), %r12
jmp 0x3ff2
xorl %ebp, %ebp
jmp 0x40a9
movq %r14, %rdi
movq %r12, %rsi
callq 0x2200
movq %rax, %rbx
testq %rax, %rax
je 0x40b4
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
shrl $0x1f, %eax
movq %rbx, %r14
movq %r12, 0x10(%rsp)
testb %al, %al
jne 0x409f
movq %r13, %rdi
callq 0x20e0
movq %rax, %r12
leaq 0x29(%rax), %rdi
callq 0x21d0
testq %rax, %rax
je 0x40a1
movq %rax, %rbx
movq %rax, %rdi
addq $0x28, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x21b0
movb $0x0, 0x28(%rbx,%r12)
movl 0x40(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
sete 0x18(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rbx)
movq $0x0, 0x8(%rbx)
movq (%rsp), %rax
movq %rax, (%rbx)
testq %rax, %rax
je 0x409b
movq %rbx, 0x8(%rax)
movq %rbx, (%rsp)
xorl %ebp, %ebp
movq %r15, %r12
movq 0x8(%rsp), %rbx
testb %bpl, %bpl
je 0x3f58
jmp 0x40bb
movb $0x1, %al
jmp 0x402e
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x2120
movq %rsp, %rax
movq $-0x8, %rdi
movq $-0x1, %rcx
movq (%rax), %rax
addq $0x8, %rdi
incq %rcx
testq %rax, %rax
jne 0x40dc
cmpq $0x2, %rcx
movq 0x20(%rsp), %rbp
jb 0x41a3
callq 0x21d0
testq %rax, %rax
je 0x41a3
movq %rax, %rbx
movq (%rsp), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0x4138
movq %rax, (%rbx,%r15,8)
incq %r15
movq (%rax), %rax
jmp 0x4112
leaq 0x33dc(%rip), %rdi      # 0x7506
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x2d46
jmp 0x41a7
leaq 0xf5(%rip), %rcx        # 0x4234
movl $0x8, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2070
testq %r15, %r15
je 0x4194
xorl %eax, %eax
movq (%rbx,%rax,8), %rdx
movq %rax, 0x10(%rdx)
leaq 0x1(%rax), %rcx
cmpq %r15, %rcx
jae 0x416e
movq 0x8(%rbx,%rax,8), %rsi
jmp 0x4170
xorl %esi, %esi
movq %rsi, (%rdx)
decq %rcx
je 0x417f
movq -0x8(%rbx,%rax,8), %rdx
jmp 0x4181
xorl %edx, %edx
movq (%rbx,%rax,8), %rax
movq %rdx, 0x8(%rax)
incq %rcx
movq %rcx, %rax
cmpq %r15, %rcx
jne 0x4156
movq (%rbx), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0x2030
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x421b
xorl %r14d, %r14d
movq %rbx, %r15
leaq 0x28(%r15), %rdi
callq 0x3925
cmpq %r14, %rax
cmovaq %rax, %r14
movq (%r15), %r15
testq %r15, %r15
jne 0x41b2
movq 0x10(%rbp), %rdi
testq %rdi, %rdi
je 0x41d8
callq 0x2030
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
je 0x41f1
movq (%rdi), %r15
callq 0x2030
movq %r15, %rdi
testq %r15, %r15
jne 0x41e1
movq %r12, 0x10(%rbp)
movq %rbx, 0x18(%rbp)
movq %r14, 0x20(%rbp)
movq %rbx, 0x28(%rbp)
movq $0x0, 0x30(%rbp)
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