// File: /workspace/github_cpp_makefile_star2_O1/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 0x58f0(%rip), %r14      # 0x8fd8
leaq 0x2a10(%rip), %rsi      # 0x60ff
movl $0x6, %edx
movq %r14, %rdi
callq 0x2190
testq %rbx, %rbx
je 0x371d
movq %rbx, %rdi
callq 0x20a0
movq 0x58c8(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2190
jmp 0x3735
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 0x430c
movb (%rbx), %al
testb %al, %al
je 0x3798
incq %rbx
movsbl %al, %esi
movq %r14, %rdi
callq 0x43a2
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x3784
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       # 0x3a8e
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 0x3a1a
movq -0x78(%rbp), %rbx
cmpq %r12, %rbx
je 0x387b
leaq -0x60(%rbp), %r14
leaq -0x30(%rbp), %r15
movq 0x20(%rbx), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq %rdi, -0x30(%rbp)
callq 0x5314
testb %al, %al
jne 0x386b
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5314
testb %al, %al
jne 0x386b
movq %r14, %rdi
movq %r15, %rsi
callq 0x4158
cmpq %r13, %rax
je 0x385b
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq 0x10(%rax), %rdx
cmpl (%rdx), %ecx
jne 0x3955
movq 0x8(%rax), %rdx
movq %r15, %rax
cmpl (%rdx), %ecx
je 0x3804
jmp 0x3955
movq %r14, %rdi
movq %r15, %rsi
callq 0x41c4
movq %r15, %rax
jmp 0x3804
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rbx
cmpq %r12, %rax
jne 0x3800
movq 0x5756(%rip), %rbx      # 0x8fd8
leaq 0x28a6(%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 0x5724(%rip), %rdi      # 0x8fd8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq 0x5710(%rip), %rbx      # 0x8fd8
leaq 0x27e6(%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 0x56de(%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 0x3b88
leaq -0x90(%rbp), %rdi
callq 0x3b2a
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 0x4158
movq 0x20(%rax), %rdi
callq 0x548a
movq 0x5666(%rip), %rdi      # 0x8fd8
leaq 0x278d(%rip), %rsi      # 0x6106
movl $0xa, %edx
callq 0x2190
movq 0x564e(%rip), %rdi      # 0x8fd8
callq 0x20b0
movq 0x5642(%rip), %rdi      # 0x8fd8
leaq 0x2861(%rip), %rsi      # 0x61fe
movl $0x8, %edx
callq 0x2190
movq -0x30(%rbp), %rdi
callq 0x548a
movq 0x5621(%rip), %rdi      # 0x8fd8
leaq 0x2849(%rip), %rsi      # 0x6207
movl $0xd, %edx
callq 0x2190
movq 0x5609(%rip), %rdi      # 0x8fd8
callq 0x20b0
movl $0x1, %edi
callq 0x21a0
jmp 0x39fa
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
callq 0x2170
jmp 0x3a12
jmp 0x39fa
jmp 0x39fa
jmp 0x39fa
jmp 0x39fa
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x3b88
leaq -0x90(%rbp), %rdi
callq 0x3b2a
movq %rbx, %rdi
callq 0x2210