// File: /workspace/github_c_makefile_star2_O2/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 0x1614
movl %edi, %ebp
movq 0x8(%r14), %rdi
leaq 0xcd6(%rip), %rsi       # 0x2029
callq 0x11b0
testq %rax, %rax
je 0x162a
movq %rax, %rbx
cmpl $0x2, %ebp
jne 0x1372
leaq 0xcef(%rip), %r14       # 0x205f
jmp 0x1376
movq 0x10(%r14), %r14
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x164b
testq %rax, %rax
je 0x13a0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x16ca
testl %eax, %eax
je 0x13b0
movq %r15, %rdi
callq 0x17ed
movq %rbx, %rdi
callq 0x10b0
pushq $0x1
popq %rax
jmp 0x1605
movq %r15, %rdi
callq 0x182e
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x1090
testl %eax, %eax
je 0x15eb
movq %r14, 0x10(%rsp)
callq 0x1110
leaq 0x5e5(%rip), %rdi       # 0x19c0
callq 0x1e70
callq 0x10e0
movq 0x2bec(%rip), %r14      # 0x3fd8
movq (%r14), %rdi
movl %ebp, %esi
callq 0x1130
pushq $-0x1
popq %r12
movq %r15, %rdi
callq 0x19c5
movl %eax, %ebp
movq %r15, %rdi
callq 0x1a07
movq (%r14), %rdi
movl %r12d, %r13d
testq %rdi, %rdi
je 0x141f
movswl 0x4(%rdi), %r13d
incl %r13d
callq 0x10a0
cmpl $0xa, %eax
je 0x14cf
cmpl $0xd, %eax
je 0x14cf
cmpl $0x20, %eax
je 0x14a0
cmpl $0x102, %eax            # imm = 0x102
je 0x14cf
cmpl $0x103, %eax            # imm = 0x103
je 0x15a0
cmpl $0x14b, %eax            # imm = 0x14B
je 0x14a0
cmpl $0x152, %eax            # imm = 0x152
je 0x1506
cmpl $0x153, %eax            # imm = 0x153
je 0x1566
cmpl $0x157, %eax            # imm = 0x157
je 0x14cf
cmpl $0x19a, %eax            # imm = 0x19A
je 0x1544
cmpl $0x1b, %eax
je 0x15d9
cmpl $0x51, %eax
je 0x15d9
cmpl $0x71, %eax
jne 0x13fa
jmp 0x15d9
movl 0x2c86(%rip), %esi      # 0x412c
incl %esi
andl $0x0, 0xc(%rsp)
movq %r15, %rdi
leaq 0xc(%rsp), %rdx
callq 0x1d77
testq %rax, %rax
je 0x14cf
cmpl $0x2, 0x10(%rax)
jne 0x14cf
xorl %ecx, %ecx
cmpl $0x0, (%rax)
sete %cl
movl %ecx, (%rax)
movl 0x2c57(%rip), %eax      # 0x412c
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
cmovll %ecx, %eax
movl %eax, 0x2c49(%rip)      # 0x412c
subl %r13d, %eax
jl 0x13fa
movl 0x2c3e(%rip), %ecx      # 0x4130
xorl %edx, %edx
cmpl %eax, %ecx
setle %dl
addl %ecx, %edx
movl %edx, 0x2c2f(%rip)      # 0x4130
jmp 0x13fa
movl %r13d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
addl %r13d, %eax
addl 0x2c18(%rip), %eax      # 0x4130
cmpl %eax, %ebp
jl 0x151e
movl %eax, %ebp
subl %r13d, %ebp
testl %ebp, %ebp
jg 0x1527
xorl %ebp, %ebp
movl %ebp, 0x2c03(%rip)      # 0x4130
cmpl %ebp, 0x2bf9(%rip)      # 0x412c
jge 0x13fa
movl %ebp, 0x2bed(%rip)      # 0x412c
jmp 0x13fa
callq 0x1200
movq %r15, %rdi
callq 0x1a07
callq 0x1060
movq (%r14), %rdi
pushq $0x1
popq %rsi
callq 0x1130
jmp 0x13fa
movl %r13d, %eax
cltd
pushq $-0x2
popq %rcx
idivl %ecx
addl 0x2bbb(%rip), %eax      # 0x4130
testl %eax, %eax
jg 0x157b
xorl %eax, %eax
movl %eax, 0x2baf(%rip)      # 0x4130
addl %eax, %r13d
cmpl %r13d, 0x2ba1(%rip)     # 0x412c
jl 0x13fa
decl %r13d
movl %r13d, 0x2b91(%rip)     # 0x412c
jmp 0x13fa
movl 0x2b86(%rip), %ecx      # 0x412c
xorl %eax, %eax
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x2b77(%rip)      # 0x412c
movl 0x2b75(%rip), %eax      # 0x4130
cmpl %ecx, %eax
jle 0x13fa
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovll %ecx, %eax
decl %eax
movl %eax, 0x2b5c(%rip)      # 0x4130
jmp 0x13fa
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1870
jmp 0x15f3
movq %r15, %rdi
callq 0x18e4
movq %r15, %rdi
callq 0x17ed
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 0x29dd(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%r14), %rdx
leaq 0x9dc(%rip), %rsi       # 0x2004
jmp 0x163f
movq 0x29c7(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x8(%r14), %rdx
leaq 0x9ed(%rip), %rsi       # 0x202c
xorl %eax, %eax
callq 0x1160
jmp 0x13a8