// File: /workspace/github_c_makefile_star2_O3/kobolt[P]curses-collection/fileselect/fileselect.c
// Function: main
int main(int argc, char *argv[])
{
  file_node_t *root;
  char *root_dir;
  FILE *fh;

  if (argc < 2) {
     fprintf(stderr, "Usage: %s <output file> [directory]\n", argv[0]);
     return 1;
  }

  fh = fopen(argv[1], "wx");
  if (fh == NULL) {
     fprintf(stderr, "Error: Cannot open file, or it exists already: %s\n", argv[1]);
     return 1;
  }

  if (argc > 2) {
    root_dir = argv[2];
  } else {
    root_dir = ".";
  }

  root = file_node_new(NULL, NULL, FILE_NODE_TYPE_ROOT);
  if (root == NULL) {
    fclose(fh);
    return 1;
  }

  if (file_node_scan(root, root_dir) != 0) {
    file_node_remove(root);
    fclose(fh);
    return 1;
  }

  file_node_sort(root);

  if (isatty(STDOUT_FILENO)) {
    file_node_curses_loop(root);
    file_node_print_marked(root, root_dir, fh);
  } else {
    /* Mostly for debugging. */
    file_node_dump(root);
  }

  file_node_remove(root);
  fclose(fh);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
cmpl $0x1, %edi
jle 0x16ad
movl %edi, %ebp
movq 0x8(%r14), %rdi
leaq 0xc96(%rip), %rsi       # 0x2029
callq 0x11b0
testq %rax, %rax
je 0x16ba
movq %rax, %rbx
cmpl $0x2, %ebp
jne 0x13b2
leaq 0xcaf(%rip), %r15       # 0x205f
jmp 0x13b6
movq 0x10(%r14), %r15
movl $0x30, %edi
callq 0x1190
testq %rax, %rax
je 0x13f8
movq %rax, %r14
xorl %eax, %eax
movq %rax, 0x8(%r14)
movl %eax, 0x10(%r14)
movq %rax, 0x18(%r14)
movl %eax, 0x20(%r14)
movq %rax, 0x28(%r14)
movl %eax, (%r14)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1751
testl %eax, %eax
je 0x140a
movq %r14, %rdi
callq 0x188a
movq %rbx, %rdi
callq 0x10b0
movl $0x1, %eax
jmp 0x169e
movq %r14, %rdi
callq 0x18d8
movl $0x1, %edi
callq 0x1090
testl %eax, %eax
je 0x1684
movq %r15, 0x10(%rsp)
callq 0x1110
leaq 0x65e(%rip), %rdi       # 0x1a93
callq 0x1f80
callq 0x10e0
movq 0x2b92(%rip), %r13      # 0x3fd8
movq (%r13), %rdi
movl $0x1, %esi
callq 0x1130
leaq 0xc(%rsp), %r12
movq %r14, %rdi
callq 0x1a98
movl %eax, %ebp
movq %r14, %rdi
callq 0x1ada
movq (%r13), %rdi
testq %rdi, %rdi
je 0x147e
movswl 0x4(%rdi), %r15d
incl %r15d
jmp 0x1484
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
callq 0x10a0
cmpl $0x14a, %eax            # imm = 0x14A
jg 0x14b2
cmpl $0x50, %eax
jg 0x14fb
cmpl $0x1a, %eax
jg 0x1575
cmpl $0xa, %eax
je 0x15ae
cmpl $0xd, %eax
je 0x15ae
jmp 0x1459
cmpl $0x152, %eax            # imm = 0x152
jle 0x1523
cmpl $0x153, %eax            # imm = 0x153
je 0x162b
cmpl $0x157, %eax            # imm = 0x157
je 0x15ae
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x1459
callq 0x1200
movq %r14, %rdi
callq 0x1ada
callq 0x1060
movq (%r13), %rdi
movl $0x1, %esi
callq 0x1130
jmp 0x1459
cmpl $0x102, %eax            # imm = 0x102
jg 0x15e5
je 0x15ae
cmpl $0x51, %eax
je 0x1672
cmpl $0x71, %eax
jne 0x1459
jmp 0x1672
cmpl $0x14b, %eax            # imm = 0x14B
je 0x157e
cmpl $0x152, %eax            # imm = 0x152
jne 0x1459
movl %r15d, %eax
shrl $0x1f, %eax
addl %r15d, %eax
sarl %eax
addl %r15d, %eax
addl 0x2be7(%rip), %eax      # 0x4130
cmpl %eax, %ebp
jl 0x154f
movl %eax, %ebp
subl %r15d, %ebp
testl %ebp, %ebp
jg 0x1558
xorl %ebp, %ebp
movl %ebp, 0x2bd2(%rip)      # 0x4130
cmpl %ebp, 0x2bc8(%rip)      # 0x412c
jge 0x1459
movl %ebp, 0x2bbc(%rip)      # 0x412c
jmp 0x1459
cmpl $0x20, %eax
jne 0x1669
movl 0x2ba8(%rip), %esi      # 0x412c
incl %esi
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
movq %r12, %rdx
callq 0x1e8e
testq %rax, %rax
je 0x15ae
cmpl $0x2, 0x10(%rax)
jne 0x15ae
xorl %ecx, %ecx
cmpl $0x0, (%rax)
sete %cl
movl %ecx, (%rax)
movl 0x2b78(%rip), %eax      # 0x412c
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
cmovll %ecx, %eax
movl %eax, 0x2b6a(%rip)      # 0x412c
subl %r15d, %eax
jl 0x1459
movl 0x2b5f(%rip), %ecx      # 0x4130
xorl %edx, %edx
cmpl %eax, %ecx
setle %dl
addl %ecx, %edx
movl %edx, 0x2b50(%rip)      # 0x4130
jmp 0x1459
cmpl $0x103, %eax            # imm = 0x103
jne 0x1459
movl 0x2b36(%rip), %ecx      # 0x412c
xorl %eax, %eax
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x2b27(%rip)      # 0x412c
movl 0x2b25(%rip), %eax      # 0x4130
cmpl %ecx, %eax
jle 0x1459
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x2b0a(%rip)      # 0x4130
jmp 0x1459
movl %r15d, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
sarl %ecx
movl 0x2af4(%rip), %eax      # 0x4130
subl %ecx, %eax
testl %eax, %eax
jg 0x1644
xorl %eax, %eax
movl %eax, 0x2ae6(%rip)      # 0x4130
addl %eax, %r15d
cmpl %r15d, 0x2ad8(%rip)     # 0x412c
jl 0x1459
decl %r15d
movl %r15d, 0x2ac8(%rip)     # 0x412c
jmp 0x1459
cmpl $0x1b, %eax
jne 0x1459
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1920
jmp 0x168c
movq %r14, %rdi
callq 0x1999
movq %r14, %rdi
callq 0x188a
movq %rbx, %rdi
callq 0x10b0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x125e
jmp 0x1400
addq $0x8, %r14
movq %r14, %rdi
callq 0x1240
jmp 0x1400