// File: Ahhgust[P]STRaitRazor/str8.cpp
// Function: main
int
main(int argc, char **argv) {

  if (argc < 3) {
    fprintf(stderr, "Not enough arguments!\n");
    usage(argv[0]);
  }

  unsigned i;

#ifdef OSX // for the named semaphores required by OSX
  char buff[100];
  sprintf(buff, "%ld", (long)getpid() );
#endif


  int start = parseArgs(argc, argv, opt);

  if ( opt.useQuality) {
    initQvalLUT( opt.useQuality );
    USE_QVALS=opt.useQuality; // working with pthreads is much easier if we just use globals... 
  }
  
  if (opt.numThreads == 0)
    opt.numThreads=1;
  
  int *ids;
  
  ids = new int [ opt.numThreads];
  matches = new Matches[ opt.numThreads ]; // each thread records the records it found

  
  
  for (i=0; i < (unsigned) opt.numThreads; ++i)
    ids[i] = i;
  
  std::ios::sync_with_stdio(false);
  
  // parse the config file
  c = parseConfig(opt.config, &numStrs, opt.type);

  biasCounts = new unsigned* [ opt.numThreads]; // and counts for partial allelic dropout  
  totalCounts = new unsigned* [ opt.numThreads]; // and counts for partial allelic dropout  

  leftFlankPosSum = new unsigned long* [ opt.numThreads]; // and counts for partial allelic dropout  
  rightFlankPosSum = new unsigned long* [ opt.numThreads]; // and counts for partial allelic dropout  

  for (i=0; i < (unsigned) opt.numThreads; ++i) {
    biasCounts[i] = new unsigned[ numStrs ](); // () initializes the bias counts to 0
    totalCounts[i] = new unsigned[ numStrs ](); // () initializes the total counts to 0

    leftFlankPosSum[i] = new unsigned long [ numStrs ](); 
    rightFlankPosSum[i] = new unsigned long [ numStrs ](); 
  }
  

  if (numStrs==0) {
    fprintf(stderr, "No markers found in file: %s\n", opt.config);
    return 1;
  }


  // compute minima and maxima for the STRs we're looking for
  minLen = min((*c)[0].forwardLength,  (*c)[0].reverseLength);
  maxLen = max(  (*c)[0].forwardLength,
                 max( (*c)[0].reverseLength, (*c)[0].motifLength));
  // assumes that the motif nomenclature cannot be negative
  minFrag =   (*c)[0].forwardLength +   (*c)[0].reverseLength + (*c)[0].motifOffset;
  for (i=1; i < numStrs; ++i) {

    if ((int)  (*c)[i].forwardLength < minLen)
      minLen =   (*c)[i].forwardLength;

    if ((int)  (*c)[i].reverseLength < minLen)
      minLen =   (*c)[i].reverseLength;

    if ((int)  (*c)[i].forwardLength > maxLen)
      maxLen =   (*c)[i].forwardLength;

    if ((int)  (*c)[i].reverseLength > maxLen)
      maxLen =   (*c)[i].reverseLength;

    if ((int)  (*c)[i].motifLength > maxLen)
      maxLen =   (*c)[i].motifLength;


    int fragLen =   (*c)[i].forwardLength +   (*c)[i].reverseLength + (*c)[i].motifOffset;
    if (fragLen < minFrag)
      minFrag = fragLen;
  }


  trie = new Trie;
  trie->makeTrieFromConfig(c, numStrs, opt.distance, opt.motifDistance);
    

#ifndef NOTHREADS
  if (opt.numThreads > 1) {
    if (pthread_mutex_init(&ioLock, 0)) {
      cerr << "Failed to init mutex..." << endl;
    }
    /* unnamed semaphore. not supported on OSX! */
#ifdef OSX
    writersLock = sem_open( buff , O_CREAT, 0600, 0);
#else
    if (sem_init(&writersLock, 0, 0)) {
      cerr << "Failed to init semaphore..." << endl;
      return 1;
    }
#endif

    

  }
#endif

  
  for (i=start ; i < (unsigned)argc; ++i) {
    ifstream in;
    in.open(argv[i], ios::in);
    if (! in.is_open() ) {
      cerr << "Failed to open " << argv[i] << " for reading\n";
      continue;
    }
    currentInputStream = &in;


    if (opt.numThreads < 2) 
      findMatchesOneThread(  );
    else {
#ifndef NOTHREADS
      int err;
      pthread_t t;
      list <pthread_t> threads;
            
      err = pthread_create(&t, NULL, writerThread, NULL ); 
      if (err) {
        cerr << "Error creating writer thread" << endl;
        exit(EXIT_FAILURE);
      }
      threads.push_back(t);

      for (int j=0; j < opt.numThreads; ++j) {
        err = pthread_create(&t, NULL, workerThread, (void*) &(ids[j]) ); 
        if (err) {
          cerr << "Error creating thread number: " << j << endl;
          exit(EXIT_FAILURE);
        }
        threads.push_back(t);
      }
      for (list<pthread_t>::iterator itr = threads.begin(); itr != threads.end(); ++itr) { // collect the threads when we're done
        t = *itr;
        pthread_join(t, NULL);
      }

      threads.clear();
      std::ios::sync_with_stdio(true);
      printReportsMT(opt.out);
      std::ios::sync_with_stdio(false);
#endif

    }
    in.close();
  }

  // if no fastq files are given then check stdin
  if (argc == start)  {

    currentInputStream = &cin;
    if (opt.numThreads < 2) 
      findMatchesOneThread(  );

    else {
#ifndef NOTHREADS
      int err;
      pthread_t t;
      list <pthread_t> threads;
            
      err = pthread_create(&t, NULL, writerThread, NULL ); 
      if (err) {
        cerr << "Error creating writer thread" << endl;
        exit(EXIT_FAILURE);
      }
      threads.push_back(t);
      
      for (int j=0; j < opt.numThreads; ++j) {
        err = pthread_create(&t, NULL, workerThread, (void*) &ids[j] ); 
        if (err) {
          cerr << "Error creating thread number: " << j << endl;
          exit(EXIT_FAILURE);
        }
        threads.push_back(t);
      }
      for (list<pthread_t>::iterator itr = threads.begin(); itr != threads.end(); ++itr) { // collect the threads when we're done
        t = *itr;
        pthread_join(t, NULL);
      }

      threads.clear();
      std::ios::sync_with_stdio(true);
      printReportsMT(opt.out);
      std::ios::sync_with_stdio(false);
#endif

    }

  }


#ifndef NOTHREADS
  if (opt.numThreads > 1) {
    pthread_mutex_destroy(&ioLock);

#ifdef OSX
    sem_unlink(buff);
#else
    sem_destroy(&writersLock);
#endif

  }
#endif

  // let's close our file handles, shall we?
  fclose(opt.out);

  // optionally can free memory here...
  // delete ids;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3b0, %rsp            # imm = 0x3B0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x7813
movq 0x147d2(%rip), %rax     # 0x1bfc8
movq (%rax), %rdi
leaq 0xd426(%rip), %rsi      # 0x14c26
movb $0x0, %al
callq 0x3390
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x67d0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x14ab7(%rip), %rdx     # 0x1c2d8
callq 0x6aa0
movl %eax, -0x18(%rbp)
cmpb $0x0, 0x14ab2(%rip)     # 0x1c2e2
je 0x784a
movsbl 0x14aa9(%rip), %edi     # 0x1c2e2
callq 0x3a00
movb 0x14a9e(%rip), %al      # 0x1c2e2
movb %al, 0x62fb36(%rip)     # 0x637380
cmpl $0x0, 0x14aa7(%rip)     # 0x1c2f8
jne 0x785d
movl $0x1, 0x14a9b(%rip)     # 0x1c2f8
movslq 0x14a94(%rip), %rax     # 0x1c2f8
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x20(%rbp)
movslq 0x14a68(%rip), %rax     # 0x1c2f8
movq %rax, -0x2d0(%rbp)
movl $0x30, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x2c8(%rbp)
cmpq $0x0, %rax
je 0x7936
movq -0x2c8(%rbp), %rax
movq -0x2d0(%rbp), %rcx
imulq $0x30, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x2e0(%rbp)
movq %rax, -0x2d8(%rbp)
movq -0x2d8(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x9300
movq -0x2e8(%rbp), %rax
movq -0x2e0(%rbp), %rcx
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, -0x2d8(%rbp)
jne 0x7905
movq -0x2c8(%rbp), %rax
movq %rax, 0x62fa8c(%rip)    # 0x6373d0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x149a4(%rip), %eax     # 0x1c2f8
jae 0x796e
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x794b
xorl %edi, %edi
callq 0x3110
movq 0x14974(%rip), %rdi     # 0x1c2f0
movq 0x1497d(%rip), %rdx     # 0x1c300
leaq 0x62fa06(%rip), %rsi    # 0x637390
callq 0xf5a0
movq %rax, 0x62f9f2(%rip)    # 0x637388
movslq 0x1495b(%rip), %rax     # 0x1c2f8
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, 0x62f9eb(%rip)    # 0x6373b0
movslq 0x1492c(%rip), %rax     # 0x1c2f8
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, 0x62f9c4(%rip)    # 0x6373b8
movslq 0x148fd(%rip), %rax     # 0x1c2f8
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, 0x62f99d(%rip)    # 0x6373c0
movslq 0x148ce(%rip), %rax     # 0x1c2f8
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, 0x62f976(%rip)    # 0x6373c8
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x14896(%rip), %eax     # 0x1c2f8
jae 0x7be2
movl 0x62f922(%rip), %eax    # 0x637390
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x328(%rbp)
callq 0x3030
movq -0x328(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x320(%rbp)
xorl %esi, %esi
callq 0x3160
movq -0x320(%rbp), %rdx
movq 0x62f8f4(%rip), %rax    # 0x6373b0
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl 0x62f8c7(%rip), %eax    # 0x637390
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x318(%rbp)
callq 0x3030
movq -0x318(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x310(%rbp)
xorl %esi, %esi
callq 0x3160
movq -0x310(%rbp), %rdx
movq 0x62f8a1(%rip), %rax    # 0x6373b8
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl 0x62f86c(%rip), %eax    # 0x637390
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x308(%rbp)
callq 0x3030
movq -0x308(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x300(%rbp)
xorl %esi, %esi
callq 0x3160
movq -0x300(%rbp), %rdx
movq 0x62f84e(%rip), %rax    # 0x6373c0
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl 0x62f811(%rip), %eax    # 0x637390
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x3030
movq -0x2f8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x2f0(%rbp)
xorl %esi, %esi
callq 0x3160
movq -0x2f0(%rbp), %rdx
movq 0x62f7fb(%rip), %rax    # 0x6373c8
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7a59
cmpl $0x0, 0x62f7a7(%rip)    # 0x637390
jne 0x7c16
movq 0x143d6(%rip), %rax     # 0x1bfc8
movq (%rax), %rdi
movq 0x146f4(%rip), %rdx     # 0x1c2f0
leaq 0xd03a(%rip), %rsi      # 0x14c3d
movb $0x0, %al
callq 0x3390
movl $0x1, -0x4(%rbp)
jmp 0x8612
movq 0x62f76b(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
addq $0xa0, %rax
movq %rax, -0x348(%rbp)
movq 0x62f74e(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
movq -0x348(%rbp), %rdi
movq %rax, %rsi
addq $0xa4, %rsi
callq 0x9320
movl (%rax), %eax
movl %eax, 0x62f737(%rip)    # 0x637398
movq 0x62f720(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
addq $0xa0, %rax
movq %rax, -0x338(%rbp)
movq 0x62f703(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
addq $0xa4, %rax
movq %rax, -0x340(%rbp)
movq 0x62f6e6(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
movq -0x340(%rbp), %rdi
movq %rax, %rsi
addq $0xa8, %rsi
callq 0x9360
movq -0x338(%rbp), %rdi
movq %rax, %rsi
callq 0x9360
movl (%rax), %eax
movl %eax, 0x62f6c4(%rip)    # 0x63739c
movq 0x62f6a9(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
movl 0xa0(%rax), %eax
movl %eax, -0x330(%rbp)
movq 0x62f68d(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
movq %rax, %rcx
movl -0x330(%rbp), %eax
addl 0xa4(%rcx), %eax
movl %eax, -0x32c(%rbp)
movq 0x62f668(%rip), %rdi    # 0x637388
xorl %eax, %eax
movl %eax, %esi
callq 0x8890
movq %rax, %rcx
movl -0x32c(%rbp), %eax
movzwl 0xae(%rcx), %ecx
addl %ecx, %eax
movl %eax, 0x62f653(%rip)    # 0x637394
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x62f63f(%rip), %eax    # 0x637390
jae 0x7f10
movq 0x62f62a(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa0(%rax), %eax
cmpl 0x62f624(%rip), %eax    # 0x637398
jge 0x7d93
movq 0x62f60b(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa0(%rax), %eax
movl %eax, 0x62f605(%rip)    # 0x637398
movq 0x62f5ee(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa4(%rax), %eax
cmpl 0x62f5e8(%rip), %eax    # 0x637398
jge 0x7dcf
movq 0x62f5cf(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa4(%rax), %eax
movl %eax, 0x62f5c9(%rip)    # 0x637398
movq 0x62f5b2(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa0(%rax), %eax
cmpl 0x62f5b0(%rip), %eax    # 0x63739c
jle 0x7e0b
movq 0x62f593(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa0(%rax), %eax
movl %eax, 0x62f591(%rip)    # 0x63739c
movq 0x62f576(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa4(%rax), %eax
cmpl 0x62f574(%rip), %eax    # 0x63739c
jle 0x7e47
movq 0x62f557(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa4(%rax), %eax
movl %eax, 0x62f555(%rip)    # 0x63739c
movq 0x62f53a(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa8(%rax), %eax
cmpl 0x62f538(%rip), %eax    # 0x63739c
jle 0x7e83
movq 0x62f51b(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa8(%rax), %eax
movl %eax, 0x62f519(%rip)    # 0x63739c
movq 0x62f4fe(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movl 0xa0(%rax), %eax
movl %eax, -0x350(%rbp)
movq 0x62f4e1(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movq %rax, %rcx
movl -0x350(%rbp), %eax
addl 0xa4(%rcx), %eax
movl %eax, -0x34c(%rbp)
movq 0x62f4bb(%rip), %rdi    # 0x637388
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x8890
movq %rax, %rcx
movl -0x34c(%rbp), %eax
movzwl 0xae(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x62f49f(%rip), %eax    # 0x637394
jge 0x7f00
movl -0x24(%rbp), %eax
movl %eax, 0x62f494(%rip)    # 0x637394
jmp 0x7f02
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7d48
movl $0x18, %edi
callq 0x32b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x358(%rbp)
callq 0x11270
jmp 0x7f2e
movq -0x358(%rbp), %rax
movq %rax, 0x62f464(%rip)    # 0x6373a0
movq 0x62f45d(%rip), %rdi    # 0x6373a0
movq 0x62f43e(%rip), %rsi    # 0x637388
movl 0x62f440(%rip), %edx    # 0x637390
movb 0x143a7(%rip), %al      # 0x1c2fd
movzbl %al, %ecx
movzbl 0x1439d(%rip), %r8d     # 0x1c2fe
callq 0x121b0
cmpl $0x1, 0x1438b(%rip)     # 0x1c2f8
jle 0x8013
leaq 0x62ebae(%rip), %rdi    # 0x636b28
xorl %eax, %eax
movl %eax, %esi
callq 0x33c0
cmpl $0x0, %eax
je 0x7fce
movq 0x14061(%rip), %rdi     # 0x1bff0
leaq 0xccc5(%rip), %rsi      # 0x14c5b
callq 0x3290
movq %rax, %rdi
movq 0x14013(%rip), %rsi     # 0x1bfb8
callq 0x32e0
jmp 0x7fce
movq -0x358(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x18, %esi
callq 0x32c0
jmp 0x861e
leaq 0x62eb7b(%rip), %rdi    # 0x636b50
xorl %edx, %edx
movl %edx, %esi
callq 0x3240
cmpl $0x0, %eax
je 0x8011
movq 0x14006(%rip), %rdi     # 0x1bff0
leaq 0xcc82(%rip), %rsi      # 0x14c73
callq 0x3290
movq %rax, %rdi
movq 0x13fb8(%rip), %rsi     # 0x1bfb8
callq 0x32e0
movl $0x1, -0x4(%rbp)
jmp 0x8612
jmp 0x8013
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jae 0x8386
leaq -0x240(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x32f0
movq -0x360(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movl $0x8, %edx
callq 0x31c0
jmp 0x8056
leaq -0x240(%rbp), %rdi
callq 0x3420
movb %al, -0x361(%rbp)
jmp 0x806a
movb -0x361(%rbp), %al
testb $0x1, %al
jne 0x80e7
jmp 0x8076
movq 0x13f73(%rip), %rdi     # 0x1bff0
leaq 0xcc0b(%rip), %rsi      # 0x14c8f
callq 0x3290
movq %rax, -0x370(%rbp)
jmp 0x8092
movq -0x370(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
callq 0x3290
movq %rax, -0x378(%rbp)
jmp 0x80b2
movq -0x378(%rbp), %rdi
leaq 0xcbdf(%rip), %rsi      # 0x14c9f
callq 0x3290
jmp 0x80c7
movl $0xd, -0x244(%rbp)
jmp 0x834b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x8375
leaq -0x240(%rbp), %rax
movq %rax, 0x62ea2b(%rip)    # 0x636b20
cmpl $0x2, 0x141fc(%rip)     # 0x1c2f8
jge 0x810a
callq 0x66d0
jmp 0x8105
jmp 0x8333
leaq -0x268(%rbp), %rdi
callq 0x93a0
leaq -0x250(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xaa8(%rip), %rdx      # 0x7680
movq %rcx, %rsi
callq 0x34c0
movl %eax, -0x248(%rbp)
cmpl $0x0, -0x248(%rbp)
je 0x8197
movq 0x13eaa(%rip), %rdi     # 0x1bff0
leaq 0xcb60(%rip), %rsi      # 0x14cad
callq 0x3290
movq %rax, -0x380(%rbp)
jmp 0x815b
movq -0x380(%rbp), %rdi
movq 0x13e4f(%rip), %rsi     # 0x1bfb8
callq 0x32e0
jmp 0x8170
movl $0x1, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x9500
jmp 0x8375
leaq -0x268(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x93c0
jmp 0x81ac
movl $0x0, -0x26c(%rbp)
movl -0x26c(%rbp), %eax
cmpl 0x14136(%rip), %eax     # 0x1c2f8
jge 0x8281
movq -0x20(%rbp), %rcx
movslq -0x26c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
leaq -0x250(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0xdac(%rip), %rdx      # 0x7440
callq 0x34c0
movl %eax, -0x248(%rbp)
cmpl $0x0, -0x248(%rbp)
je 0x8256
movq 0x13de9(%rip), %rdi     # 0x1bff0
leaq 0xcabc(%rip), %rsi      # 0x14cca
callq 0x3290
movq %rax, -0x388(%rbp)
jmp 0x821c
movq -0x388(%rbp), %rdi
movl -0x26c(%rbp), %esi
callq 0x3480
movq %rax, -0x390(%rbp)
jmp 0x8237
movq -0x390(%rbp), %rdi
movq 0x13d73(%rip), %rsi     # 0x1bfb8
callq 0x32e0
jmp 0x824c
movl $0x1, %edi
callq 0x3330
leaq -0x268(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x93c0
jmp 0x826b
jmp 0x826d
movl -0x26c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x26c(%rbp)
jmp 0x81b6
leaq -0x268(%rbp), %rdi
callq 0x9400
movq %rax, -0x278(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x9460
movq %rax, -0x280(%rbp)
leaq -0x278(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x9430
testb $0x1, %al
jne 0x82c0
jmp 0x82f8
leaq -0x278(%rbp), %rdi
callq 0x9490
movq (%rax), %rax
movq %rax, -0x250(%rbp)
movq -0x250(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3280
jmp 0x82e8
jmp 0x82ea
leaq -0x278(%rbp), %rdi
callq 0x94b0
jmp 0x8294
leaq -0x268(%rbp), %rdi
callq 0x94d0
movl $0x1, %edi
callq 0x3110
jmp 0x8310
movq 0x13fd1(%rip), %rdi     # 0x1c2e8
callq 0x4840
jmp 0x831e
xorl %edi, %edi
callq 0x3110
jmp 0x8327
leaq -0x268(%rbp), %rdi
callq 0x9500
leaq -0x240(%rbp), %rdi
callq 0x30a0
jmp 0x8341
movl $0x0, -0x244(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x30b0
movl -0x244(%rbp), %eax
testl %eax, %eax
je 0x8365
jmp 0x8363
jmp 0x8367
jmp 0x8367
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8019
leaq -0x240(%rbp), %rdi
callq 0x30b0
jmp 0x861e
movl -0x8(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x85de
movq 0x13c3f(%rip), %rax     # 0x1bfd8
movq %rax, 0x62e780(%rip)    # 0x636b20
cmpl $0x2, 0x13f51(%rip)     # 0x1c2f8
jge 0x83b3
callq 0x66d0
jmp 0x85dc
leaq -0x2a8(%rbp), %rdi
callq 0x93a0
leaq -0x290(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xd51(%rip), %rdx      # 0x7680
movq %rcx, %rsi
callq 0x34c0
movl %eax, -0x284(%rbp)
cmpl $0x0, -0x284(%rbp)
je 0x8440
movq 0x13c01(%rip), %rdi     # 0x1bff0
leaq 0xc8b7(%rip), %rsi      # 0x14cad
callq 0x3290
movq %rax, -0x398(%rbp)
jmp 0x8404
movq -0x398(%rbp), %rdi
movq 0x13ba6(%rip), %rsi     # 0x1bfb8
callq 0x32e0
jmp 0x8419
movl $0x1, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x9500
jmp 0x861e
leaq -0x2a8(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x93c0
jmp 0x8455
movl $0x0, -0x2ac(%rbp)
movl -0x2ac(%rbp), %eax
cmpl 0x13e8d(%rip), %eax     # 0x1c2f8
jge 0x852a
movq -0x20(%rbp), %rcx
movslq -0x2ac(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
leaq -0x290(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x1055(%rip), %rdx     # 0x7440
callq 0x34c0
movl %eax, -0x284(%rbp)
cmpl $0x0, -0x284(%rbp)
je 0x84ff
movq 0x13b40(%rip), %rdi     # 0x1bff0
leaq 0xc813(%rip), %rsi      # 0x14cca
callq 0x3290
movq %rax, -0x3a0(%rbp)
jmp 0x84c5
movq -0x3a0(%rbp), %rdi
movl -0x2ac(%rbp), %esi
callq 0x3480
movq %rax, -0x3a8(%rbp)
jmp 0x84e0
movq -0x3a8(%rbp), %rdi
movq 0x13aca(%rip), %rsi     # 0x1bfb8
callq 0x32e0
jmp 0x84f5
movl $0x1, %edi
callq 0x3330
leaq -0x2a8(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x93c0
jmp 0x8514
jmp 0x8516
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x845f
leaq -0x2a8(%rbp), %rdi
callq 0x9400
movq %rax, -0x2b8(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x9460
movq %rax, -0x2c0(%rbp)
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x9430
testb $0x1, %al
jne 0x8569
jmp 0x85a1
leaq -0x2b8(%rbp), %rdi
callq 0x9490
movq (%rax), %rax
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3280
jmp 0x8591
jmp 0x8593
leaq -0x2b8(%rbp), %rdi
callq 0x94b0
jmp 0x853d
leaq -0x2a8(%rbp), %rdi
callq 0x94d0
movl $0x1, %edi
callq 0x3110
jmp 0x85b9
movq 0x13d28(%rip), %rdi     # 0x1c2e8
callq 0x4840
jmp 0x85c7
xorl %edi, %edi
callq 0x3110
jmp 0x85d0
leaq -0x2a8(%rbp), %rdi
callq 0x9500
jmp 0x85de
cmpl $0x1, 0x13d13(%rip)     # 0x1c2f8
jle 0x85ff
leaq 0x62e53a(%rip), %rdi    # 0x636b28
callq 0x3310
leaq 0x62e556(%rip), %rdi    # 0x636b50
callq 0x3500
movq 0x13ce2(%rip), %rdi     # 0x1c2e8
callq 0x32a0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x3b0, %rsp            # imm = 0x3B0
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x34a0
nopw (%rax,%rax)