// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsi, %rbx
movl %edi, %ebp
movl $0x0, 0x4(%rsp)
leaq 0x18(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x78(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movb 0x9fd9(%rip), %al       # 0xe550
testb %al, %al
je 0x47e9
leaq 0x9dfa(%rip), %r14      # 0xe380
leaq 0x4(%rsp), %r15
leaq 0x8(%rsp), %r13
movq 0x9f99(%rip), %rdx      # 0xe530
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rcx
movq %r15, %r8
callq 0x35e0
movl $0x1, %r12d
cmpl $0x61, %eax
jg 0x4671
testl %eax, %eax
jne 0x469b
movslq 0x4(%rsp), %rax
shlq $0x5, %rax
movq (%rax,%r14), %rsi
leaq 0x48(%rsp), %r12
movq %r12, %rdi
leaq 0x3(%rsp), %rdx
callq 0x4900
movq %r13, %rdi
movq %r12, %rsi
callq 0x3430
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4604
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3350
movq %r13, %rdi
leaq 0x653d(%rip), %rsi      # 0xab4b
callq 0x30e0
testl %eax, %eax
je 0x4781
movq %r13, %rdi
leaq 0x5b3a(%rip), %rsi      # 0xa15f
callq 0x30e0
testl %eax, %eax
je 0x478f
movq %r13, %rdi
leaq 0x5b2b(%rip), %rsi      # 0xa167
callq 0x30e0
testl %eax, %eax
je 0x468c
movq %r13, %rdi
leaq 0x5b1f(%rip), %rsi      # 0xa16e
callq 0x30e0
testl %eax, %eax
je 0x46bf
movq %r13, %rdi
leaq 0x5b13(%rip), %rsi      # 0xa175
callq 0x30e0
testl %eax, %eax
jne 0x4590
jmp 0x4680
cmpl $0x62, %eax
je 0x468c
cmpl $0x68, %eax
je 0x46aa
cmpl $0x72, %eax
jne 0x46b2
movb $0x1, 0x9e67(%rip)      # 0xe4ee
jmp 0x4590
movl $0x1, 0x9e52(%rip)      # 0xe4e8
jmp 0x4590
cmpl $-0x1, %eax
je 0x46cb
cmpl $0x56, %eax
jne 0x46b2
jmp 0x477a
xorl %r12d, %r12d
callq 0x7ac4
movl %r12d, %edi
callq 0x7ad9
jmp 0x4590
movb $0x1, 0x9e27(%rip)      # 0xe4ed
jmp 0x4590
movq 0x98fe(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x4722
movq (%rbx,%rax,8), %rbx
movq %rbx, 0x9dc4(%rip)      # 0xe4a8
cmpb $0x0, (%rbx)
je 0x46f0
movb $0x1, 0x9dc0(%rip)      # 0xe4b0
movq %rbx, %rdi
callq 0x3180
cmpq $0x1, %rax
jne 0x4722
movsbl (%rbx), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x4722
movq %rbx, %rdi
callq 0x35a0
movl %eax, 0x9d9d(%rip)      # 0xe4b4
movq $0x0, 0x9d86(%rip) # 0xe4a8
leaq -0x346(%rip), %rbx      # 0x43e3
movl $0x2, %edi
movq %rbx, %rsi
callq 0x33f0
movl $0xf, %edi
movq %rbx, %rsi
callq 0x33f0
movl $0xb, %edi
movq %rbx, %rsi
callq 0x33f0
callq 0x7e8c
leaq -0x2da(%rip), %rsi      # 0x4482
movl $0x1c, %edi
callq 0x33f0
callq 0x4ba4
testb %al, %al
je 0x479b
cmpl $0x1, 0x9d72(%rip)      # 0xe4e8
je 0x47a5
jmp 0x47b1
callq 0x7ac4
jmp 0x4794
callq 0x7ac4
xorl %edi, %edi
callq 0x7ad9
jmp 0x4794
callq 0x7ac4
xorl %edi, %edi
callq 0x3410
movl $0x1, 0x9d43(%rip)      # 0xe4e8
leaq 0x5a05(%rip), %rdi      # 0xa1b1
callq 0x5102
movq 0x9808(%rip), %rbx      # 0xdfc0
callq 0x9289
movq (%rbx), %rdi
callq 0x3150
movl %eax, %edi
callq 0x7ed7
testb %al, %al
jne 0x47b8
leaq 0x28(%rsp), %rdi
callq 0x606d
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x41e8
leaq 0x9d60(%rip), %rdi      # 0xe550
callq 0x3640
testl %eax, %eax
je 0x457f
leaq 0x9d3c(%rip), %rax      # 0xe540
movq %rax, 0x9d25(%rip)      # 0xe530
leaq 0x9d1e(%rip), %rdi      # 0xe530
leaq 0x5938(%rip), %rsi      # 0xa151
leaq 0x593e(%rip), %rdx      # 0xa15e
callq 0x4b0e
movq 0x977c(%rip), %rdi      # 0xdfa8
leaq 0x9cfd(%rip), %rsi      # 0xe530
leaq 0x9b2e(%rip), %rdx      # 0xe368
callq 0x32f0
leaq 0x9d0a(%rip), %rdi      # 0xe550
callq 0x3220
jmp 0x457f
movq %rax, %rbx
leaq 0x9cf6(%rip), %rdi      # 0xe550
callq 0x3210
jmp 0x488a
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x488a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3350
jmp 0x488a
jmp 0x4887
jmp 0x4887
jmp 0x4887
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x48a6
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3350
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x48c2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3350
movq %rbx, %rdi
callq 0x3620