// File: /workspace/github_cpp_makefile_star2_O2/Ahhgust[P]STRaitRazor/trie.cpp
// Function: Trie::addPermutations(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int, unsigned int, unsigned char, unsigned char, unsigned char)
void
Trie::addPermutations(string w, unsigned wordLen, unsigned id, unsigned char type1, unsigned char type2, unsigned char distance) {


  unsigned i, j;
  char letter, l1, l2;

  addWord(w.c_str(), wordLen, id, type1);
  addWordRC(w.c_str(), wordLen, id, type2);


  if (distance > 0) {
  // this does all of the (3*kmer.len) single-base substitution permutations
  // and adds them to the vector
    for (i=0; i < wordLen; ++i) {
      
      letter = w[i];
      
      if (letter != 'A') {
        w[i] = 'A';
        addWord(w.c_str(), wordLen, id, type1);
        addWordRC(w.c_str(), wordLen, id, type2);
      }
      if (letter != 'C') {
        w[i] = 'C';
        addWord(w.c_str(), wordLen, id, type1);
        addWordRC(w.c_str(), wordLen, id, type2);
      }
      if (letter != 'G') {
        w[i] = 'G';
        addWord(w.c_str(), wordLen, id, type1);
        addWordRC(w.c_str(), wordLen, id, type2);
      }
      if (letter != 'T') {
        w[i] = 'T';
        addWord(w.c_str(), wordLen, id, type1);
        addWordRC(w.c_str(), wordLen, id, type2);
      }
      // undo the substitution at base position i
      w[i] = letter;
    }
  } 

  if (distance > 1) { // all of the two-base substitutions as well

    char LETTERS[4] = {'A','C','G','T'};
    
    // every single pair of positions
    for (i=0; i < wordLen; ++i) {
      l1 = w[i];
      for (j=i+1; j < wordLen; ++j) {
        l2 = w[j];

	// every single pair of base pair changes
        unsigned char a, b;
        for (a=0; a < 4; ++a) {
          for (b=0; b < 4; ++b) {
            if (LETTERS[a] != l1 && LETTERS[b] != l2) { // make sure what we're adding is unique
              w[i] = LETTERS[a];
              w[j] = LETTERS[b];

              addWord(w.c_str(), wordLen, id, type1);
              addWordRC(w.c_str(), wordLen, id, type2);
              w[i] = l1;
              w[j] = l2;

            }
          }
        }
      }
    }
    

  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r13d
movl %r8d, %r12d
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movq (%rsi), %rsi
callq 0x88de
movq (%r14), %rsi
movq %r15, 0x28(%rsp)
movq %r15, %rdi
movl %ebp, %edx
movl %ebx, 0x14(%rsp)
movl %ebx, %ecx
movl %r13d, %r8d
callq 0x8a14
cmpb $0x0, 0x80(%rsp)
je 0x8d49
movl %ebp, %eax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movzbl %r12b, %r8d
movzbl %r13b, %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rsp), %r15d
movq 0x28(%rsp), %r12
movl %r8d, 0x4(%rsp)
cmpq %rbx, 0x20(%rsp)
je 0x8d3f
movq (%r14), %rax
movb (%rax,%rbx), %cl
movb %cl, 0x8(%rsp)
cmpb $0x41, %cl
je 0x8c8e
movb $0x41, (%rax,%rbx)
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x88de
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl 0x10(%rsp), %r13d
movl %r13d, %r8d
callq 0x8a14
cmpb $0x43, 0x8(%rsp)
je 0x8cc1
movq (%r14), %rax
movl 0x4(%rsp), %r8d
movb $0x43, (%rax,%rbx)
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x88de
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl 0x10(%rsp), %r13d
movl %r13d, %r8d
callq 0x8a14
cmpb $0x47, 0x8(%rsp)
je 0x8cf9
movq (%r14), %rax
movb $0x47, (%rax,%rbx)
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl 0x4(%rsp), %r8d
callq 0x88de
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl %r13d, %r8d
callq 0x8a14
movb 0x8(%rsp), %cl
cmpb $0x54, %cl
je 0x8d2c
movq (%r14), %rax
movb $0x54, (%rax,%rbx)
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl 0x4(%rsp), %r8d
callq 0x88de
movq (%r14), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl %r13d, %r8d
callq 0x8a14
movb 0x8(%rsp), %cl
movq (%r14), %rax
movb %cl, (%rax,%rbx)
incq %rbx
movl 0x4(%rsp), %r8d
jmp 0x8c39
cmpb $0x1, 0x80(%rsp)
jne 0x8d58
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edx, %edx
leaq 0x213f(%rip), %rcx      # 0xaea0
movl %ebp, 0x18(%rsp)
movq 0x28(%rsp), %rbx
cmpq 0x20(%rsp), %rdx
je 0x8d49
movq (%r14), %rax
movb (%rax,%rdx), %sil
leaq 0x1(%rdx), %rax
movq %rax, 0x30(%rsp)
movq %rdx, 0x40(%rsp)
movb %sil, 0x1(%rsp)
cmpl %ebp, %eax
jae 0x8e82
movl %eax, 0x1c(%rsp)
movl %eax, %edi
movq (%r14), %rax
movq %rdi, 0x8(%rsp)
movb (%rax,%rdi), %dil
xorl %eax, %eax
movb %dil, 0x2(%rsp)
cmpq $0x4, %rax
je 0x8e73
movq %rax, 0x38(%rsp)
movb (%rax,%rcx), %r9b
xorl %r12d, %r12d
movb %r9b, 0x3(%rsp)
cmpq $0x4, %r12
je 0x8e66
cmpb %sil, %r9b
je 0x8e5e
movb (%r12,%rcx), %al
cmpb %dil, %al
je 0x8e5e
movq (%r14), %rcx
movb %r9b, (%rcx,%rdx)
movq (%r14), %rcx
movq 0x8(%rsp), %r10
movb %al, (%rcx,%r10)
movq (%r14), %rsi
movq %rbx, %rdi
movq %r14, %r15
movl 0x18(%rsp), %r14d
movl %r14d, %edx
movl 0x14(%rsp), %ebp
movl %ebp, %ecx
movl %r8d, %r13d
callq 0x88de
movq (%r15), %rsi
movq %rbx, %rdi
movl %r14d, %edx
movq %r15, %r14
movl %ebp, %ecx
movl 0x10(%rsp), %r8d
callq 0x8a14
movb 0x3(%rsp), %r9b
movb 0x2(%rsp), %dil
movb 0x1(%rsp), %sil
leaq 0x205d(%rip), %rcx      # 0xaea0
movq 0x40(%rsp), %rdx
movl %r13d, %r8d
movq (%r15), %rax
movb %sil, (%rax,%rdx)
movq (%r15), %rax
movq 0x8(%rsp), %r10
movb %dil, (%rax,%r10)
incq %r12
jmp 0x8dc7
movq 0x38(%rsp), %rax
incq %rax
jmp 0x8dac
movl 0x1c(%rsp), %eax
incl %eax
movl 0x18(%rsp), %ebp
jmp 0x8d8b
movq 0x30(%rsp), %rdx
jmp 0x8d6a