// File: /workspace/github_cpp_makefile_star2_O2/elarielcl[P]ArielsSequitur/TestSequitur.cpp
// Function: digramUniquenessTest(char*)
void digramUniquenessTest(char string[]) {
  cout << "INPUT=" << string << endl;
  SequiturGrammar* grammar = new SequiturGrammar();
  for (int i = 0; string[i]!=0; ++i)
    grammar->put(string[i]);

  map<Rule*, int> rules;
  map<Rule*, int>  :: iterator r;

  bool(*fn_pt)(Node*,Node*) = digramEquality;
  set<Node*,bool(*)(Node*,Node*)> digrams (fn_pt);


  getRules(grammar->initialRule, &rules);

  bool hasRepeatedDigram = false;
  for (r = rules.begin(); r != rules.end(); ++r) {
    for (Node* current = r->first->guard->next; !current->isGuard() && !current->next->isGuard(); current = current->next) {
        if(digrams.find(current) == digrams.end()) {
          digrams.insert(current);
        }else if (!(current->symbol == current->prev->symbol && current->symbol == current->next->symbol)){
          (*(digrams.find(current)))->printDigram();
          hasRepeatedDigram = true;
          cout << "WRONG TEST" << endl;
          cout << "Digram: ";
          current->printDigram();
          cout << "is not unique"  << endl;
          exit(1);;
        }
      }
      if (hasRepeatedDigram) break;

  }
  if (!hasRepeatedDigram) cout << "SUCCESSFUL TEST" << endl;
  cout << "================" << endl << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x518f(%rip), %rdi      # 0x7fd8
leaq 0x22af(%rip), %rsi      # 0x50ff
callq 0x2130
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
pushq $0x28
popq %rdi
callq 0x2140
movq %rax, %r14
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x3bf4
jmp 0x2e92
movq %r14, %rdi
callq 0x3c7e
incq %rbx
movsbl (%rbx), %esi
testl %esi, %esi
jne 0x2e87
leaq -0x88(%rbp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
leaq 0x223(%rip), %rax       # 0x30e5
leaq -0x58(%rbp), %r13
movq %rax, -0x8(%r13)
andl $0x0, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
andq $0x0, 0x20(%r13)
movq (%r14), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3082
movq -0x78(%rbp), %r15
leaq -0x60(%rbp), %rbx
leaq -0x30(%rbp), %r14
cmpq %r12, %r15
je 0x2f76
movq 0x20(%r15), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x4a88
testb %al, %al
jne 0x2f69
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4a88
testb %al, %al
jne 0x2f69
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39a8
cmpq %r13, %rax
je 0x2f59
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq 0x10(%rax), %rdx
cmpl (%rdx), %ecx
jne 0x2fd8
movq 0x8(%rax), %rdx
movq %r14, %rax
cmpl (%rdx), %ecx
je 0x2f05
jmp 0x2fd8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3a34
movq %r14, %rax
jmp 0x2f05
movq %r15, %rdi
callq 0x20d0
movq %rax, %r15
jmp 0x2efc
movq 0x505b(%rip), %rdi      # 0x7fd8
leaq 0x21ab(%rip), %rsi      # 0x512f
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq 0x5040(%rip), %rdi      # 0x7fd8
leaq 0x2116(%rip), %rsi      # 0x50b5
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
callq 0x20b0
leaq -0x60(%rbp), %rdi
callq 0x3212
leaq -0x90(%rbp), %rdi
callq 0x31b6
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x60(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x39a8
movq 0x20(%rax), %rdi
callq 0x4b9a
movq 0x4fe3(%rip), %rdi      # 0x7fd8
leaq 0x210a(%rip), %rsi      # 0x5106
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq 0x4fc8(%rip), %rdi      # 0x7fd8
leaq 0x21e7(%rip), %rsi      # 0x51fe
callq 0x2130
movq -0x30(%rbp), %rdi
callq 0x4b9a
movq 0x4fac(%rip), %rdi      # 0x7fd8
leaq 0x21d4(%rip), %rsi      # 0x5207
callq 0x2130
movq %rax, %rdi
callq 0x20b0
pushq $0x1
popq %rdi
callq 0x2180
jmp 0x3062
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x2150
jmp 0x307a
jmp 0x3062
jmp 0x3062
jmp 0x3062
jmp 0x3062
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x3212
leaq -0x90(%rbp), %rdi
callq 0x31b6
movq %rbx, %rdi
callq 0x21e0