// File: /workspace/github_cpp_makefile_star2_O2/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 0x16b1a(%rip), %rax     # 0x1b618
movl $0xa, (%rax)
leaq 0x16b11(%rip), %rax     # 0x1b61c
movl $0x64, (%rax)
leaq 0x16b08(%rip), %rax     # 0x1b620
movl $0x28, (%rax)
leaq 0x16aff(%rip), %rcx     # 0x1b624
pushq $0x4
popq %rax
movl %eax, (%rcx)
leaq 0x16af7(%rip), %rcx     # 0x1b628
movl $0x3, (%rcx)
leaq 0x16aee(%rip), %rcx     # 0x1b62c
movl $0x14, (%rcx)
leaq 0x16ae5(%rip), %rcx     # 0x1b630
movl %eax, (%rcx)
leaq 0x16aec(%rip), %rcx     # 0x1b640
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, (%rcx)
leaq 0x16af8(%rip), %rcx     # 0x1b660
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, (%rcx)
leaq 0x16ad0(%rip), %rax     # 0x1b64c
andl $0x0, (%rax)
leaq 0x16aca(%rip), %rax     # 0x1b650
pushq $0x1
popq %rcx
movl %ecx, (%rax)
leaq 0x16ac2(%rip), %rax     # 0x1b654
movl %ecx, (%rax)
leaq 0x16abd(%rip), %rax     # 0x1b658
andl $0x0, (%rax)
leaq 0x16ab7(%rip), %rax     # 0x1b65c
andl $0x0, (%rax)
leaq 0x16a85(%rip), %rax     # 0x1b634
andl $0x0, (%rax)
leaq 0x16a7f(%rip), %rax     # 0x1b638
movl $0x5, (%rax)
leaq 0x16a82(%rip), %rax     # 0x1b648
movb $0x0, (%rax)
leaq -0x168(%rbp), %rdi
callq 0x62e0
callq 0x81fe
movq 0x163f7(%rip), %rax     # 0x1afd8
andl $0x0, (%rax)
leaq -0x30(%rbp), %rax
andl $0x0, (%rax)
leaq -0x110(%rbp), %r12
leaq -0x130(%rbp), %r15
movq 0x163d0(%rip), %r13     # 0x1afd0
movl %r14d, %edi
movq %rbx, %rsi
leaq 0xde51(%rip), %rdx      # 0x12a5e
leaq 0x1672c(%rip), %rcx     # 0x1b340
leaq -0x30(%rbp), %r8
callq 0x4540
leal -0x63(%rax), %ecx
cmpl $0x17, %ecx
ja 0x4c8a
leaq 0xd3d8(%rip), %rdx      # 0x12004
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
pushq $-0x1
popq %rax
movslq (%r13), %rcx
cltq
addq %rcx, %rax
movl %eax, (%r13)
cmpl %r14d, %eax
jge 0x4c00
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
je 0x4c00
movq %r12, %rdi
leaq 0xe2ef(%rip), %rsi      # 0x12f4c
callq 0x51f1
testb %al, %al
je 0x4c75
movq %r12, %rdi
leaq 0xde24(%rip), %rsi      # 0x12a94
callq 0x45f0
movslq (%r13), %rax
movq (%rbx,%rax,8), %rsi
movq %r12, %rdi
callq 0x45f0
pushq $0x1
popq %rax
jmp 0x4c38
testl %eax, %eax
jne 0x4ebc
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x1669f(%rip), %rcx     # 0x1b340
cmpq $0x0, 0x10(%rax,%rcx)
jne 0x4c00
leaq 0x1668c(%rip), %rcx     # 0x1b340
addq %rcx, %rax
movq (%rax), %rsi
leaq 0xddbc(%rip), %rdi      # 0x12a7d
xorl %eax, %eax
callq 0x4040
movq 0x162d1(%rip), %rax     # 0x1afa0
movq (%rax), %rsi
testq %rsi, %rsi
je 0x4ce5
leaq 0xdda9(%rip), %rdi      # 0x12a87
xorl %eax, %eax
callq 0x4040
pushq $0xa
popq %rdi
callq 0x4420
jmp 0x4c00
movq 0x162a7(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x16918(%rip), %rcx     # 0x1b620
movl %eax, (%rcx)
jmp 0x4c00
movq 0x1628a(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x16907(%rip), %rcx     # 0x1b62c
movl %eax, (%rcx)
jmp 0x4c00
movq 0x1626d(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x168da(%rip), %rcx     # 0x1b61c
movl %eax, (%rcx)
jmp 0x4c00
movq 0x16250(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x168c9(%rip), %rcx     # 0x1b628
movl %eax, (%rcx)
jmp 0x4c00
movq 0x16233(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x1689c(%rip), %rcx     # 0x1b618
movl %eax, (%rcx)
jmp 0x4c00
movq 0x16216(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x1688b(%rip), %rcx     # 0x1b624
movl %eax, (%rcx)
jmp 0x4c00
movq 0x161f9(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x1687a(%rip), %rcx     # 0x1b630
movl %eax, (%rcx)
jmp 0x4c00
movq 0x161dc(%rip), %rax     # 0x1afa0
movq (%rax), %rsi
leaq -0x150(%rbp), %rdi
callq 0x4600
jmp 0x4c00
movq 0x161c1(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x43a0
leaq 0x16852(%rip), %rax     # 0x1b640
movsd %xmm0, (%rax)
jmp 0x4c00
movq 0x161a2(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x1682b(%rip), %rcx     # 0x1b638
movl %eax, (%rcx)
jmp 0x4c00
movq 0x16185(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x44e0
leaq 0x1680a(%rip), %rcx     # 0x1b634
movl %eax, (%rcx)
jmp 0x4c00
leaq 0x16810(%rip), %rax     # 0x1b648
movb $0x1, (%rax)
jmp 0x4c00
movq 0x16159(%rip), %rax     # 0x1afa0
movq (%rax), %rdi
callq 0x43a0
leaq 0x1680a(%rip), %rax     # 0x1b660
movsd %xmm0, (%rax)
jmp 0x4c00
pushq $-0x1
popq %rax
movslq (%r13), %rcx
cltq
addq %rcx, %rax
movl %eax, (%r13)
cmpl %r14d, %eax
jge 0x4c00
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
je 0x4c00
movq %r15, %rdi
leaq 0xe0bd(%rip), %rsi      # 0x12f4c
callq 0x51f1
testb %al, %al
je 0x4ea7
movq %r15, %rdi
leaq 0xdbf2(%rip), %rsi      # 0x12a94
callq 0x45f0
movslq (%r13), %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
callq 0x45f0
pushq $0x1
popq %rax
jmp 0x4e62
cmpl $-0x1, %eax
jne 0x4f52
leaq 0xe080(%rip), %rsi      # 0x12f4c
movq %r12, %rdi
callq 0x51fe
movl %eax, %r14d
testb %al, %al
jne 0x4fc9
leaq 0xe066(%rip), %rsi      # 0x12f4c
movq %r15, %rdi
callq 0x51fe
testb %al, %al
jne 0x4fe9
leaq 0x1672f(%rip), %rax     # 0x1b62c
movl (%rax), %eax
leaq 0x1671e(%rip), %rcx     # 0x1b624
cmpl (%rcx), %eax
jl 0x5018
testb %r14b, %r14b
jne 0x5033
leaq -0x168(%rbp), %rdi
callq 0x686e
callq 0x81fe
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x82a4
leaq -0x168(%rbp), %rdi
callq 0x6392
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 0x5148
movq 0x16056(%rip), %rax     # 0x1afb8
movl (%rax), %r14d
cmpl $0x63, %r14d
je 0x5081
cmpl $0x6f, %r14d
je 0x503b
cmpl $0x72, %r14d
jne 0x50c4
movq 0x1603e(%rip), %rax     # 0x1afc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xdaff(%rip), %rsi      # 0x12a96
xorl %eax, %eax
callq 0x4450
movq (%rbx), %rsi
leaq -0xd0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0xd0(%rbp), %rdi
callq 0x484c
leaq -0xd0(%rbp), %rdi
jmp 0x513b
movq 0x15ff8(%rip), %rax     # 0x1afc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xdb87(%rip), %rsi      # 0x12b64
xorl %eax, %eax
callq 0x4450
jmp 0x4edf
movq 0x15fd8(%rip), %rax     # 0x1afc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xdb94(%rip), %rsi      # 0x12b91
xorl %eax, %eax
callq 0x4450
leaq 0x16621(%rip), %rax     # 0x1b62c
movl (%rax), %eax
leaq 0x16610(%rip), %rcx     # 0x1b624
cmpl (%rcx), %eax
jge 0x5033
movq 0x15fa9(%rip), %rax     # 0x1afc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xdb90(%rip), %rsi      # 0x12bbc
xorl %eax, %eax
callq 0x4450
pushq $0x1
popq %rdi
callq 0x4380
movq 0x15f86(%rip), %rax     # 0x1afc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xda73(%rip), %rsi      # 0x12ac2
xorl %eax, %eax
callq 0x4450
movq (%rbx), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0xb0(%rbp), %rdi
callq 0x484c
leaq -0xb0(%rbp), %rdi
jmp 0x513b
movq 0x15f40(%rip), %rax     # 0x1afc8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xda59(%rip), %rsi      # 0x12aee
xorl %eax, %eax
callq 0x4450
movq (%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0x90(%rbp), %rdi
callq 0x484c
leaq -0x90(%rbp), %rdi
jmp 0x513b
movl %r14d, %edi
callq 0x45a0
movq 0x15ef5(%rip), %rcx     # 0x1afc8
movq (%rcx), %rdi
movq (%rbx), %rdx
testl %eax, %eax
jne 0x510d
leaq 0xda57(%rip), %rsi      # 0x12b3b
movl %r14d, %ecx
xorl %eax, %eax
callq 0x4450
movq (%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0x50(%rbp), %rdi
callq 0x484c
leaq -0x50(%rbp), %rdi
jmp 0x513b
leaq 0xda06(%rip), %rsi      # 0x12b1a
movl %r14d, %ecx
xorl %eax, %eax
callq 0x4450
movq (%rbx), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0x70(%rbp), %rdi
callq 0x484c
leaq -0x70(%rbp), %rdi
callq 0x4160
pushq $0x1
popq %rbx
jmp 0x4f32
callq 0x41f0
movq (%rbx), %rsi
leaq -0xf0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4120
leaq -0xf0(%rbp), %rdi
callq 0x484c
leaq -0xf0(%rbp), %rdi
callq 0x4160
xorl %edi, %edi
callq 0x4380
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x51cd
jmp 0x51da
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x51cd
jmp 0x51da
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x51cd
jmp 0x51da
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x51cd
jmp 0x51da
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
jmp 0x51cd
jmp 0x51da
jmp 0x51da
jmp 0x51da
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x4160
jmp 0x51dd
jmp 0x51da
jmp 0x51da
jmp 0x51da
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x6392
movq %rbx, %rdi
callq 0x4590