// File: /workspace/github_cpp_makefile_star2_O2/gtonkinhill[P]pairsnp-cpp/src/main.cpp
// Function: main
int main(int argc, char *argv[])
{

  // parse command line parameters
  int opt, quiet=0, csv=0, sparse=0, dist=-1, knn=-1, index=0;
  size_t nthreads=1;
  while ((opt = getopt(argc, argv, "hqsncvid:t:k:")) != -1) {
    switch (opt) {
      case 'h': show_help(EXIT_SUCCESS); break;
      case 'q': quiet=1; break;
      case 'c': csv=1; break;
      case 's': sparse=1; break;
      case 'i': index=1; break;
      case 'd': dist=atoi(optarg); break;
      case 'k': knn=atoi(optarg); break;
      case 't': nthreads=atoi(optarg); break;
      case 'v': printf("%s %s\n", EXENAME, VERSION); exit(EXIT_SUCCESS);
      default : show_help(EXIT_FAILURE);
    }
  }

  char sep = csv ? ',' : '\t';

  // require a filename argument
  if (optind >= argc) {
    show_help(EXIT_FAILURE);
    return 0;
  }
  const char* fasta = argv[optind];

  // say hello
  if (!quiet) fprintf(stderr, "This is %s %s\n", EXENAME, VERSION);

  // open filename and initialise kseq
  int l;
  gzFile fp = gzopen(fasta, "r");
  kseq_t * seq = kseq_init(fp);

  //Initially run through fasta to get SNPS not matching reference
  size_t n_seqs = 0;
  size_t seq_length;

  // initialise roaring bitmaps
  std::vector<std::string> seq_names;
  std::vector<boost::dynamic_bitset<>> A_snps;
  std::vector<boost::dynamic_bitset<>> C_snps;
  std::vector<boost::dynamic_bitset<>> G_snps;
  std::vector<boost::dynamic_bitset<>> T_snps;
  std::string consensus;

  while(true) {
    l = kseq_read(seq);

    if (l == -1)  // end of file
        break;
    if (l == -2) {
        std::cerr << "Error: incorrect FASTA format" << seq->name.s << "\n";
        return 1;
    }
    if (l == -3) {
        std::cerr << "Error reading " << fasta << "\n";
        return 1;
    }

    // check sequence length
    if ((n_seqs>0) && (seq->seq.l != seq_length)){
      std::cerr << "Error: incorrect FASTA format, variable sequence lengths! " << seq->name.s << "\n";
      return 1;
    }
    seq_length = seq->seq.l;

    seq_names.push_back(seq->name.s);
    boost::dynamic_bitset<> As(seq_length);
    boost::dynamic_bitset<> Cs(seq_length);
    boost::dynamic_bitset<> Gs(seq_length);
    boost::dynamic_bitset<> Ts(seq_length);

    for(size_t j=0; j<seq_length; j++){

      seq->seq.s[j] = std::toupper(seq->seq.s[j]);

      switch(seq->seq.s[j]){
        case 'A': As[j] = 1; break;
        case 'C': Cs[j] = 1; break;
        case 'G': Gs[j] = 1; break;
        case 'T': Ts[j] = 1; break;

        // M = A or C
        case 'M': As[j] = 1; 
          Cs[j] = 1;
          break;

        // R = A or G
        case 'R': As[j] = 1; 
          Gs[j] = 1;
          break;

        // W = A or T
        case 'W': As[j] = 1; 
          Ts[j] = 1;
          break;

        // S = C or G
        case 'S': Cs[j] = 1; 
          Gs[j] = 1;
          break;

        // Y = C or T
        case 'Y': Cs[j] = 1; 
          Ts[j] = 1;
          break;

        // K = G or T
        case 'K': Gs[j] = 1; 
          Ts[j] = 1;
          break;

        // V = A,C or G
        case 'V': As[j] = 1; 
          Cs[j] = 1; 
          Gs[j] = 1;
          break;

        // H = A,C or T
        case 'H': As[j] = 1; 
          Cs[j] = 1; 
          Ts[j] = 1;
          break;
        
        // D = A,G or T
        case 'D': As[j] = 1;
          Gs[j] = 1; 
          Ts[j] = 1;
          break;

        // B = C,G or T
        case 'B': Cs[j] = 1;
          Gs[j] = 1; 
          Ts[j] = 1;
          break;

        // N = A,C,G or T
        default:  
          As[j] = 1;
          Cs[j] = 1;
          Gs[j] = 1; 
          Ts[j] = 1;
          break;

      }
    }
    A_snps.push_back(As);
    C_snps.push_back(Cs);
    G_snps.push_back(Gs);
    T_snps.push_back(Ts);

    n_seqs++;
  }
  kseq_destroy(seq);
  gzclose(fp);

  if((knn!=-1) && (knn>=int(n_seqs))){
      fprintf(stderr, "kNN > number of samples. Running in dense mode!\n" );
      knn = -1;
  }
  
  //If sparse output print sequence names in the header
  if (index){
    std::cout << '#' << sep;
    for (size_t j=0; j < n_seqs; j++) {
      std::cout << seq_names[j] << sep;
    }
    std::cout << std::endl;
  }

  #pragma omp parallel for ordered shared(A_snps, C_snps \
    , G_snps, T_snps, seq_length \
    , n_seqs, seq_names, dist, sep, sparse \
    , knn, index) default(none) schedule(static,1) num_threads(nthreads)
  for (size_t i = 0; i < n_seqs; i++) {

    std::vector<int> comp_snps(n_seqs);
    boost::dynamic_bitset<> res(seq_length);

    size_t start;
    if (sparse && (knn<0)){
      start = i+1;
    } else {
      start = 0;
    }
    
    for(size_t j=start; j<n_seqs; j++){

      res = A_snps[i] & A_snps[j];
      res |= C_snps[i] & C_snps[j];
      res |= G_snps[i] & G_snps[j];
      res |= T_snps[i] & T_snps[j];

      comp_snps[j] = seq_length - res.count();

    }

    // if using knn find the distance needed
    if (knn>=0){
      std::vector<int> s_comp = comp_snps;
      std::sort(s_comp.begin(), s_comp.end());
      dist = s_comp[knn+1];
      start=0;
    } else {
      start = i+1;
    }

    // Output the distance matrix to stdout
    #pragma omp ordered //#pragma omp critical
    if (sparse){
      for (size_t j=start; j < n_seqs; j++) {
        if ((dist==-1) || (comp_snps[j] <= dist)){
          if (index) {
            std::printf("%d%c%d%c%d\n", i, sep, j, sep, comp_snps[j]);
          } else {
            std::printf("%s%c%s%c%d\n", seq_names[i].c_str(), sep, seq_names[j].c_str(), sep, comp_snps[j]);
          }
        }
      }
    } else {
      if (index) {
        printf("%d", i);
      } else {
        printf("%s", seq_names[i].c_str());
      }
      for (size_t j=0; j < n_seqs; j++) {
        printf("%c%d", sep, comp_snps[j]);
      }
      printf("\n");
    }
  }

  return 0;

  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rsi, %rbx
