// File: /workspace/github_cpp_makefile_star2_O2/Linkerist[P]xs/src/xs.cc
// Function: main
int
main(int argc, char ** argv)
{
 int c;
 int opt_idx = 0;

 char * arg = NULL;

 string optname;
 string argument;

 const static string xs_short_opts = "a:f:u:brco:hV";

 static struct option xs_long_opts[] = {
  {"help",      no_argument, NULL, 'h'},
  {"version",   no_argument, NULL, 'V'},
 
  {"browse",    no_argument, 0, 0},
  {"nowrap",    no_argument, 0, 0},
  {"noresolve", no_argument, 0, 0},
  {"output",    required_argument, 0, 0},
 
  {NULL, 0, NULL, 0}
 };

 while ((c = getopt_long(argc, argv, xs_short_opts.c_str(), xs_long_opts, &opt_idx)) != -1) {
  switch (c) {
   case 0:
    optname = string(xs_long_opts[opt_idx].name);

    if (optname == "help") {
     version();
     usage(EXIT_SUCCESS);
     exit(0);
    } else if (optname == "version") {
     version();
     exit(0);
    } else if(optname == "browse")
     mode = BROWSE;
    else if (optname == "nowrap")
     opt_no_wrap = true;
    else if (optname == "noresolve")
     opt_no_resolve = true;

    break;

   case 'b':
    mode = BROWSE;
    break;
   case 'r':
    opt_no_resolve = true;
    break;
   case 'h':
    version();
    usage(EXIT_SUCCESS);
    break;
   case 'V':
    version();
    exit(0);
   default:
    usage(EXIT_FAILURE);
  }
 }

 (void)arg;

 if (optind < argc) {
  Needle = argv[optind];
  if (strlen(Needle) > 0)
   NeedleGiven = true;
  
  if (strlen(Needle) == 1 && isdigit(Needle[0])) {
   CurrPosition = atoi(Needle);
   Needle = NULL;
  }

  //usage(EXIT_FAILURE);
 }

 // leave terminal tidy
 // FIXME: what other signals do I need to catch? 
 signal(SIGINT, terminate);
 signal(SIGTERM, terminate);
 signal(SIGSEGV, terminate);

 init_curses();

 // answer to terminal reizing
 signal(SIGWINCH, resizeevent);

 /* get list from file or start in browse mode */
 if (!list_from_file())
  /* doesn't exist. browse current dir */
  mode = BROWSE;

 // if we're browsing read the CWD
 if(mode == BROWSE)
  list_from_dir();

 /* main event loop */
 /* determines the entry to use */
 while (1) {
  display_list();
  c = getch();
  if (!user_interaction(c))
   break;
 }

 finish(current_entry(), true);
 exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
andl $0x0, 0x4(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %rbx
movl %edi, %ebp
xorl %ecx, %ecx
leaq 0x78(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
movb 0xa491(%rip), %al       # 0xe540
testb %al, %al
je 0x4303
leaq 0xa2b2(%rip), %r14      # 0xe370
leaq 0x4(%rsp), %r15
leaq 0x28(%rsp), %r13
movq 0xa451(%rip), %rdx      # 0xe520
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rcx
movq %r15, %r8
callq 0x35a0
testl %eax, %eax
je 0x4119
cmpl $0x62, %eax
je 0x418c
cmpl $0x68, %eax
je 0x419b
cmpl $0x72, %eax
je 0x41e6
cmpl $-0x1, %eax
je 0x41f2
pushq $0x1
popq %r12
cmpl $0x56, %eax
jne 0x41a3
jmp 0x4296
movslq 0x4(%rsp), %rax
shlq $0x5, %rax
movq (%rax,%r14), %rsi
leaq 0x48(%rsp), %r12
movq %r12, %rdi
leaq 0x3(%rsp), %rdx
callq 0x43c8
movq %r13, %rdi
movq %r12, %rsi
callq 0x33e0
movq %r12, %rdi
callq 0x36a8
movq %r13, %rdi
leaq 0x59f6(%rip), %rsi      # 0x9b4b
callq 0x4556
testb %al, %al
jne 0x429d
movq %r13, %rdi
leaq 0x4ff6(%rip), %rsi      # 0x9162
callq 0x4556
testb %al, %al
jne 0x42ab
movq %r13, %rdi
leaq 0x4fe7(%rip), %rsi      # 0x916a
callq 0x4556
testb %al, %al
je 0x41b0
movl $0x1, 0xa342(%rip)      # 0xe4d8
jmp 0x40c8
xorl %r12d, %r12d
callq 0x67a4
movl %r12d, %edi
callq 0x67b9
jmp 0x40c8
movq %r13, %rdi
leaq 0x4fb7(%rip), %rsi      # 0x9171
callq 0x4556
testb %al, %al
je 0x41cf
movb $0x1, 0xa313(%rip)      # 0xe4dd
jmp 0x40c8
movq %r13, %rdi
leaq 0x4f9f(%rip), %rsi      # 0x9178
callq 0x4556
testb %al, %al
je 0x40c8
movb $0x1, 0xa2f1(%rip)      # 0xe4de
jmp 0x40c8
movq 0x9dd7(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x4246
movq (%rbx,%rax,8), %rbx
movq %rbx, 0xa28d(%rip)      # 0xe498
cmpb $0x0, (%rbx)
je 0x4217
movb $0x1, 0xa289(%rip)      # 0xe4a0
movq %rbx, %rdi
callq 0x3160
cmpq $0x1, %rax
jne 0x4246
movsbl (%rbx), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x4246
movq %rbx, %rdi
callq 0x3550
movl %eax, 0xa266(%rip)      # 0xe4a4
andq $0x0, 0xa252(%rip)      # 0xe498
leaq -0x321(%rip), %rbx      # 0x3f2c
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x33a0
pushq $0xf
popq %rdi
movq %rbx, %rsi
callq 0x33a0
pushq $0xb
popq %rdi
movq %rbx, %rsi
callq 0x33a0
callq 0x6ad0
leaq -0x2bd(%rip), %rsi      # 0x3fbd
pushq $0x1c
popq %rdi
callq 0x33a0
callq 0x46cc
testb %al, %al
je 0x42b7
cmpl $0x1, 0xa246(%rip)      # 0xe4d8
je 0x42c1
jmp 0x42cd
callq 0x67a4
jmp 0x42b0
callq 0x67a4
xorl %edi, %edi
callq 0x67b9
jmp 0x42b0
callq 0x67a4
xorl %edi, %edi
callq 0x33c0
movl $0x1, 0xa217(%rip)      # 0xe4d8
leaq 0x4eec(%rip), %rdi      # 0x91b4
callq 0x4a75
movq 0x9cec(%rip), %rbx      # 0xdfc0
callq 0x79a6
movq (%rbx), %rdi
callq 0x3130
movl %eax, %edi
callq 0x6b21
testb %al, %al
jne 0x42d4
leaq 0x8(%rsp), %rdi
callq 0x53b7
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x3dc7
leaq 0xa236(%rip), %rdi      # 0xe540
callq 0x35f0
testl %eax, %eax
je 0x40b7
leaq 0xa202(%rip), %rdi      # 0xe520
leaq 0x4e2f(%rip), %rsi      # 0x9154
leaq 0x48(%rsp), %rdx
callq 0x43c8
movq 0x9c7a(%rip), %rdi      # 0xdfb0
leaq 0xa1e3(%rip), %rsi      # 0xe520
leaq 0xa014(%rip), %rdx      # 0xe358
callq 0x32d0
leaq 0xa1f0(%rip), %rdi      # 0xe540
callq 0x3220
jmp 0x40b7
movq %rax, %rbx
leaq 0xa1dc(%rip), %rdi      # 0xe540
callq 0x3210
jmp 0x4383
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x36a8
jmp 0x4383
jmp 0x4380
jmp 0x4380
jmp 0x4380
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x36a8
leaq 0x28(%rsp), %rdi
callq 0x36a8
movq %rbx, %rdi
callq 0x35d0
nop