// File: /workspace/github_cpp_makefile_star2_O1/afinit[P]afin/afin.cpp
// Function: main
int main( int argc, char** argv ){
  //////////////////////////////////
  // Process Command Line Options //
  //////////////////////////////////
  max_search_loops = 10;
  contig_sub_len = 100;
  extend_len = 40;
  max_sort_char = 4;
  min_cov = 3;
  min_overlap = 20;
  max_threads = 4;
  initial_trim = 0;
  max_missed = 5;
  stop_ext = .5;
  mismatch_threshold = 0.1;
  test_run = false;
  print_fused = 0;
  screen_output = 1;
  log_output = 1;
  verbose = 0;
  no_fusion = 0;

  int c;
  bool quit_flag = false;
  Process process;
  
  // initialize global Log object
  Log::Inst();
  
  // prevent output to stderr if erroneous option is found
  opterr = 0;
  
  int option_index = 0;

  static struct option long_options[] =
  {
    {"silent",        no_argument,  &screen_output, 0},
    {"no_log",        no_argument,  &log_output,  0},
    {"no_fusion",     no_argument,  &no_fusion,  1},
    {"verbose",       no_argument,  &verbose,  1},
    {"print_fused",   no_argument,  &print_fused, 1},
    {"contigsfiles",  required_argument,  0,  'c'},
    {"readsfiles",    required_argument,  0,  'r'},
    {"outfile",       required_argument,  0,  'o'},
    {"sort_char",     required_argument,  0,  'm'},
    {"sub_len",       required_argument,  0,  's'},
    {"search_loops",  required_argument,  0,  'l'},
    {"min_cov",       required_argument,  0,  'i'},
    {"min_overlap",   required_argument,  0,  'p'},
    {"max_threads",   required_argument,  0,  't'},
    {"initial_trim",  required_argument,  0,  'd'},
    {"max_missed",    required_argument,  0,  'e'},
    {"mismatch",      required_argument,  0,  'g'},
    {"extend_len",    required_argument,  0,  'x'},
    {"stop_ext",      required_argument,  0,  'f'},
    {"help",          no_argument,        0,  'h'},
    {"test_run",      no_argument,        0,  'z'},
    {0, 0, 0, 0}
  };
  
  // get all options that have been provided on the command line
  while (( c = getopt_long(argc, argv, "hr:c:o:s:l:x:m:i:p:t:d:e:f:g:z", long_options, &option_index )) != -1 ) {
    switch( c ) {
      case 0:
        /* If this option set a flag, do nothing else now. */
        if (long_options[option_index].flag != 0)
          break;
        printf ("option %s", long_options[option_index].name);
        if (optarg)
          printf (" with arg %s", optarg);
        printf ("\n");
        break;
      case 'h':
        print_usage( argv[0] );
        exit(0);
        break;
      // max_sort_char option
      case 'm':
        max_sort_char = atoi(optarg);
        break;
      // contig_sub_len option
      case 's':
        contig_sub_len = atoi(optarg);
        break;
      // extend_len option
      case 'x':
        extend_len = atoi(optarg);
        break;
      // max_sort_char option
      case 'l':
        max_search_loops = atoi(optarg);
        break;
      // min_cov option
      case 'i':
        min_cov = atoi(optarg);
        break;
      // min_overlap option
      case 'p':
        min_overlap = atoi(optarg);
        break;
      // max_threads option
      case 't':
        max_threads = atoi(optarg);
        break;
      // initial_trim option
      case 'd':
        initial_trim = atoi(optarg);
        break;
      // max_missed option
      case 'e':
        max_missed = atoi(optarg);
        break;
      // stop_ext option
      case 'f':
        stop_ext = atof(optarg);
        break;
      // mismatch_threshold option
      case 'g':
        mismatch_threshold = atof(optarg);
        break;
      // outputfile option
      case 'o':
        process.outfile = optarg;
        break;
      // readfile option
      case 'r':
        optind--;
        // loop through each file
        while ( optind < argc && argv[optind][0] != '-' ) { 
          if( process.readsfiles != "" ){
            process.readsfiles.append( "," );
          }
          process.readsfiles.append( argv[optind] );
          optind++;
        }   
        break;
      // contig file option
      case 'c':
        optind--;
        // loop through each file
        while ( optind < argc && argv[optind][0] != '-' ) { 
          if( process.contigsfiles != "" ){
            process.contigsfiles.append( "," );
          }
          process.contigsfiles.append( argv[optind] );
          optind++;
        }   
        break;
      // test_run option
      case 'z':
        test_run = true;
        break;
      case '?':
        if ( optopt == 'r' ){
          fprintf( stderr, "%s: Error: Option -r requires an argument. ", argv[0] );
          print_usage( argv[0] );
        }
        else if ( optopt == 'o' ){
          fprintf( stderr, "%s: Error: Option -o requires an argument. ", argv[0] );
          print_usage( argv[0] );
        }
        else if ( optopt == 'c' ){
          fprintf( stderr, "%s: Error: Option -c requires an argument. ", argv[0] );
          print_usage( argv[0] );
        }
        else if ( isprint( optopt )){
          fprintf( stderr, "%s: Error: Unknown option -%c. \n", argv[0], optopt );
          print_usage( argv[0] );
        }
        else{
          fprintf( stderr, "%s: Error: Unknown option character %x.\n", argv[0], optopt );
          print_usage( argv[0] );
        }
        return 1;
      default:
        abort();
    }
  }
  
  /////////////////
  // End Options //
  /////////////////

  //////////////////
  // Input Errors //
  //////////////////
  if( process.contigsfiles == "" ){
    fprintf( stderr, "%s: Error: contigsfile(s) must be provided.\n", argv[0] );
    quit_flag = true;
  }

  if( process.readsfiles == "" ){
    fprintf( stderr, "%s: Error: readsfile(s) must be provided.\n", argv[0] );
    quit_flag = true;
  }

  if( min_overlap < max_sort_char ){
    fprintf( stderr, "%s: Error: min_overlap must be >= max_sort_char.\n", argv[0] );
    quit_flag = true;
  }

  if( quit_flag ){
    exit(1);
  }

  ////////////////
  // End Errors //
  ////////////////

  // start run
  process.start_run();

  Log::Inst()->close_log();
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x184e4(%rip), %rax     # 0x1d608
movl $0xa, (%rax)
leaq 0x184db(%rip), %rax     # 0x1d60c
movl $0x64, (%rax)
leaq 0x184d2(%rip), %rax     # 0x1d610
movl $0x28, (%rax)
leaq 0x184c9(%rip), %rcx     # 0x1d614
movl $0x4, %eax
movl %eax, (%rcx)
leaq 0x184bf(%rip), %rcx     # 0x1d618
movl $0x3, (%rcx)
leaq 0x184b6(%rip), %rcx     # 0x1d61c
movl $0x14, (%rcx)
leaq 0x184ad(%rip), %rcx     # 0x1d620
movl %eax, (%rcx)
xorl %r15d, %r15d
leaq 0x184b1(%rip), %rcx     # 0x1d630
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, (%rcx)
leaq 0x184ad(%rip), %rax     # 0x1d640
movl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x184a3(%rip), %rax     # 0x1d644
movl %ecx, (%rax)
leaq 0x184a6(%rip), %rcx     # 0x1d650
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, (%rcx)
leaq 0x1847e(%rip), %rax     # 0x1d63c
movl %r15d, (%rax)
leaq 0x18480(%rip), %rax     # 0x1d648
movl %r15d, (%rax)
leaq 0x1847a(%rip), %rax     # 0x1d64c
movl %r15d, (%rax)
leaq 0x18448(%rip), %rax     # 0x1d624
movl %r15d, (%rax)
leaq 0x18442(%rip), %rax     # 0x1d628
movl $0x5, (%rax)
leaq 0x18445(%rip), %rax     # 0x1d638
movb $0x0, (%rax)
leaq -0x168(%rbp), %rdi
callq 0x6bf8
callq 0x9626
movq 0x17dca(%rip), %rax     # 0x1cfd8
movl %r15d, (%rax)
leaq -0x30(%rbp), %rax
movl %r15d, (%rax)
leaq -0x110(%rbp), %r15
movq 0x17daa(%rip), %r13     # 0x1cfd0
movl %r14d, %edi
movq %rbx, %rsi
leaq 0x1082b(%rip), %rdx     # 0x15a5e
leaq 0x180f6(%rip), %rcx     # 0x1d330
leaq -0x30(%rbp), %r8
callq 0x4550
cmpl $0x62, %eax
jle 0x52c5
addl $-0x63, %eax
cmpl $0x17, %eax
ja 0x57b5
leaq 0xfda9(%rip), %rcx      # 0x15004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r13), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r13)
cmpl %r14d, %ecx
jg 0x5226
cltq
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
je 0x5226
movq %r15, %rdi
leaq 0x10cc3(%rip), %rsi     # 0x15f4c
callq 0x40d0
testl %eax, %eax
je 0x52a1
movq %r15, %rdi
leaq 0x107f8(%rip), %rsi     # 0x15a94
callq 0x45f0
movslq (%r13), %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
callq 0x45f0
movl (%r13), %eax
incl %eax
movl %eax, (%r13)
cmpl %r14d, %eax
jl 0x5274
jmp 0x5226
testl %eax, %eax
jne 0x552d
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x18054(%rip), %rcx     # 0x1d330
cmpq $0x0, 0x10(%rax,%rcx)
jne 0x5226
leaq 0x18041(%rip), %rcx     # 0x1d330
addq %rcx, %rax
movq (%rax), %rsi
leaq 0x10781(%rip), %rdi     # 0x15a7d
xorl %eax, %eax
callq 0x4040
movq 0x17c8e(%rip), %rax     # 0x1cf98
movq (%rax), %rsi
testq %rsi, %rsi
je 0x5320
leaq 0x1076e(%rip), %rdi     # 0x15a87
xorl %eax, %eax
callq 0x4040
movl $0xa, %edi
callq 0x4430
jmp 0x5226
movq 0x17c62(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x182c3(%rip), %rcx     # 0x1d608
movl %eax, (%rcx)
jmp 0x5226
movq 0x17c45(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x182be(%rip), %rcx     # 0x1d620
movl %eax, (%rcx)
jmp 0x5226
movq 0x17c28(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x182a5(%rip), %rcx     # 0x1d624
movl %eax, (%rcx)
jmp 0x5226
movq 0x17c0b(%rip), %rax     # 0x1cf98
movq (%rax), %r15
movq -0x148(%rbp), %r12
movq %r15, %rdi
callq 0x4140
leaq -0x150(%rbp), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r15, %rcx
leaq -0x110(%rbp), %r15
movq %rax, %r8
callq 0x44f0
jmp 0x5226
movq 0x17bcf(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x18240(%rip), %rcx     # 0x1d618
movl %eax, (%rcx)
jmp 0x5226
movq 0x17bb2(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x43c0
leaq 0x1823b(%rip), %rax     # 0x1d630
movsd %xmm0, (%rax)
jmp 0x5226
movq 0x17b93(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x18214(%rip), %rcx     # 0x1d628
movl %eax, (%rcx)
jmp 0x5226
movq 0x17b76(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x181db(%rip), %rcx     # 0x1d60c
movl %eax, (%rcx)
jmp 0x5226
movq 0x17b59(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x43c0
leaq 0x18202(%rip), %rax     # 0x1d650
movsd %xmm0, (%rax)
jmp 0x5226
movq 0x17b3a(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x181a7(%rip), %rcx     # 0x1d614
movl %eax, (%rcx)
jmp 0x5226
movl (%r13), %ecx
leal -0x1(%rcx), %eax
movl %eax, (%r13)
cmpl %r14d, %ecx
jg 0x5226
cltq
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
je 0x5226
leaq -0x130(%rbp), %r12
movq %r12, %rdi
leaq 0x10aa4(%rip), %rsi     # 0x15f4c
callq 0x40d0
testl %eax, %eax
je 0x54c0
movq %r12, %rdi
leaq 0x105d9(%rip), %rsi     # 0x15a94
callq 0x45f0
movslq (%r13), %rax
movq (%rbx,%rax,8), %rsi
movq %r12, %rdi
callq 0x45f0
movl (%r13), %eax
incl %eax
movl %eax, (%r13)
cmpl %r14d, %eax
jl 0x5488
jmp 0x5226
movq 0x17aad(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x18116(%rip), %rcx     # 0x1d610
movl %eax, (%rcx)
jmp 0x5226
movq 0x17a90(%rip), %rax     # 0x1cf98
movq (%rax), %rdi
callq 0x4500
leaq 0x18105(%rip), %rcx     # 0x1d61c
movl %eax, (%rcx)
jmp 0x5226
leaq 0x18113(%rip), %rax     # 0x1d638
movb $0x1, (%rax)
jmp 0x5226
cmpl $-0x1, %eax
jne 0x55cc
leaq -0x110(%rbp), %rdi
leaq 0x10a08(%rip), %rsi     # 0x15f4c
callq 0x40d0
testl %eax, %eax
sete %r14b
je 0x563f
leaq -0x130(%rbp), %rdi
leaq 0x109e9(%rip), %rsi     # 0x15f4c
callq 0x40d0
testl %eax, %eax
je 0x564c
leaq 0x180a5(%rip), %rax     # 0x1d61c
movl (%rax), %eax
leaq 0x18094(%rip), %rcx     # 0x1d614
cmpl (%rcx), %eax
jl 0x565c
testb %r14b, %r14b
jne 0x5664
leaq -0x168(%rbp), %rdi
callq 0x7b10
callq 0x9626
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x96b2
leaq -0x168(%rbp), %rdi
callq 0x6cee
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3f, %eax
jne 0x57b5
movq 0x179dc(%rip), %rax     # 0x1cfb8
movl (%rax), %r14d
cmpl $0x63, %r14d
je 0x56b4
cmpl $0x6f, %r14d
je 0x566e
cmpl $0x72, %r14d
jne 0x56f4
movq 0x179c8(%rip), %rax     # 0x1cfc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x10489(%rip), %rsi     # 0x15a96
xorl %eax, %eax
callq 0x4460
movq (%rbx), %rsi
leaq -0xd0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0xd0(%rbp), %rdi
callq 0x4a6c
leaq -0xc0(%rbp), %rax
jmp 0x576b
movq %rbx, %rdi
callq 0x4650
jmp 0x5555
movq %rbx, %rdi
callq 0x4674
movb $0x1, %r14b
jmp 0x5570
movq %rbx, %rdi
callq 0x4698
movl $0x1, %edi
callq 0x43a0
movq 0x17953(%rip), %rax     # 0x1cfc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x10440(%rip), %rsi     # 0x15ac2
xorl %eax, %eax
callq 0x4460
movq (%rbx), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0xb0(%rbp), %rdi
callq 0x4a6c
leaq -0xa0(%rbp), %rax
jmp 0x576b
movq 0x1790d(%rip), %rax     # 0x1cfc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x10426(%rip), %rsi     # 0x15aee
xorl %eax, %eax
callq 0x4460
movq (%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0x90(%rbp), %rdi
callq 0x4a6c
leaq -0x80(%rbp), %rax
jmp 0x576b
movl %r14d, %edi
callq 0x45a0
movq 0x178c5(%rip), %rcx     # 0x1cfc8
movq (%rcx), %rdi
movq (%rbx), %rdx
testl %eax, %eax
jne 0x573d
leaq 0x10427(%rip), %rsi     # 0x15b3b
movl %r14d, %ecx
xorl %eax, %eax
callq 0x4460
movq (%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0x50(%rbp), %rdi
callq 0x4a6c
leaq -0x40(%rbp), %rax
jmp 0x576b
leaq 0x103d6(%rip), %rsi     # 0x15b1a
movl %r14d, %ecx
xorl %eax, %eax
callq 0x4460
movq (%rbx), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0x70(%rbp), %rdi
callq 0x4a6c
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5779
callq 0x42f0
movl $0x1, %ebx
jmp 0x55ac
movq (%rbx), %rsi
leaq -0xf0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0xf0(%rbp), %rdi
callq 0x4a6c
leaq -0xf0(%rbp), %rdi
callq 0x4160
xorl %edi, %edi
callq 0x43a0
callq 0x41e0
movq %rax, %rbx
leaq -0x60(%rbp), %rax
jmp 0x5805
jmp 0x581b
movq %rax, %rbx
leaq -0x40(%rbp), %rax
jmp 0x5805
jmp 0x581b
movq %rax, %rbx
leaq -0x80(%rbp), %rax
jmp 0x5805
jmp 0x581b
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
jmp 0x5805
jmp 0x581b
movq %rax, %rbx
leaq -0xc0(%rbp), %rax
jmp 0x5805
jmp 0x581b
jmp 0x581b
jmp 0x581b
movq %rax, %rbx
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x581e
callq 0x42f0
jmp 0x581e
jmp 0x581b
jmp 0x581b
jmp 0x581b
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x6cee
movq %rbx, %rdi
callq 0x4590
nop