movl %edi, %ebp
movl $0x0, 0x20(%rsp)
pushq $-0x1
popq %rcx
movb $0x1, %al
movl %eax, 0x1c(%rsp)
leaq 0x2ddf(%rip), %r14      # 0x530c
leaq 0x2ad0(%rip), %r12      # 0x5004
movl %ecx, 0x18(%rsp)
movl %ecx, 0xc(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2050
leal -0x63(%rax), %ecx
cmpl $0x13, %ecx
ja 0x25a9
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
pushq $0x1
popq %r13
jmp 0x2542
movq 0x5a43(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x2220
movl %eax, 0x18(%rsp)
jmp 0x2542
movq 0x5a2e(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x2220
movl %eax, 0xc(%rsp)
jmp 0x2542
pushq $0x1
popq %r15
jmp 0x2542
movl $0x0, 0x1c(%rsp)
jmp 0x2542
pushq $0x1
popq %rax
movl %eax, 0x20(%rsp)
jmp 0x2542
cmpl $-0x1, %eax
jne 0x30ae
testl %r13d, %r13d
pushq $0x9
popq %rax
pushq $0x2c
popq %rcx
cmovel %eax, %ecx
movl %ecx, 0x68(%rsp)
movq 0x5a07(%rip), %rax      # 0x7fd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x30ae
movq (%rbx,%rax,8), %rbx
testl %r15d, %r15d
je 0x3057
leaq 0x2d47(%rip), %rsi      # 0x532f
movq %rbx, 0x98(%rsp)
movq %rbx, %rdi
callq 0x2200
movq %rax, %r14
pushq $0x1
popq %rbx
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r15
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r12
movq %r14, 0xa0(%rsp)
movq %r14, 0x18(%rax)
movl $0x1000, %edi           # imm = 0x1000
callq 0x21c0
movq %rax, (%r12)
movq %r12, 0x68(%r15)
xorps %xmm0, %xmm0
leaq 0xd0(%rsp), %rax
andq $0x0, 0x10(%rax)
leaq 0x150(%rsp), %rcx
andq $0x0, 0x10(%rcx)
movaps %xmm0, (%rax)
movaps %xmm0, (%rcx)
leaq 0x130(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x110(%rsp), %rcx
andq $0x0, 0x10(%rcx)
leaq 0xf0(%rsp), %rdx
andq $0x0, 0x10(%rdx)
leaq 0x178(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movaps %xmm0, (%rcx)
movaps %xmm0, (%rdx)
movb $0x0, (%rax)
leaq 0x18(%r15), %rax
movq %rax, 0x70(%rsp)
xorl %ebx, %ebx
leaq 0x48(%rsp), %r13
xorl %eax, %eax
movq $0x0, 0x10(%rsp)
testl %eax, %eax
jne 0x26e1
movq %r12, %rdi
callq 0x3220
cmpl $-0x1, %eax
je 0x2c9f
cmpl $0x40, %eax
je 0x26d9
cmpl $0x3e, %eax
jne 0x26be
movl %eax, 0x28(%rsp)
movl %eax, 0x60(%r15)
andq $0x0, 0x48(%r15)
andq $0x0, 0x30(%r15)
andq $0x0, 0x18(%r15)
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
leaq 0x28(%rsp), %rcx
callq 0x328d
testl %eax, %eax
js 0x2ca6
cmpl $0xa, 0x28(%rsp)
je 0x2723
movq %r12, %rdi
pushq $0xa
popq %rsi
movq 0x70(%rsp), %rdx
xorl %ecx, %ecx
callq 0x328d
movq %r12, %rdi
callq 0x3220
movl %eax, %ebx
movl %eax, 0x28(%rsp)
cmpl $-0x1, %eax
je 0x27c8
cmpl $0x2b, %ebx
je 0x27c8
cmpl $0x3e, %ebx
je 0x27c4
cmpl $0x40, %ebx
je 0x27c4
movl %ebx, %edi
callq 0x2140
testl %eax, %eax
je 0x2723
movq 0x30(%r15), %r14
movq 0x40(%r15), %rax
leaq 0x1(%r14), %r13
cmpq 0x38(%r15), %r13
jb 0x27b2
movq %r13, %rcx
shrq %rcx
orq %r13, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rsi
shrq $0x10, %rsi
orq %rdx, %rsi
incq %rsi
movq %rsi, 0x38(%r15)
movq %rax, %rdi
callq 0x2250
movq %rax, 0x40(%r15)
movl 0x28(%rsp), %ebx
movq %r13, 0x30(%r15)
movb %bl, (%rax,%r14)
leaq 0x48(%rsp), %r13
jmp 0x2723
movl %ebx, 0x60(%r15)
movq 0x30(%r15), %rbp
movq 0x40(%r15), %rbx
movb $0x0, (%rbx,%rbp)
cmpl $0x2b, 0x28(%rsp)
jne 0x2856
movq 0x38(%r15), %rsi
cmpq %rsi, 0x50(%r15)
jae 0x27f6
movq %rsi, 0x50(%r15)
movq 0x58(%r15), %rdi
callq 0x2250
movq %rax, 0x58(%r15)
movq %r12, %rdi
callq 0x3220
movl %eax, 0x28(%rsp)
cmpl $-0x1, %eax
je 0x2c0a
cmpl $0xa, %eax
jne 0x27f6
jmp 0x2826
cmpl $0x21, %eax
jl 0x2826
movq 0x58(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x48(%r15)
movb %al, (%rdx,%rcx)
movq %r12, %rdi
callq 0x3220
movl %eax, 0x28(%rsp)
movq 0x48(%r15), %rcx
cmpl $-0x1, %eax
je 0x2840
cmpq %rbp, %rcx
jb 0x2812
movq 0x58(%r15), %rax
movb $0x0, (%rax,%rcx)
andl $0x0, 0x60(%r15)
cmpq %rcx, %rbp
jne 0x2c0a
cmpl $-0x3, %ebp
je 0x3082
cmpl $-0x2, %ebp
je 0x2c0a
cmpl $-0x1, %ebp
je 0x2caa
cmpq $0x0, 0x10(%rsp)
setne %al
cmpq 0xa8(%rsp), %rbp
setne %cl
testb %cl, %al
jne 0x30a2
movq 0x10(%r15), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x78(%rsp), %rdx
callq 0x34ac
leaq 0xd0(%rsp), %rdi
movq %r14, %rsi
callq 0x3892
movq %r14, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rbp, %r12
movq %rbp, %rsi
xorl %edx, %edx
leaq 0x78(%rsp), %r14
movq %r14, %rcx
callq 0x34e8
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x34e8
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
leaq 0xb0(%rsp), %r13
movq %r13, %rcx
callq 0x34e8
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
leaq 0x27(%rsp), %rcx
callq 0x34e8
xorl %r13d, %r13d
cmpq %r13, %rbp
je 0x2b79
movsbl (%rbx,%r13), %edi
callq 0x2290
movb %al, (%rbx,%r13)
movzbl %al, %eax
addl $-0x41, %eax
cmpl $0x18, %eax
ja 0x2b2e
leaq 0x2717(%rip), %rcx      # 0x5054
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
jmp 0x2b6e
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x351a
orq %rdx, (%rax)
incq %r13
jmp 0x2910
leaq 0x150(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3548
leaq 0x48(%rsp), %r13
leaq 0x130(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3548
leaq 0x110(%rsp), %rdi
movq %r13, %rsi
callq 0x3548
leaq 0xf0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x3548
incq 0x10(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x3574
movq %r13, %rdi
callq 0x3574
leaq 0x78(%rsp), %rdi
callq 0x3574
leaq 0x28(%rsp), %rdi
callq 0x3574
movq 0x68(%r15), %r12
movl 0x60(%r15), %eax
movq %rbp, 0xa8(%rsp)
jmp 0x26ba
leaq 0x2720(%rip), %rsi      # 0x5331
movq 0x53d8(%rip), %rdi      # 0x7ff0
callq 0x2150
movq 0x10(%r15), %rsi
movq %rax, %rdi
callq 0x2150
leaq 0x2798(%rip), %rsi      # 0x53c8
movq %rax, %rdi
callq 0x2150
pushq $0x1
popq %r14
leaq 0x168(%rsp), %rdi
callq 0x20a0
leaq 0xf0(%rsp), %rdi
callq 0x3790
leaq 0x110(%rsp), %rdi
callq 0x3790
leaq 0x130(%rsp), %rdi
callq 0x3790
leaq 0x150(%rsp), %rdi
callq 0x3790
leaq 0xd0(%rsp), %rdi
callq 0x37b2
movl %r14d, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r15, %r15
jne 0x2caa
jmp 0x2cee
movq 0x40(%r15), %rbx
movq 0x10(%r15), %rdi
callq 0x2190
movq 0x28(%r15), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2190
movq 0x58(%r15), %rdi
callq 0x2190
movq 0x68(%r15), %rbx
testq %rbx, %rbx
je 0x2ce6
movq (%rbx), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2190
movq 0xa0(%rsp), %rdi
callq 0x2260
movl 0x18(%rsp), %ebp
cmpl $-0x1, %ebp
je 0x2d26
cmpl 0x10(%rsp), %ebp
jl 0x2d29
movq 0x52b7(%rip), %rax      # 0x7fc8
movq (%rax), %rcx
leaq 0x267e(%rip), %rdi      # 0x5399
pushq $0x30
popq %rsi
pushq $0x1
popq %rdx
callq 0x22b0
pushq $-0x1
popq %rbp
movzbl 0x68(%rsp), %ebx
testb $0x1, 0x1c(%rsp)
jne 0x2d92
movq 0x5284(%rip), %rdi      # 0x7fc0
pushq $0x23
popq %rsi
callq 0x2180
movq %rax, %rdi
movl %ebx, %esi
callq 0x2180
xorl %r14d, %r14d
movq 0x5268(%rip), %r15      # 0x7fc0
movq 0x10(%rsp), %r12
subq $0x1, %r12
jb 0x2d86
movq 0xd0(%rsp), %rsi
addq %r14, %rsi
movq %r15, %rdi
callq 0x2130
movq %rax, %rdi
movl %ebx, %esi
callq 0x2180
addq $0x20, %r14
jmp 0x2d5d
movq 0x5233(%rip), %rdi      # 0x7fc0
callq 0x20b0
cmpl $0x0, 0x20(%rsp)
setne %al
testl %ebp, %ebp
sets %cl
andb %al, %cl
movb %cl, 0xa0(%rsp)
movl %ebp, 0x18(%rsp)
movl %ebp, %eax
movq %rax, 0x98(%rsp)
xorl %r14d, %r14d
leaq 0x28(%rsp), %r15
leaq 0x78(%rsp), %r12
xorl %r13d, %r13d
movq 0x10(%rsp), %rsi
cmpq %rsi, %r13
je 0x2c3c
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
callq 0x35b2
movq %r15, %rdi
movq 0xa8(%rsp), %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x34e8
leaq 0x1(%r13), %rax
cmpb $0x0, 0xa0(%rsp)
movl $0x0, %r14d
movq %rax, 0x68(%rsp)
cmovneq %rax, %r14
movq %r14, %rbp
shlq $0x5, %rbp
movq %r13, 0x70(%rsp)
shlq $0x5, %r13
cmpq 0x10(%rsp), %r14
jae 0x2efb
movq 0x150(%rsp), %rdx
leaq (%rdx,%r13), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3603
movq %r15, %rdi
movq %r12, %rsi
callq 0x365c
movq %r12, %rdi
callq 0x3574
movq 0x130(%rsp), %rdx
leaq (%rdx,%r13), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3603
movq %r15, %rdi
movq %r12, %rsi
callq 0x36d4
movq %r12, %rdi
callq 0x3574
movq 0x110(%rsp), %rdx
leaq (%rdx,%r13), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3603
movq %r15, %rdi
movq %r12, %rsi
callq 0x36d4
movq %r12, %rdi
callq 0x3574
movq 0xf0(%rsp), %rdx
leaq (%rdx,%r13), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3603
movq %r15, %rdi
movq %r12, %rsi
callq 0x36d4
movq %r12, %rdi
callq 0x3574
movq %r15, %rdi
callq 0x3728
movq 0xa8(%rsp), %rcx
subl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, (%rax,%r14,4)
incq %r14
addq $0x20, %rbp
jmp 0x2e21
movq 0x68(%rsp), %rbp
cmpl $0x0, 0x18(%rsp)
js 0x2f45
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x3742
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x439e
movq 0x78(%rsp), %rax
movq 0x98(%rsp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movl %eax, 0xc(%rsp)
movq %r12, %rdi
callq 0x4136
xorl %ebp, %ebp
cmpl $0x0, 0x20(%rsp)
je 0x2fd3
leaq (,%rbp,4), %r14
movl 0xc(%rsp), %ecx
cmpq 0x10(%rsp), %rbp
jae 0x3038
cmpl $-0x1, %ecx
je 0x2f77
movq 0x48(%rsp), %rax
cmpl %ecx, (%rax,%r14)
jg 0x2fca
testb $0x1, 0x1c(%rsp)
je 0x2fa2
movq 0xd0(%rsp), %rax
movq (%rax,%r13), %rsi
movq (%rax,%r14,8), %rcx
movq 0x48(%rsp), %rax
movl (%rax,%r14), %r9d
leaq 0x2438(%rip), %rdi      # 0x53d6
movl %ebx, %edx
jmp 0x2fbc
movq 0x48(%rsp), %rax
movl (%rax,%r14), %r9d
leaq 0x2418(%rip), %rdi      # 0x53ca
movq 0x70(%rsp), %rsi
movl %ebx, %edx
movq %rbp, %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2030
movl 0xc(%rsp), %ecx
incq %rbp
addq $0x4, %r14
jmp 0x2f5c
testb $0x1, 0x1c(%rsp)
je 0x2fef
movq 0xd0(%rsp), %rax
movq (%rax,%r13), %rsi
leaq 0x23f5(%rip), %rdi      # 0x53e2
jmp 0x2ffb
leaq 0x23f1(%rip), %rdi      # 0x53e7
movq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
movq 0x10(%rsp), %r13
leaq 0x23d7(%rip), %rbp      # 0x53e5
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x3030
movq 0x48(%rsp), %rax
movl (%rax,%r14,4), %edx
movq %rbp, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x2030
incq %r14
jmp 0x3011
pushq $0xa
popq %rdi
callq 0x21d0
movq %r15, %rdi
callq 0x3574
leaq 0x48(%rsp), %rdi
callq 0x4136
movq 0x68(%rsp), %r13
xorl %r14d, %r14d
jmp 0x2dc6
movq 0x4f6a(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
leaq 0x22b8(%rip), %rsi      # 0x5320
leaq 0x20e9(%rip), %rdx      # 0x5158
leaq 0x22a4(%rip), %rcx      # 0x531a
xorl %eax, %eax
callq 0x21e0
jmp 0x25e1
movq 0x4f67(%rip), %rdi      # 0x7ff0
leaq 0x22bf(%rip), %rsi      # 0x534f
callq 0x2150
movq 0x98(%rsp), %rsi
jmp 0x2c21
leaq 0x22b5(%rip), %rsi      # 0x535e
jmp 0x2c11
pushq $0x1
popq %rdi
callq 0x23ec
leaq 0x226b(%rip), %rdi      # 0x5328
leaq 0x2094(%rip), %rsi      # 0x5158
leaq 0x224f(%rip), %rdx      # 0x531a
xorl %eax, %eax
callq 0x2030
xorl %edi, %edi
callq 0x21a0
xorl %edi, %edi
callq 0x23ec
movq %rax, %rbx
jmp 0x3168
movq %rax, %rbx
jmp 0x3172
movq %rax, %rbx
jmp 0x317c
jmp 0x31a8
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20a0
jmp 0x31ca
jmp 0x31a8
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x3158
jmp 0x31a8
jmp 0x31a8
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x3574
leaq 0x48(%rsp), %rdi
callq 0x3574
leaq 0x78(%rsp), %rdi
callq 0x3574
leaq 0x28(%rsp), %rdi
callq 0x3574
jmp 0x31ca
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x4136
jmp 0x31b6
jmp 0x31b3
jmp 0x31a8
jmp 0x31a8
movq %rax, %rbx
jmp 0x31c0
jmp 0x31a8
jmp 0x31a8
jmp 0x31a8
movq %rax, %rbx
jmp 0x31ca
jmp 0x31b3
jmp 0x31b3
jmp 0x31b3
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3574
leaq 0x48(%rsp), %rdi
callq 0x4136
leaq 0x168(%rsp), %rdi
callq 0x20a0
leaq 0xf0(%rsp), %rdi
callq 0x3790
leaq 0x110(%rsp), %rdi
callq 0x3790
leaq 0x130(%rsp), %rdi
callq 0x3790
leaq 0x150(%rsp), %rdi
callq 0x3790
leaq 0xd0(%rsp), %rdi
callq 0x37b2
movq %rbx, %rdi
callq 0x2270