// File: /workspace/github_cpp_makefile_star2_O1/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 0x9fd8(%rip), %al       # 0xe550
testb %al, %al
je 0x47e8
leaq 0x9df9(%rip), %r14      # 0xe380
leaq 0x4(%rsp), %r15
leaq 0x8(%rsp), %r13
movq 0x9f98(%rip), %rdx      # 0xe530
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rcx
movq %r15, %r8
callq 0x35e0
movl $0x1, %r12d
cmpl $0x61, %eax
jg 0x4672
testl %eax, %eax
jne 0x469c
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 0x4605
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3350
movq %r13, %rdi
leaq 0x653c(%rip), %rsi      # 0xab4b
callq 0x30e0
testl %eax, %eax
je 0x47ce
movq %r13, %rdi
leaq 0x5b39(%rip), %rsi      # 0xa15f
callq 0x30e0
testl %eax, %eax
je 0x47dc
movq %r13, %rdi
leaq 0x5b2a(%rip), %rsi      # 0xa167
callq 0x30e0
testl %eax, %eax
je 0x468d
movq %r13, %rdi
leaq 0x5b1e(%rip), %rsi      # 0xa16e
callq 0x30e0
testl %eax, %eax
je 0x46c0
movq %r13, %rdi
leaq 0x5b12(%rip), %rsi      # 0xa175
callq 0x30e0
testl %eax, %eax
jne 0x4591
jmp 0x4681
cmpl $0x62, %eax
je 0x468d
cmpl $0x68, %eax
je 0x46ab
cmpl $0x72, %eax
jne 0x46b3
movb $0x1, 0x9e66(%rip)      # 0xe4ee
jmp 0x4591
movl $0x1, 0x9e51(%rip)      # 0xe4e8
jmp 0x4591
cmpl $-0x1, %eax
je 0x46cc
cmpl $0x56, %eax
jne 0x46b3
jmp 0x47c7
xorl %r12d, %r12d
callq 0x7ae8
movl %r12d, %edi
callq 0x7afd
jmp 0x4591
movb $0x1, 0x9e26(%rip)      # 0xe4ed
jmp 0x4591
movq 0x98fd(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x4723
movq (%rbx,%rax,8), %rbx
movq %rbx, 0x9dc3(%rip)      # 0xe4a8
cmpb $0x0, (%rbx)
je 0x46f1
movb $0x1, 0x9dbf(%rip)      # 0xe4b0
movq %rbx, %rdi
callq 0x3180
cmpq $0x1, %rax
jne 0x4723
movsbl (%rbx), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x4723
movq %rbx, %rdi
callq 0x35a0
movl %eax, 0x9d9c(%rip)      # 0xe4b4
movq $0x0, 0x9d85(%rip) # 0xe4a8
leaq -0x346(%rip), %rbx      # 0x43e4
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 0x7eb3
leaq -0x2da(%rip), %rsi      # 0x4483
movl $0x1c, %edi
callq 0x33f0
callq 0x4b98
testb %al, %al
jne 0x477a
movl $0x1, 0x9d6e(%rip)      # 0xe4e8
cmpl $0x1, 0x9d67(%rip)      # 0xe4e8
jne 0x478f
leaq 0x5a27(%rip), %rdi      # 0xa1b1
callq 0x50fa
movq 0x982a(%rip), %rbx      # 0xdfc0
callq 0x92c0
movq (%rbx), %rdi
callq 0x3150
movl %eax, %edi
callq 0x7efe
testb %al, %al
jne 0x4796
leaq 0x28(%rsp), %rdi
callq 0x6045
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x41e9
callq 0x7ae8
jmp 0x47e1
callq 0x7ae8
xorl %edi, %edi
callq 0x7afd
jmp 0x47e1
callq 0x7ae8
xorl %edi, %edi
callq 0x3410
leaq 0x9d61(%rip), %rdi      # 0xe550
callq 0x3640
testl %eax, %eax
je 0x4580
leaq 0x9d3d(%rip), %rax      # 0xe540
movq %rax, 0x9d26(%rip)      # 0xe530
leaq 0x9d1f(%rip), %rdi      # 0xe530
leaq 0x5939(%rip), %rsi      # 0xa151
leaq 0x593f(%rip), %rdx      # 0xa15e
callq 0x4b08
movq 0x977d(%rip), %rdi      # 0xdfa8
leaq 0x9cfe(%rip), %rsi      # 0xe530
leaq 0x9b2f(%rip), %rdx      # 0xe368
callq 0x32f0
leaq 0x9d0b(%rip), %rdi      # 0xe550
callq 0x3220
jmp 0x4580
movq %rax, %rbx
leaq 0x9cf7(%rip), %rdi      # 0xe550
callq 0x3210
jmp 0x4889
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4889
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3350
jmp 0x4889
jmp 0x4886
jmp 0x4886
jmp 0x4886
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x48a5
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3350
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x48c1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3350
movq %rbx, %rdi
callq 0x3620
nop