// File: /workspace/github_c_makefile_star2_O3/moefh[P]hed/src/file_sel.c
// Function: hed_select_file
int hed_select_file(struct hed_editor *editor, char *filename, size_t max_filename_len)
{
  clear_msg();

  struct hed_screen *scr = &editor->screen;
  struct file_sel file_sel;
  init_file_sel(&file_sel, editor);
  change_dir(&file_sel, ".");
  
  reset_color();
  clear_screen();
  scr->redraw_needed = true;
  while (! editor->quit && ! file_sel.quit) {
    if (scr->redraw_needed)
      draw_main_screen(&file_sel);
    process_input(&file_sel);
  }

  if (file_sel.ret >= 0) {
    if (file_sel.sel)
      snprintf(filename, max_filename_len, "%s/%s", file_sel.dir_name, file_sel.sel->filename);
    else
      file_sel.ret = -1;
  }
  
  destroy_file_sel(&file_sel);

  reset_color();
  clear_screen();
  scr->redraw_needed = true;
  return file_sel.ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, %r15
callq 0x2db2
movq %rsp, %rdi
movq %r15, (%rdi)
movb $0x0, 0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, 0x20(%rdi)
movl $0xffffffff, 0xc(%rdi)  # imm = 0xFFFFFFFF
movq $0x0, 0x30(%rdi)
leaq 0x41ff(%rip), %rsi      # 0x7a71
callq 0x3d11
callq 0x318e
callq 0x31fe
movb $0x1, 0x115(%r15)
cmpb $0x0, (%r15)
jne 0x3c82
testb $0x1, 0x8(%rsp)
jne 0x3c82
leaq 0x3f5c(%rip), %r13      # 0x7801
leaq 0x60(%rsp), %rbx
movq %r15, 0x50(%rsp)
movq (%rsp), %rbp
cmpb $0x1, 0x115(%r15)
jne 0x3b32
cmpb $0x1, 0x114(%rbp)
jne 0x38db
callq 0x318e
callq 0x31fe
movb $0x0, 0x114(%rbp)
callq 0x318e
movl $0x1e, %edi
movl $0x2f, %esi
callq 0x3124
movl $0x1, %edi
movl $0x1, %esi
callq 0x31aa
callq 0x319c
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x3924
movl 0x10c(%rbp), %esi
addl $-0x1e, %esi
leaq 0x3c4c(%rip), %rdi      # 0x7569
xorl %eax, %eax
callq 0x2e58
movl 0x10c(%rbp), %edi
addl $-0x9, %edi
movl $0x1, %esi
callq 0x31aa
leaq 0x4011(%rip), %rdi      # 0x794f
leaq 0x3c2f(%rip), %rsi      # 0x7574
xorl %eax, %eax
callq 0x2e58
callq 0x318e
callq 0x318e
movl 0x110(%rbp), %esi
decl %esi
movl $0x1, %edi
callq 0x31aa
cmpb $0x0, 0x119(%rbp)
je 0x3998
leaq 0x119(%rbp), %r14
movl $0x1e, %edi
movl $0x2f, %esi
callq 0x3124
leaq 0x3fc0(%rip), %rdi      # 0x794e
movq %r14, %rsi
xorl %eax, %eax
callq 0x2e58
callq 0x319c
movl 0x110(%rbp), %esi
movl $0x1, %edi
leaq 0x3bce(%rip), %rdx      # 0x757d
leaq 0x3bca(%rip), %rcx      # 0x7580
callq 0x42cb
callq 0x319c
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
leaq 0x18(%rsp), %r15
movq (%r15), %r15
cmpq %rax, %rcx
jae 0x39dc
incq %rcx
testq %r15, %r15
jne 0x39cc
movq 0x20(%rsp), %rax
incq %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
cmovaeq %rcx, %rax
movl 0x10c(%rbp), %ecx
addl $-0x14, %ecx
cmpl %eax, %ecx
cmovgel %eax, %ecx
testq %r15, %r15
je 0x3af0
movl %ecx, 0x3c(%rsp)
movslq %ecx, %r12
xorl %ebx, %ebx
movq %rbp, 0x58(%rsp)
leal 0x6(%rbx), %eax
cmpl 0x110(%rbp), %eax
jge 0x3af2
cmpq 0x28(%rsp), %r15
je 0x3a32
callq 0x318e
jmp 0x3a41
movl $0x1e, %edi
movl $0x2f, %esi
callq 0x3124
leal 0x3(%rbx), %esi
movl $0x1, %edi
callq 0x31aa
leaq 0x28(%r15), %r14
movq %r14, %rdi
callq 0x37d1
movq %rax, %rbp
cmpq %rax, %r12
jae 0x3a79
leaq 0x3b06(%rip), %rdi      # 0x756f
movl 0x3c(%rsp), %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e58
jmp 0x3a8a
leaq 0x3ecf(%rip), %rdi      # 0x794f
movq %r14, %rsi
xorl %eax, %eax
callq 0x2e58
movq %r12, %r14
subq %rbp, %r14
jbe 0x3aa1
movq %r13, %rdi
xorl %eax, %eax
callq 0x2e58
decq %r14
jne 0x3a92
cmpb $0x0, 0x18(%r15)
movq 0x58(%rsp), %rbp
je 0x3ac1
movq 0x20(%r15), %rsi
leaq 0x3a90(%rip), %rdi      # 0x7548
xorl %eax, %eax
callq 0x2e58
jmp 0x3acf
leaq 0x3a8c(%rip), %rdi      # 0x7554
xorl %eax, %eax
callq 0x2e58
cmpq 0x28(%rsp), %r15
jne 0x3adb
callq 0x318e
incl %ebx
callq 0x319c
movq (%r15), %r15
testq %r15, %r15
jne 0x3a15
jmp 0x3af2
xorl %ebx, %ebx
addl $0x6, %ebx
cmpl 0x110(%rbp), %ebx
jge 0x3b18
callq 0x318e
leal -0x3(%rbx), %esi
movl $0x1, %edi
callq 0x31aa
callq 0x319c
incl %ebx
jmp 0x3af5
callq 0x2de3
movb $0x0, 0x115(%rbp)
movq (%rsp), %rbp
movq 0x50(%rsp), %r15
leaq 0x60(%rsp), %rbx
movl 0x108(%rbp), %edi
movl $0x40, %edx
movq %rbx, %rsi
callq 0x2898
cmpl $0x110001, %eax         # imm = 0x110001
jg 0x3b92
leal -0xc(%rax), %ecx
cmpl $0xd, %ecx
ja 0x3c43
leaq 0x3971(%rip), %rdx      # 0x74d0
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x3c71
cmpb $0x1, 0x18(%rsi)
jne 0x3c5e
movb $0x1, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x3c71
leal -0x111002(%rax), %ecx
cmpl $0x7, %ecx
ja 0x3c30
leaq 0x3960(%rip), %rdx      # 0x7508
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x3c71
movq %rax, 0x28(%rsp)
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rcx
cmpq %rcx, %rax
cmovbq %rax, %rcx
jmp 0x3c15
movq 0x28(%rsp), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x3c71
movslq 0x110(%rbp), %rax
addq $-0x6, %rax
movq %rcx, 0x28(%rsp)
movq 0x30(%rsp), %rdx
addq %rax, %rdx
decq %rdx
movq 0x10(%rcx), %rcx
cmpq %rcx, %rdx
jae 0x3c6a
subq %rax, %rcx
incq %rcx
movq %rcx, 0x30(%rsp)
jmp 0x3c6a
movq %rsp, %rdi
callq 0x419c
jmp 0x3c71
movq %rsp, %rdi
callq 0x4144
jmp 0x3c71
cmpl $0x110002, %eax         # imm = 0x110002
jne 0x3c71
callq 0x318e
callq 0x31fe
jmp 0x3c6a
cmpl $0x3, %eax
jne 0x3c71
movb $0x1, %al
movb %al, 0x115(%rbp)
movb %al, 0x8(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
jmp 0x3c71
addq $0x28, %rsi
movq %rsp, %rdi
callq 0x3d11
movb $0x1, 0x115(%rbp)
cmpb $0x0, (%r15)
jne 0x3c82
testb $0x1, 0x8(%rsp)
je 0x38af
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
js 0x3cbf
movq 0x28(%rsp), %r8
testq %r8, %r8
je 0x3cba
movq 0x10(%rsp), %r14
addq $0x28, %r8
leaq 0x3884(%rip), %rdx      # 0x7528
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2100
jmp 0x3cc4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x3cd1
movq %r14, %rdi
callq 0x2030
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x3ceb
movq (%rdi), %rbx
callq 0x2030
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x3cdb
callq 0x318e
callq 0x31fe
movb $0x1, 0x115(%r15)
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq