// File: /workspace/github_cpp_makefile_star2_O3/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 0x5915(%rip), %r14      # 0x8fd8
leaq 0x2a35(%rip), %rsi      # 0x60ff
movl $0x6, %edx
movq %r14, %rdi
callq 0x2190
testq %rbx, %rbx
je 0x36f8
movq %rbx, %rdi
callq 0x20a0
movq 0x58ed(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2190
jmp 0x3710
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x21f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x28, %edi
callq 0x2160
movq %rax, %r14
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x42dc
movb (%rbx), %al
testb %al, %al
je 0x3773
incq %rbx
movsbl %al, %esi
movq %r14, %rdi
callq 0x4372
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x375f
leaq -0x88(%rbp), %r12
xorl %eax, %eax
movl %eax, (%r12)
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq 0x2ce(%rip), %rcx       # 0x3a69
leaq -0x58(%rbp), %r13
movq %rcx, -0x8(%r13)
movl %eax, (%r13)
movq %rax, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rax, 0x20(%r13)
movq (%r14), %rdi
leaq -0x90(%rbp), %rsi
callq 0x39f5
movq -0x78(%rbp), %rbx
cmpq %r12, %rbx
je 0x3856
leaq -0x60(%rbp), %r14
leaq -0x30(%rbp), %r15
movq 0x20(%rbx), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x527c
testb %al, %al
jne 0x3846
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x527c
testb %al, %al
jne 0x3846
movq %r14, %rdi
movq %r15, %rsi
callq 0x4134
cmpq %r13, %rax
je 0x3836
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq 0x10(%rax), %rdx
cmpl (%rdx), %ecx
jne 0x3930
movq 0x8(%rax), %rdx
movq %r15, %rax
cmpl (%rdx), %ecx
je 0x37df
jmp 0x3930
movq %r14, %rdi
movq %r15, %rsi
callq 0x419e
movq %r15, %rax
jmp 0x37df
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rbx
cmpq %r12, %rax
jne 0x37db
movq 0x577b(%rip), %rbx      # 0x8fd8
leaq 0x28cb(%rip), %rsi      # 0x612f
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2190
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq 0x5749(%rip), %rdi      # 0x8fd8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq 0x5735(%rip), %rbx      # 0x8fd8
leaq 0x280b(%rip), %rsi      # 0x60b5
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2190
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq 0x5703(%rip), %rdi      # 0x8fd8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0x60(%rbp), %rdi
callq 0x3b62
leaq -0x90(%rbp), %rdi
callq 0x3b04
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 0x4134
movq 0x20(%rax), %rdi
callq 0x53f2
movq 0x568b(%rip), %rdi      # 0x8fd8
leaq 0x27b2(%rip), %rsi      # 0x6106
movl $0xa, %edx
callq 0x2190
movq 0x5673(%rip), %rdi      # 0x8fd8
callq 0x20b0
movq 0x5667(%rip), %rdi      # 0x8fd8
leaq 0x2886(%rip), %rsi      # 0x61fe
movl $0x8, %edx
callq 0x2190
movq -0x30(%rbp), %rdi
callq 0x53f2
movq 0x5646(%rip), %rdi      # 0x8fd8
leaq 0x286e(%rip), %rsi      # 0x6207
movl $0xd, %edx
callq 0x2190
movq 0x562e(%rip), %rdi      # 0x8fd8
callq 0x20b0
movl $0x1, %edi
callq 0x21a0
jmp 0x39d5
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
callq 0x2170
jmp 0x39ed
jmp 0x39d5
jmp 0x39d5
jmp 0x39d5
jmp 0x39d5
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x3b62
leaq -0x90(%rbp), %rdi
callq 0x3b04
movq %rbx, %rdi
callq 0x2210