// File: /workspace/github_cpp_makefile_star2_O3/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, 0x60(%rsp)
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
movb $0x1, %al
movl %eax, 0x5c(%rsp)
leaq 0x2d3b(%rip), %r14      # 0x5320
leaq 0x2a64(%rip), %r12      # 0x5050
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %r15d, %r15d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2060
cmpl $0x74, %eax
je 0x25fa
leal -0x63(%rax), %ecx
cmpl $0x13, %ecx
ja 0x266b
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, %r13d
jmp 0x25fa
movl $0x1, 0x60(%rsp)
jmp 0x25fa
movq 0x597a(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x2210
movl %eax, 0x54(%rsp)
jmp 0x25fa
movl $0x0, 0x5c(%rsp)
jmp 0x25fa
movq 0x595b(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x2210
movl %eax, 0x58(%rsp)
jmp 0x25fa
movl $0x1, %r15d
jmp 0x25fa
cmpl $-0x1, %eax
jne 0x34db
testl %r13d, %r13d
movl $0x9, %eax
movl $0x2c, %ecx
cmovel %eax, %ecx
movl %ecx, (%rsp)
movq 0x5942(%rip), %rax      # 0x7fd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x34db
movq (%rbx,%rax,8), %rbx
testl %r15d, %r15d
je 0x3447
leaq 0x2c96(%rip), %rsi      # 0x5343
movq %rbx, 0x90(%rsp)
movq %rbx, %rdi
callq 0x21f0
movq %rax, %rbx
movl $0x1, %edi
movl $0x70, %esi
callq 0x20e0
movq %rax, %r12
movl $0x1, %edi
movl $0x20, %esi
callq 0x20e0
movq %rax, %rbp
movq %rbx, 0x98(%rsp)
movq %rbx, 0x18(%rax)
movl $0x1000, %edi           # imm = 0x1000
callq 0x21b0
movq %rax, (%rbp)
movq %rbp, 0x68(%r12)
xorl %r15d, %r15d
leaq 0xd0(%rsp), %rax
movq %r15, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x170(%rsp), %rax
movq %r15, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x150(%rsp), %rax
movq %r15, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x130(%rsp), %rax
movq %r15, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x110(%rsp), %rax
movq %r15, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x18(%r12), %rax
movq %rax, 0x88(%rsp)
xorl %ebx, %ebx
xorl %eax, %eax
xorl %r14d, %r14d
testl %eax, %eax
movq %r14, 0x8(%rsp)
jne 0x2803
movl 0x8(%rbp), %ecx
movl 0xc(%rbp), %eax
cmpl $0x0, 0x10(%rbp)
je 0x2798
cmpl %eax, %ecx
jge 0x2dd8
cmpl %eax, %ecx
jl 0x27ce
movl $0x0, 0x8(%rbp)
movq (%rbp), %rsi
movq 0x18(%rbp), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x22a0
movl %eax, 0xc(%rbp)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0x27ce
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x2dd8
movq (%rbp), %rdx
movslq 0x8(%rbp), %rsi
leal 0x1(%rsi), %ecx
movl %ecx, 0x8(%rbp)
movzbl (%rdx,%rsi), %esi
movsbl %sil, %edx
movl %edx, 0x30(%rsp)
cmpl $0x3e, %esi
je 0x27fe
cmpl $0xff, %esi
je 0x2dd8
cmpl $0x40, %esi
jne 0x278a
movl %edx, 0x60(%r12)
movq %r15, 0x48(%r12)
movq %r15, 0x30(%r12)
movq %r15, 0x18(%r12)
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x30(%rsp), %rcx
callq 0x3676
testl %eax, %eax
js 0x3451
cmpl $0xa, 0x30(%rsp)
je 0x284a
movq %rbp, %rdi
movl $0xa, %esi
movq 0x88(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3676
cmpl $0x0, 0x10(%rbp)
sete %cl
movl 0xc(%rbp), %ebx
cmpl %ebx, 0x8(%rbp)
setl %al
orb %al, %cl
testb $0x1, %cl
je 0x297b
testb $0x1, %al
jne 0x289d
movl $0x0, 0x8(%rbp)
movq (%rbp), %rsi
movq 0x18(%rbp), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x22a0
movl %eax, %ebx
movl %eax, 0xc(%rbp)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0x289d
movl $0x1, 0x10(%rbp)
testl %ebx, %ebx
je 0x297b
movq (%rbp), %rax
movslq 0x8(%rbp), %rcx
leal 0x1(%rcx), %r15d
movl %r15d, 0x8(%rbp)
movb (%rax,%rcx), %r14b
movsbl %r14b, %edi
movl %edi, 0x30(%rsp)
movzbl %dil, %eax
cmpl $0x3f, %eax
jg 0x28d5
cmpl $0x2b, %eax
je 0x298a
cmpl $0x3e, %eax
jne 0x28e9
jmp 0x2985
cmpl $0x40, %eax
je 0x2985
cmpl $0xff, %eax
je 0x298a
callq 0x2140
testl %eax, %eax
je 0x2962
movq 0x30(%r12), %rbx
movq 0x40(%r12), %rax
leaq 0x1(%rbx), %r15
cmpq 0x38(%r12), %r15
jb 0x2952
movq %r15, %rcx
shrq %rcx
orq %r15, %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(%r12)
movq %rax, %rdi
callq 0x2240
movq %rax, 0x40(%r12)
movb 0x30(%rsp), %r14b
movq %r15, 0x30(%r12)
movb %r14b, (%rax,%rbx)
movl 0x8(%rbp), %r15d
movl 0xc(%rbp), %ebx
cmpl %ebx, %r15d
setl %al
cmpl $0x0, 0x10(%rbp)
je 0x2865
cmpl %ebx, %r15d
jl 0x2865
movl $0xffffffff, 0x30(%rsp) # imm = 0xFFFFFFFF
jmp 0x298a
movl %edi, 0x60(%r12)
movq 0x30(%r12), %r13
movq 0x40(%r12), %rbx
movb $0x0, (%rbx,%r13)
cmpl $0x2b, 0x30(%rsp)
movq 0x8(%rsp), %r14
leaq 0x68(%rsp), %r15
jne 0x2aeb
movq 0x38(%r12), %rsi
cmpq %rsi, 0x50(%r12)
jae 0x29ce
movq %rsi, 0x50(%r12)
movq 0x58(%r12), %rdi
callq 0x2240
movq %rax, 0x58(%r12)
movl 0x8(%rbp), %ecx
movl 0xc(%rbp), %eax
cmpl $0x0, 0x10(%rbp)
je 0x29e2
cmpl %eax, %ecx
jge 0x2d93
cmpl %eax, %ecx
jl 0x2a18
movl $0x0, 0x8(%rbp)
movq (%rbp), %rsi
movq 0x18(%rbp), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x22a0
movl %eax, 0xc(%rbp)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0x2a18
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x2d93
movq (%rbp), %rdx
movslq 0x8(%rbp), %rsi
leal 0x1(%rsi), %ecx
movl %ecx, 0x8(%rbp)
movzbl (%rdx,%rsi), %edx
movsbl %dl, %esi
movl %esi, 0x30(%rsp)
cmpl $0xff, %edx
je 0x2d93
cmpl $0xa, %edx
jne 0x29d4
jmp 0x2a60
cmpb $0x21, %dl
jl 0x2a60
movq 0x58(%r12), %rax
leaq 0x1(%rsi), %rcx
movq %rcx, 0x48(%r12)
movb %dl, (%rax,%rsi)
movl 0x8(%rbp), %ecx
movl 0xc(%rbp), %eax
cmpl %eax, %ecx
setl %dl
cmpl $0x0, 0x10(%rbp)
je 0x2a6f
cmpl %eax, %ecx
jge 0x2acb
testb $0x1, %dl
jne 0x2aa2
movl $0x0, 0x8(%rbp)
movq (%rbp), %rsi
movq 0x18(%rbp), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x22a0
movl %eax, 0xc(%rbp)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0x2aa2
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x2acb
movq (%rbp), %rdx
movslq 0x8(%rbp), %rsi
leal 0x1(%rsi), %ecx
movl %ecx, 0x8(%rbp)
movsbl (%rdx,%rsi), %edx
movl %edx, 0x30(%rsp)
cmpl $-0x1, %edx
je 0x2acb
movq 0x48(%r12), %rsi
cmpq %r13, %rsi
jb 0x2a44
movq 0x48(%r12), %rax
movq 0x58(%r12), %rcx
movb $0x0, (%rcx,%rax)
movl $0x0, 0x60(%r12)
cmpq %rax, %r13
jne 0x2d93
cmpl $-0x3, %r13d
je 0x345b
cmpl $-0x2, %r13d
je 0x2d93
cmpl $-0x1, %r13d
je 0x2ddd
testq %r14, %r14
sete %al
cmpq 0xa0(%rsp), %r13
sete %cl
orb %al, %cl
je 0x3480
movq 0x10(%r12), %rsi
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rdx
callq 0x38ba
leaq 0xd0(%rsp), %rdi
movq %rbp, %rsi
callq 0x3dea
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2b68
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2170
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x38f8
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x38f8
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
leaq 0xb0(%rsp), %r15
movq %r15, %rcx
callq 0x38f8
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
leaq 0x67(%rsp), %rcx
callq 0x38f8
testq %r13, %r13
je 0x2c7e
xorl %r15d, %r15d
movsbl (%rbx,%r15), %edi
callq 0x2290
movb %al, (%rbx,%r15)
movq %r15, %rdx
movl $0x1, %esi
movl %r15d, %ecx
shlq %cl, %rsi
shrq $0x6, %rdx
movzbl %al, %eax
addl $-0x41, %eax
cmpl $0x18, %eax
ja 0x2c48
leaq 0x24b0(%rip), %rdi      # 0x50a0
movslq (%rdi,%rax,4), %rcx
addq %rdi, %rcx
movq %rbp, %rax
jmpq *%rcx
movq 0x30(%rsp), %rax
jmp 0x2c56
movq 0x30(%rsp), %rax
jmp 0x2c5f
movq 0x30(%rsp), %rax
jmp 0x2c1f
movq 0x30(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
leaq 0x68(%rsp), %rax
jmp 0x2c6b
movq 0x30(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq %r14, %rax
jmp 0x2c6b
movq 0x30(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %rax
jmp 0x2c5f
movq 0x30(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x68(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
leaq 0xb0(%rsp), %rax
movq (%rax), %rax
orq %rsi, (%rax,%rdx,8)
incq %r15
cmpq %r15, %r13
jne 0x2bbe
leaq 0x170(%rsp), %rdi
movq %rbp, %rsi
callq 0x3936
leaq 0x68(%rsp), %r15
leaq 0x150(%rsp), %rdi
movq %r14, %rsi
callq 0x3936
leaq 0x130(%rsp), %rdi
movq %r15, %rsi
callq 0x3936
leaq 0x110(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x3936
leaq 0xb0(%rsp), %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r14
je 0x2cff
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %r15, %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2d26
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
leaq 0x10(%rsp), %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d4f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbp, %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2d76
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
incq %r14
movq 0x68(%r12), %rbp
movl 0x60(%r12), %eax
movq %r13, 0xa0(%rsp)
xorl %r15d, %r15d
jmp 0x277b
movq 0x5256(%rip), %rdi      # 0x7ff0
leaq 0x25a4(%rip), %rsi      # 0x5345
movl $0x1d, %edx
callq 0x2180
movq 0x10(%r12), %rbx
testq %rbx, %rbx
je 0x3392
movq %rbx, %rdi
callq 0x20a0
movq 0x5228(%rip), %rdi      # 0x7ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x33b0
testq %r12, %r12
je 0x2e25
movq 0x10(%r12), %rdi
callq 0x2190
movq 0x28(%r12), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2190
movq 0x58(%r12), %rdi
callq 0x2190
movq 0x68(%r12), %rbx
testq %rbx, %rbx
je 0x2e1d
movq (%rbx), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2190
movq %r12, %rdi
callq 0x2190
movq 0x98(%rsp), %rdi
callq 0x2250
movl 0x54(%rsp), %ebp
cmpl $-0x1, %ebp
je 0x2e45
cmpl %r14d, %ebp
jl 0x2e4a
callq 0x22f6
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb $0x1, 0x5c(%rsp)
jne 0x2f0d
leaq 0x30(%rsp), %rsi
movb $0x23, (%rsi)
movq 0x515c(%rip), %rbx      # 0x7fc0
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2180
leaq 0x30(%rsp), %rsi
movl (%rsp), %ecx
movb %cl, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2180
testq %r14, %r14
je 0x2edd
movl $0x8, %r14d
movq 0x5126(%rip), %r15      # 0x7fc0
leaq 0x30(%rsp), %r12
movq 0x8(%rsp), %r13
movq 0xd0(%rsp), %rax
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r15, %rdi
callq 0x2180
movl (%rsp), %ecx
movb %cl, 0x30(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2180
addq $0x20, %r14
decq %r13
jne 0x2ea4
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movq 0x8(%rsp), %r14
movsbl %al, %esi
movq 0x50c0(%rip), %rdi      # 0x7fc0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
testq %r14, %r14
je 0x338e
cmpl $0x0, 0x60(%rsp)
setne %al
testl %ebp, %ebp
sets %cl
andb %al, %cl
movb %cl, 0x98(%rsp)
movl %ebp, 0x54(%rsp)
movl %ebp, %eax
movq %rax, 0x90(%rsp)
movzbl (%rsp), %ebx
leaq 0x30(%rsp), %r13
leaq 0x10(%rsp), %r12
movq $0x0, (%rsp)
movl 0x58(%rsp), %ebp
movl %ebx, 0xac(%rsp)
movl %ebp, 0x58(%rsp)
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x39c8
movq %r13, %rdi
movq 0xa0(%rsp), %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x38f8
movq (%rsp), %rax
incq %rax
cmpb $0x0, 0x98(%rsp)
movl $0x0, %r15d
movq %rax, 0x88(%rsp)
cmovneq %rax, %r15
cmpq 0x8(%rsp), %r15
jae 0x31a5
movq %r15, %rbp
shlq $0x5, %rbp
movq (%rsp), %r14
shlq $0x5, %r14
movq 0x170(%rsp), %rdx
leaq (%rdx,%r14), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a54
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x3055
subq %rdi, %rsi
callq 0x2170
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
movq %rax, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x306d
subq %rdi, %rsi
callq 0x2170
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x306d
jmp 0x34bc
movq 0x28(%rsp), %rax
movq %rax, 0x48(%rsp)
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq %r12, %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x309d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x150(%rsp), %rdx
leaq (%rdx,%r14), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a54
movq %r13, %rdi
movq %r12, %rsi
callq 0x3b10
movq %r12, %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x30e6
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x130(%rsp), %rdx
leaq (%rdx,%r14), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a54
movq %r13, %rdi
movq %r12, %rsi
callq 0x3b10
movq %r12, %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x312f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x110(%rsp), %rdx
leaq (%rdx,%r14), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a54
movq %r13, %rdi
movq %r12, %rsi
callq 0x3b10
movq %r12, %rdi
callq 0x4312
testb %al, %al
je 0x349d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3178
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %r13, %rdi
callq 0x3b6c
movq 0xa0(%rsp), %rcx
subl %eax, %ecx
movq 0x68(%rsp), %rax
movl %ecx, (%rax,%r15,4)
incq %r15
addq $0x20, %rbp
cmpq %r15, 0x8(%rsp)
jne 0x2fbf
movq 0x88(%rsp), %r15
cmpl $0x0, 0x54(%rsp)
movl 0x58(%rsp), %ebp
js 0x3226
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
callq 0x3c68
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rbp
cmpq %rbp, %r15
je 0x3206
movq %rbp, %rax
subq %r15, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x470a
movq %r15, %rdi
movq %rbp, %rsi
callq 0x47ed
movq 0x10(%rsp), %r15
movq 0x90(%rsp), %rax
movl 0x4(%r15,%rax,4), %ebp
movq 0x20(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x2170
xorl %r15d, %r15d
cmpl $0x0, 0x60(%rsp)
je 0x32b9
cmpq 0x8(%rsp), %r15
jae 0x3336
movq %r15, %r14
shlq $0x5, %r14
cmpl $-0x1, %ebp
je 0x3253
movq 0x68(%rsp), %rax
cmpl %ebp, (%rax,%r15,4)
jg 0x32a9
testb $0x1, 0x5c(%rsp)
je 0x3286
movq 0xd0(%rsp), %rax
movq (%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq (%rax,%r14), %rcx
movq 0x68(%rsp), %rax
movl (%rax,%r15,4), %r9d
leaq 0x2168(%rip), %rdi      # 0x53ea
movl %ebx, %edx
jmp 0x329f
movq 0x68(%rsp), %rax
movl (%rax,%r15,4), %r9d
leaq 0x2148(%rip), %rdi      # 0x53de
movq (%rsp), %rsi
movl %ebx, %edx
movq %r15, %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2040
incq %r15
addq $0x20, %r14
cmpq %r15, 0x8(%rsp)
jne 0x3243
jmp 0x3336
testb $0x1, 0x5c(%rsp)
je 0x32dd
movq 0xd0(%rsp), %rax
movq (%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
leaq 0x211b(%rip), %rdi      # 0x53f6
jmp 0x32e8
leaq 0x2117(%rip), %rdi      # 0x53fb
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x2040
movq 0x8(%rsp), %r15
xorl %r14d, %r14d
leaq 0x20fb(%rip), %rbx      # 0x53f9
movl 0xac(%rsp), %r13d
movq 0x68(%rsp), %rax
movl (%rax,%r14,4), %edx
movq %rbx, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x2040
incq %r14
cmpq %r14, %r15
jne 0x3306
movl $0xa, %edi
callq 0x21c0
movl %r13d, %ebx
leaq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x4312
testb %al, %al
movq 0x8(%rsp), %r14
je 0x349d
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3362
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x3379
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
cmpq %r14, %rax
jne 0x2f5b
xorl %ebx, %ebx
jmp 0x33cd
movq 0x4c57(%rip), %rax      # 0x7ff0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x2260
movl $0x1, %ebx
movq 0x4c34(%rip), %rdi      # 0x7ff0
leaq 0x2019(%rip), %rsi      # 0x53dc
movl $0x1, %edx
callq 0x2180
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x33f2
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x110(%rsp), %rdi
callq 0x3ce8
leaq 0x130(%rsp), %rdi
callq 0x3ce8
leaq 0x150(%rsp), %rdi
callq 0x3ce8
leaq 0x170(%rsp), %rdi
callq 0x3ce8
leaq 0xd0(%rsp), %rdi
callq 0x3d18
movl %ebx, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x22d0
jmp 0x26a6
movq 0x40(%r12), %rbx
jmp 0x2ddd
movq 0x4b8e(%rip), %rdi      # 0x7ff0
leaq 0x1efa(%rip), %rsi      # 0x5363
movl $0xe, %edx
callq 0x2180
movq 0x90(%rsp), %rbx
jmp 0x2db0
movq 0x4b69(%rip), %rdi      # 0x7ff0
leaq 0x1ee4(%rip), %rsi      # 0x5372
movl $0x3a, %edx
callq 0x2180
jmp 0x2dab
leaq 0x208b(%rip), %rdi      # 0x552f
leaq 0x1faa(%rip), %rsi      # 0x5455
leaq 0x2092(%rip), %rcx      # 0x5544
movl $0x2be, %edx            # imm = 0x2BE
callq 0x20d0
leaq 0x2288(%rip), %rdi      # 0x574b
leaq 0x1f8b(%rip), %rsi      # 0x5455
leaq 0x229d(%rip), %rcx      # 0x576e
movl $0x2e7, %edx            # imm = 0x2E7
callq 0x20d0
movl $0x1, %edi
callq 0x247c
xorl %edi, %edi
callq 0x247c
leaq 0x1e49(%rip), %rdi      # 0x533c
leaq 0x1c72(%rip), %rsi      # 0x516c
leaq 0x1e2d(%rip), %rdx      # 0x532e
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x21a0
jmp 0x35c5
jmp 0x366e
jmp 0x366e
jmp 0x366e
jmp 0x366e
movq %rax, %rbx
jmp 0x3577
movq %rax, %rbx
jmp 0x3581
movq %rax, %rbx
jmp 0x358b
jmp 0x35c5
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x35fe
movq 0x40(%rsp), %rsi
incq %rsi
jmp 0x35f9
jmp 0x35c5
jmp 0x35c5
jmp 0x35c5
jmp 0x35c5
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x397c
leaq 0x68(%rsp), %rdi
callq 0x397c
leaq 0x10(%rsp), %rdi
callq 0x397c
leaq 0x30(%rsp), %rdi
callq 0x397c
jmp 0x35fe
jmp 0x35c5
jmp 0x35c5
jmp 0x35da
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x35dd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x35dd
jmp 0x366e
jmp 0x35c5
movq %rax, %rbx
jmp 0x35e7
movq %rax, %rbx
jmp 0x35fe
jmp 0x35da
jmp 0x366e
jmp 0x35da
jmp 0x35da
jmp 0x366e
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x397c
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x35fe
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x3623
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x110(%rsp), %rdi
callq 0x3ce8
leaq 0x130(%rsp), %rdi
callq 0x3ce8
leaq 0x150(%rsp), %rdi
callq 0x3ce8
leaq 0x170(%rsp), %rdi
callq 0x3ce8
leaq 0xd0(%rsp), %rdi
callq 0x3d18
movq %rbx, %rdi
callq 0x2270
jmp 0x366e
movq %rax, %rdi
callq 0x3d76