// File: /workspace/github_c_makefile_star2_O1/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 0x16b3
movl %edi, %ebp
movq 0x8(%r14), %rdi
leaq 0xc96(%rip), %rsi       # 0x2029
callq 0x11b0
testq %rax, %rax
je 0x16c0
movq %rax, %rbx
cmpl $0x2, %ebp
jne 0x13b2
leaq 0xcaf(%rip), %r15       # 0x205f
jmp 0x13b6
movq 0x10(%r14), %r15
movl $0x30, %edi
callq 0x1190
xorl %r14d, %r14d
testq %rax, %rax
je 0x13e2
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movq %r14, 0x18(%rax)
movl %r14d, 0x20(%rax)
movq %r14, 0x28(%rax)
movl %r14d, (%rax)
movq %rax, %r14
testq %r14, %r14
je 0x13fe
movq %r14, %rdi
movq %r15, %rsi
callq 0x174f
testl %eax, %eax
je 0x1410
movq %r14, %rdi
callq 0x1888
movq %rbx, %rdi
callq 0x10b0
movl $0x1, %eax
jmp 0x16a4
movq %r14, %rdi
callq 0x18d6
movl $0x1, %edi
callq 0x1090
testl %eax, %eax
je 0x168a
movq %r15, 0x10(%rsp)
callq 0x1110
leaq 0x65d(%rip), %rdi       # 0x1a98
callq 0x1f70
callq 0x10e0
movq 0x2b8c(%rip), %r13      # 0x3fd8
movq (%r13), %rdi
movl $0x1, %esi
callq 0x1130
leaq 0xc(%rsp), %r12
movq %r14, %rdi
callq 0x1a9d
movl %eax, %ebp
movq %r14, %rdi
callq 0x1adf
movq (%r13), %rdi
testq %rdi, %rdi
je 0x1484
movswl 0x4(%rdi), %r15d
incl %r15d
jmp 0x148a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
callq 0x10a0
cmpl $0x14a, %eax            # imm = 0x14A
jg 0x14b8
cmpl $0x50, %eax
jg 0x1501
cmpl $0x1a, %eax
jg 0x157b
cmpl $0xa, %eax
je 0x15b4
cmpl $0xd, %eax
je 0x15b4
jmp 0x145f
cmpl $0x152, %eax            # imm = 0x152
jle 0x1529
cmpl $0x153, %eax            # imm = 0x153
je 0x1631
cmpl $0x157, %eax            # imm = 0x157
je 0x15b4
cmpl $0x19a, %eax            # imm = 0x19A
jne 0x145f
callq 0x1200
movq %r14, %rdi
callq 0x1adf
callq 0x1060
movq (%r13), %rdi
movl $0x1, %esi
callq 0x1130
jmp 0x145f
cmpl $0x102, %eax            # imm = 0x102
jg 0x15eb
je 0x15b4
cmpl $0x51, %eax
je 0x1678
cmpl $0x71, %eax
jne 0x145f
jmp 0x1678
cmpl $0x14b, %eax            # imm = 0x14B
je 0x1584
cmpl $0x152, %eax            # imm = 0x152
jne 0x145f
movl %r15d, %eax
shrl $0x1f, %eax
addl %r15d, %eax
sarl %eax
addl %r15d, %eax
addl 0x2be1(%rip), %eax      # 0x4130
cmpl %eax, %ebp
jl 0x1555
movl %eax, %ebp
subl %r15d, %ebp
testl %ebp, %ebp
jg 0x155e
xorl %ebp, %ebp
movl %ebp, 0x2bcc(%rip)      # 0x4130
cmpl %ebp, 0x2bc2(%rip)      # 0x412c
jge 0x145f
movl %ebp, 0x2bb6(%rip)      # 0x412c
jmp 0x145f
cmpl $0x20, %eax
jne 0x166f
movl 0x2ba2(%rip), %esi      # 0x412c
incl %esi
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
movq %r12, %rdx
callq 0x1e83
testq %rax, %rax
je 0x15b4
cmpl $0x2, 0x10(%rax)
jne 0x15b4
xorl %ecx, %ecx
cmpl $0x0, (%rax)
sete %cl
movl %ecx, (%rax)
movl 0x2b72(%rip), %eax      # 0x412c
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
cmovll %ecx, %eax
movl %eax, 0x2b64(%rip)      # 0x412c
subl %r15d, %eax
jl 0x145f
movl 0x2b59(%rip), %ecx      # 0x4130
xorl %edx, %edx
cmpl %eax, %ecx
setle %dl
addl %ecx, %edx
movl %edx, 0x2b4a(%rip)      # 0x4130
jmp 0x145f
cmpl $0x103, %eax            # imm = 0x103
jne 0x145f
movl 0x2b30(%rip), %ecx      # 0x412c
xorl %eax, %eax
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x2b21(%rip)      # 0x412c
movl 0x2b1f(%rip), %eax      # 0x4130
cmpl %ecx, %eax
jle 0x145f
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x2b04(%rip)      # 0x4130
jmp 0x145f
movl %r15d, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
sarl %ecx
movl 0x2aee(%rip), %eax      # 0x4130
subl %ecx, %eax
testl %eax, %eax
jg 0x164a
xorl %eax, %eax
movl %eax, 0x2ae0(%rip)      # 0x4130
addl %eax, %r15d
cmpl %r15d, 0x2ad2(%rip)     # 0x412c
jl 0x145f
decl %r15d
movl %r15d, 0x2ac2(%rip)     # 0x412c
jmp 0x145f
cmpl $0x1b, %eax
jne 0x145f
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x191e
jmp 0x1692
movq %r14, %rdi
callq 0x1997
movq %r14, %rdi
callq 0x1888
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 0x1406
addq $0x8, %r14
movq %r14, %rdi
callq 0x1240
jmp 0x1406