// File: /workspace/github_cpp_makefile_star2_O1/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, 0x64(%rsp)
movl $0xffffffff, 0x38(%rsp) # imm = 0xFFFFFFFF
movb $0x1, %al
movl %eax, 0x68(%rsp)
leaq 0x2d0b(%rip), %r14      # 0x52f0
leaq 0x2a34(%rip), %r12      # 0x5020
movl $0xffffffff, 0x3c(%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, 0x64(%rsp)
jmp 0x25fa
movq 0x597a(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x2210
movl %eax, 0x38(%rsp)
jmp 0x25fa
movl $0x0, 0x68(%rsp)
jmp 0x25fa
movq 0x595b(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x2210
movl %eax, 0x3c(%rsp)
jmp 0x25fa
movl $0x1, %r15d
jmp 0x25fa
cmpl $-0x1, %eax
jne 0x34bc
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 0x34bc
movq (%rbx,%rax,8), %rbx
testl %r15d, %r15d
je 0x3474
leaq 0x2c66(%rip), %rsi      # 0x5313
movq %rbx, 0x98(%rsp)
movq %rbx, %rdi
callq 0x21f0
movq %rax, %r14
movl $0x1, %edi
movl $0x70, %esi
callq 0x20e0
movq %rax, %r12
movl $0x1, %edi
movl $0x20, %esi
callq 0x20e0
movq %rax, %rbx
movq %r14, 0xa0(%rsp)
movq %r14, 0x18(%rax)
movl $0x1000, %edi           # imm = 0x1000
callq 0x21b0
movq %rax, (%rbx)
movq %rbx, 0x68(%r12)
xorl %ecx, %ecx
leaq 0xb0(%rsp), %rax
movq %rcx, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x170(%rsp), %rax
movq %rcx, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x150(%rsp), %rax
movq %rcx, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x130(%rsp), %rax
movq %rcx, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x110(%rsp), %rax
movq %rcx, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rcx, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x18(%r12), %rax
movq %rax, 0x90(%rsp)
leaq 0x40(%rsp), %rbx
leaq 0x28f2(%rip), %r14      # 0x5070
xorl %r15d, %r15d
movq %r15, 0x8(%rsp)
movq 0x68(%r12), %rbp
cmpl $0x0, 0x60(%r12)
movq %r13, 0xa8(%rsp)
jne 0x2826
jmp 0x27a9
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x2806
cmpl $0x0, 0x10(%rbp)
je 0x27bd
movl 0x8(%rbp), %eax
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl 0xc(%rbp), %eax
jge 0x2806
movl 0x8(%rbp), %eax
cmpl 0xc(%rbp), %eax
jl 0x27f3
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 0x27ef
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x27a1
movq (%rbp), %rax
movslq 0x8(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbp)
movsbl (%rax,%rcx), %r15d
movl %r15d, 0x40(%rsp)
cmpl $-0x1, %r15d
je 0x2b04
cmpl $0x40, %r15d
je 0x2821
cmpl $0x3e, %r15d
jne 0x27a9
movl %r15d, 0x60(%r12)
xorl %eax, %eax
movq %rax, 0x48(%r12)
movq %rax, 0x30(%r12)
movq %rax, 0x18(%r12)
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x3667
testl %eax, %eax
js 0x2988
cmpl $0xa, 0x40(%rsp)
je 0x286d
movq %rbp, %rdi
movl $0xa, %esi
movq 0x90(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3667
cmpl $0x0, 0x10(%rbp)
je 0x2880
movl 0x8(%rbp), %eax
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpl 0xc(%rbp), %eax
jge 0x28cc
movl 0x8(%rbp), %eax
cmpl 0xc(%rbp), %eax
jl 0x28ba
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 0x28b2
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x297e
movq (%rbp), %rax
movslq 0x8(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbp)
movsbl (%rax,%rcx), %edi
movl %edi, 0x40(%rsp)
cmpl $0x3d, %edi
jg 0x28e8
cmpl $-0x1, %edi
je 0x2998
cmpl $0x2b, %edi
jne 0x28fa
jmp 0x2998
cmpl $0x3e, %edi
je 0x2993
cmpl $0x40, %edi
je 0x2993
callq 0x2140
testl %eax, %eax
je 0x286d
movq 0x30(%r12), %r15
leaq 0x1(%r15), %r13
cmpq 0x38(%r12), %r13
jb 0x295f
movq %r13, %rax
shrq %rax
orq %r13, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x38(%r12)
movq 0x40(%r12), %rdi
callq 0x2240
movq %rax, 0x40(%r12)
movb 0x40(%rsp), %al
movq 0x40(%r12), %rcx
movq %r13, 0x30(%r12)
movb %al, (%rcx,%r15)
movq 0xa8(%rsp), %r13
jmp 0x286d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0x28cc
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x2b04
movl %edi, 0x60(%r12)
movq 0x30(%r12), %r15
movq 0x40(%r12), %rax
movb $0x0, (%rax,%r15)
cmpl $0x2b, 0x40(%rsp)
jne 0x2b04
movq 0x38(%r12), %rsi
cmpq %rsi, 0x50(%r12)
jae 0x29d2
movq %rsi, 0x50(%r12)
movq 0x58(%r12), %rdi
callq 0x2240
movq %rax, 0x58(%r12)
cmpl $0x0, 0x10(%rbp)
je 0x29e5
movl 0x8(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%rbp), %ecx
jge 0x2a2d
movl 0x8(%rbp), %eax
cmpl 0xc(%rbp), %eax
jl 0x2a1b
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 0x2a17
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x2a41
movq (%rbp), %rax
movslq 0x8(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbp)
movsbl (%rax,%rcx), %eax
movl %eax, 0x40(%rsp)
cmpl $-0x1, %eax
je 0x2afe
cmpl $0xa, %eax
jne 0x29d2
jmp 0x2a67
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2a2d
cmpl $0x21, %eax
jl 0x2a67
movq 0x58(%r12), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x48(%r12)
movb %al, (%rdx,%rcx)
jmp 0x2a67
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2ac2
cmpl $0x0, 0x10(%rbp)
je 0x2a7a
movl 0x8(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%rbp), %ecx
jge 0x2ac2
movl 0x8(%rbp), %eax
cmpl 0xc(%rbp), %eax
jl 0x2ab0
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 0x2aac
movl $0x1, 0x10(%rbp)
testl %eax, %eax
je 0x2a60
movq (%rbp), %rax
movslq 0x8(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbp)
movsbl (%rax,%rcx), %eax
movl %eax, 0x40(%rsp)
cmpl $-0x1, %eax
je 0x2ad9
movq 0x48(%r12), %rcx
cmpq %r15, %rcx
jb 0x2a48
movq 0x48(%r12), %rax
movq 0x58(%r12), %rcx
movb $0x0, (%rcx,%rax)
movl $0x0, 0x60(%r12)
cmpq %rax, %r15
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmovnel %eax, %r15d
jmp 0x2b04
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
cmpl $-0x3, %r15d
leaq 0x10(%rsp), %rbp
je 0x2d9f
cmpl $-0x2, %r15d
je 0x3367
cmpl $-0x1, %r15d
je 0x2dc4
cmpq $0x0, 0x8(%rsp)
je 0x2b3a
cmpq %r13, 0x30(%r12)
jne 0x3381
movq 0x30(%r12), %r13
movq 0x10(%r12), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x3888
leaq 0xb0(%rsp), %rdi
movq %rbx, %rsi
callq 0x3dc2
leaq 0x70(%rsp), %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x2b80
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2170
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0x38c6
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x38c6
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
leaq 0xd0(%rsp), %r15
movq %r15, %rcx
callq 0x38c6
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
leaq 0x6f(%rsp), %rcx
callq 0x38c6
testq %r13, %r13
je 0x2c97
movq 0x40(%r12), %r15
xorl %ebp, %ebp
movsbl (%r15,%rbp), %edi
callq 0x2290
movb %al, (%r15,%rbp)
movq %rbp, %rdx
movl $0x1, %esi
movl %ebp, %ecx
shlq %cl, %rsi
shrq $0x6, %rdx
movzbl %al, %eax
addl $-0x41, %eax
cmpl $0x18, %eax
leaq 0xd0(%rsp), %rdi
ja 0x2c66
movslq (%r14,%rax,4), %rcx
addq %r14, %rcx
movq %rbx, %rax
jmpq *%rcx
movq 0x40(%rsp), %rax
jmp 0x2c74
movq 0x40(%rsp), %rax
jmp 0x2c7d
movq 0x40(%rsp), %rax
jmp 0x2c3b
movq 0x40(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
leaq 0x70(%rsp), %rax
jmp 0x2c84
movq 0x40(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
leaq 0x10(%rsp), %rax
jmp 0x2c84
movq 0x40(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %rax
jmp 0x2c7d
movq 0x40(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq 0x70(%rsp), %rax
orq %rsi, (%rax,%rdx,8)
movq %rdi, %rax
movq (%rax), %rax
orq %rsi, (%rax,%rdx,8)
incq %rbp
cmpq %rbp, %r13
jne 0x2bda
leaq 0x170(%rsp), %rdi
movq %rbx, %rsi
callq 0x3904
leaq 0x10(%rsp), %rbp
leaq 0x70(%rsp), %r15
leaq 0x150(%rsp), %rdi
movq %rbp, %rsi
callq 0x3904
leaq 0x130(%rsp), %rdi
movq %r15, %rsi
callq 0x3904
leaq 0x110(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x3904
leaq 0xd0(%rsp), %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r15
je 0x2d1d
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
leaq 0x70(%rsp), %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2d49
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbp, %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d70
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2d97
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
incq %r15
jmp 0x2781
movq 0x524a(%rip), %rdi      # 0x7ff0
leaq 0x2586(%rip), %rsi      # 0x5333
movl $0xe, %edx
callq 0x2180
movq 0x98(%rsp), %rbx
jmp 0x339e
testq %r12, %r12
movl 0x68(%rsp), %ebp
movq 0x8(%rsp), %r15
je 0x2e1c
movq 0x10(%r12), %rdi
callq 0x2190
movq 0x28(%r12), %rdi
callq 0x2190
movq 0x40(%r12), %rdi
callq 0x2190
movq 0x58(%r12), %rdi
callq 0x2190
movq 0x68(%r12), %rbx
testq %rbx, %rbx
je 0x2e14
movq (%rbx), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2190
movq %r12, %rdi
callq 0x2190
movq 0xa0(%rsp), %rdi
callq 0x2250
movl 0x38(%rsp), %r14d
cmpl $-0x1, %r14d
je 0x2e3e
cmpl %r15d, %r14d
jl 0x2e44
callq 0x22f6
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb $0x1, %bpl
jne 0x2f0c
leaq 0x40(%rsp), %rsi
movb $0x23, (%rsi)
movq 0x5163(%rip), %rbx      # 0x7fc0
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2180
leaq 0x40(%rsp), %rsi
movl (%rsp), %ecx
movb %cl, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2180
movl %r14d, %ebp
testq %r15, %r15
je 0x2ed9
movl $0x8, %r14d
movq 0x512a(%rip), %r12      # 0x7fc0
leaq 0x40(%rsp), %r13
movq 0x8(%rsp), %r15
movq 0xb0(%rsp), %rax
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq %r12, %rdi
callq 0x2180
movl (%rsp), %ecx
movb %cl, 0x40(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2180
addq $0x20, %r14
decq %r15
jne 0x2ea0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movq 0x8(%rsp), %r15
movl %ebp, %r14d
movsbl %al, %esi
movq 0x50c1(%rip), %rdi      # 0x7fc0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
testq %r15, %r15
je 0x3360
cmpl $0x0, 0x64(%rsp)
setne %al
testl %r14d, %r14d
sets %cl
andb %al, %cl
movb %cl, 0xa0(%rsp)
movl %r14d, 0x38(%rsp)
movl %r14d, %eax
movq %rax, 0x98(%rsp)
movzbl (%rsp), %ebx
leaq 0x40(%rsp), %r13
leaq 0x10(%rsp), %r12
movq $0x0, (%rsp)
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x3996
movq %r13, %rdi
movq 0xa8(%rsp), %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x38c6
movq (%rsp), %rax
incq %rax
cmpb $0x0, 0xa0(%rsp)
movl $0x0, %r14d
movq %rax, 0x90(%rsp)
cmovneq %rax, %r14
cmpq %r15, %r14
jae 0x317d
movq %r14, %rbp
shlq $0x5, %rbp
movq (%rsp), %r15
shlq $0x5, %r15
movq 0x170(%rsp), %rdx
leaq (%rdx,%r15), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a1f
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x18(%rsp), %xmm0
movups %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x3003
subq %rdi, %rsi
callq 0x2170
movq 0x28(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x3035
subq %rdi, %rsi
callq 0x2170
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x349d
movq $0x0, 0x28(%rsp)
movq %r12, %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3075
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x150(%rsp), %rdx
leaq (%rdx,%r15), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a1f
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ada
movq %r12, %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x30be
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x130(%rsp), %rdx
leaq (%rdx,%r15), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a1f
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ada
movq %r12, %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3107
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x110(%rsp), %rdx
leaq (%rdx,%r15), %rsi
addq %rbp, %rdx
movq %r12, %rdi
callq 0x3a1f
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ada
movq %r12, %rdi
callq 0x42d6
testb %al, %al
je 0x347e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3150
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %r13, %rdi
callq 0x3b36
movq 0xa8(%rsp), %rcx
subl %eax, %ecx
movq 0x70(%rsp), %rax
movl %ecx, (%rax,%r14,4)
incq %r14
addq $0x20, %rbp
cmpq 0x8(%rsp), %r14
jb 0x2fb0
movq 0x90(%rsp), %rbp
cmpl $0x0, 0x38(%rsp)
movl 0x68(%rsp), %r15d
js 0x3203
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3c44
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r14
cmpq %r14, %rbp
je 0x31da
movq %r14, %rax
subq %rbp, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x46d2
movq %rbp, %rdi
movq %r14, %rsi
callq 0x47b5
movq 0x10(%rsp), %rdi
movq 0x98(%rsp), %rax
movl 0x4(%rdi,%rax,4), %eax
movl %eax, 0x3c(%rsp)
testq %rdi, %rdi
je 0x3201
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
xorl %ebp, %ebp
cmpl $0x0, 0x64(%rsp)
je 0x329a
cmpq 0x8(%rsp), %rbp
jae 0x3305
movq %rbp, %r14
shlq $0x5, %r14
cmpl $-0x1, 0x3c(%rsp)
je 0x3235
movq 0x70(%rsp), %rax
movl 0x3c(%rsp), %ecx
cmpl %ecx, (%rax,%rbp,4)
jg 0x328a
testb $0x1, %r15b
je 0x3267
movq 0xb0(%rsp), %rax
movq (%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq (%rax,%r14), %rcx
movq 0x70(%rsp), %rax
movl (%rax,%rbp,4), %r9d
leaq 0x2157(%rip), %rdi      # 0x53ba
movl %ebx, %edx
jmp 0x3280
movq 0x70(%rsp), %rax
movl (%rax,%rbp,4), %r9d
leaq 0x2137(%rip), %rdi      # 0x53ae
movq (%rsp), %rsi
movl %ebx, %edx
movq %rbp, %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2040
incq %rbp
addq $0x20, %r14
cmpq 0x8(%rsp), %rbp
jb 0x3220
jmp 0x3305
testb $0x1, %r15b
je 0x32bd
movq 0xb0(%rsp), %rax
movq (%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
leaq 0x210b(%rip), %rdi      # 0x53c6
jmp 0x32c8
leaq 0x2107(%rip), %rdi      # 0x53cb
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x2040
movq 0x8(%rsp), %r15
leaq 0x20ee(%rip), %rbp      # 0x53c9
xorl %r14d, %r14d
movq 0x70(%rsp), %rax
movl (%rax,%r14,4), %edx
movq %rbp, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x2040
incq %r14
cmpq %r14, %r15
jne 0x32de
movl $0xa, %edi
callq 0x21c0
movq %r13, %rdi
callq 0x42d6
testb %al, %al
movq 0x8(%rsp), %r15
je 0x347e
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3331
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x334b
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x90(%rsp), %rax
movq %rax, (%rsp)
cmpq %r15, %rax
jne 0x2f52
xorl %ebx, %ebx
jmp 0x33fa
movq 0x4c82(%rip), %rdi      # 0x7ff0
leaq 0x1fa0(%rip), %rsi      # 0x5315
movl $0x1d, %edx
callq 0x2180
jmp 0x3399
movq 0x4c68(%rip), %rdi      # 0x7ff0
leaq 0x1fb3(%rip), %rsi      # 0x5342
movl $0x3a, %edx
callq 0x2180
movq 0x10(%r12), %rbx
testq %rbx, %rbx
je 0x33bf
movq %rbx, %rdi
callq 0x20a0
movq 0x4c3e(%rip), %rdi      # 0x7ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x33dd
movq 0x4c2a(%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 0x4c07(%rip), %rdi      # 0x7ff0
leaq 0x1fbc(%rip), %rsi      # 0x53ac
movl $0x1, %edx
callq 0x2180
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x341f
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x110(%rsp), %rdi
callq 0x3cc4
leaq 0x130(%rsp), %rdi
callq 0x3cc4
leaq 0x150(%rsp), %rdi
callq 0x3cc4
leaq 0x170(%rsp), %rdi
callq 0x3cc4
leaq 0xb0(%rsp), %rdi
callq 0x3cf4
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
leaq 0x207a(%rip), %rdi      # 0x54ff
leaq 0x1f99(%rip), %rsi      # 0x5425
leaq 0x2081(%rip), %rcx      # 0x5514
movl $0x2be, %edx            # imm = 0x2BE
callq 0x20d0
leaq 0x2277(%rip), %rdi      # 0x571b
leaq 0x1f7a(%rip), %rsi      # 0x5425
leaq 0x228c(%rip), %rcx      # 0x573e
movl $0x2e7, %edx            # imm = 0x2E7
callq 0x20d0
movl $0x1, %edi
callq 0x247c
xorl %edi, %edi
callq 0x247c
leaq 0x1e38(%rip), %rdi      # 0x530c
leaq 0x1c61(%rip), %rsi      # 0x513c
leaq 0x1e1c(%rip), %rdx      # 0x52fe
xorl %eax, %eax
callq 0x2040
xorl %edi, %edi
callq 0x21a0
jmp 0x3580
jmp 0x35ca
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x35cd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x35cd
jmp 0x365f
jmp 0x3580
movq %rax, %rbx
jmp 0x35d7
jmp 0x3580
jmp 0x3580
jmp 0x365f
jmp 0x3580
jmp 0x365f
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x35f1
movq 0x50(%rsp), %rsi
incq %rsi
jmp 0x35ec
jmp 0x365f
movq %rax, %rbx
jmp 0x3595
jmp 0x3580
movq %rax, %rbx
jmp 0x359f
jmp 0x365f
movq %rax, %rbx
jmp 0x35a9
jmp 0x3580
jmp 0x3580
jmp 0x3580
movq %rax, %rbx
jmp 0x35f1
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x394a
leaq 0x70(%rsp), %rdi
callq 0x394a
leaq 0x10(%rsp), %rdi
callq 0x394a
leaq 0x40(%rsp), %rdi
callq 0x394a
jmp 0x35f1
jmp 0x35ca
jmp 0x365f
jmp 0x35ca
jmp 0x35ca
jmp 0x365f
jmp 0x365f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x394a
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x35f1
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x3616
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x110(%rsp), %rdi
callq 0x3cc4
leaq 0x130(%rsp), %rdi
callq 0x3cc4
leaq 0x150(%rsp), %rdi
callq 0x3cc4
leaq 0x170(%rsp), %rdi
callq 0x3cc4
leaq 0xb0(%rsp), %rdi
callq 0x3cf4
movq %rbx, %rdi
callq 0x2270
movq %rax, %rdi
callq 0x3d4f