// File: 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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq 0xd7b2(%rip), %rdi      # 0x10fd8
leaq 0x78d2(%rip), %rsi      # 0xb0ff
callq 0x2150
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
movq 0xd780(%rip), %rsi      # 0x10fc8
callq 0x2190
movl $0x28, %edi
callq 0x2160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x7ef0
jmp 0x3875
movq -0xe0(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x38da
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x7ff0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3887
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x2170
jmp 0x3cc5
leaq -0x50(%rbp), %rdi
callq 0x4150
leaq -0x58(%rbp), %rdi
callq 0x4170
leaq 0x45d(%rip), %rax       # 0x3d50
movq %rax, -0x60(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x43d0
movq -0xe8(%rbp), %rdx
leaq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x43f0
jmp 0x3923
leaq -0x91(%rbp), %rdi
callq 0x4470
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3cd0
jmp 0x3941
movb $0x0, -0x92(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4190
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x41f0
movq %rax, -0xa8(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x41c0
testb $0x1, %al
jne 0x398c
jmp 0x3c15
leaq -0x58(%rbp), %rdi
callq 0x4220
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x9e50
movb %al, -0xe9(%rbp)
jmp 0x39ba
movb -0xe9(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xea(%rbp)
jne 0x39f5
jmp 0x39cf
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x9e50
movb %al, -0xeb(%rbp)
jmp 0x39e7
movb -0xeb(%rbp), %al
xorb $-0x1, %al
movb %al, -0xea(%rbp)
movb -0xea(%rbp), %al
testb $0x1, %al
jne 0x3a04
jmp 0x3bfa
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x44c0
movq %rax, -0xf8(%rbp)
jmp 0x3a20
movq -0xf8(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4500
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x4490
testb $0x1, %al
jne 0x3a5a
jmp 0x3ad5
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4530
movb %dl, -0x101(%rbp)
movq %rax, -0x100(%rbp)
jmp 0x3a7c
movb -0x101(%rbp), %al
movq -0x100(%rbp), %rcx
movq %rcx, -0xd0(%rbp)
movb %al, -0xc8(%rbp)
jmp 0x3be1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x4470
jmp 0x3cbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x45a0
jmp 0x3cbc
movq -0xb0(%rbp), %rax
movl (%rax), %eax
movq -0xb0(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x3b09
movq -0xb0(%rbp), %rax
movl (%rax), %eax
movq -0xb0(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
je 0x3bdf
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x44c0
movq %rax, -0x110(%rbp)
jmp 0x3b25
movq -0x110(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x4580
movq (%rax), %rdi
callq 0xa050
jmp 0x3b49
movb $0x1, -0x92(%rbp)
movq 0xd481(%rip), %rdi      # 0x10fd8
leaq 0x75a8(%rip), %rsi      # 0xb106
callq 0x2150
movq %rax, -0x118(%rbp)
jmp 0x3b6c
movq -0x118(%rbp), %rdi
movq 0xd44e(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x3b81
movq 0xd450(%rip), %rdi      # 0x10fd8
leaq 0x766f(%rip), %rsi      # 0xb1fe
callq 0x2150
jmp 0x3b96
movq -0xb0(%rbp), %rdi
callq 0xa050
jmp 0x3ba4
movq 0xd42d(%rip), %rdi      # 0x10fd8
leaq 0x7655(%rip), %rsi      # 0xb207
callq 0x2150
movq %rax, -0x120(%rbp)
jmp 0x3bc0
movq -0x120(%rbp), %rdi
movq 0xd3fa(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x3bd5
movl $0x1, %edi
callq 0x21f0
jmp 0x3be1
jmp 0x3be3
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x39a6
testb $0x1, -0x92(%rbp)
je 0x3c05
jmp 0x3c15
jmp 0x3c07
leaq -0x58(%rbp), %rdi
callq 0x42a0
jmp 0x3963
testb $0x1, -0x92(%rbp)
jne 0x3c51
movq 0xd3b3(%rip), %rdi      # 0x10fd8
leaq 0x7503(%rip), %rsi      # 0xb12f
callq 0x2150
movq %rax, -0x128(%rbp)
jmp 0x3c3a
movq -0x128(%rbp), %rdi
movq 0xd380(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x3c4f
jmp 0x3c51
movq 0xd380(%rip), %rdi      # 0x10fd8
leaq 0x7456(%rip), %rsi      # 0xb0b5
callq 0x2150
movq %rax, -0x130(%rbp)
jmp 0x3c6d
movq -0x130(%rbp), %rdi
movq 0xd34d(%rip), %rsi      # 0x10fc8
callq 0x2190
movq %rax, -0x138(%rbp)
jmp 0x3c89
movq -0x138(%rbp), %rdi
movq 0xd331(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x3c9e
leaq -0x90(%rbp), %rdi
callq 0x45a0
leaq -0x50(%rbp), %rdi
callq 0x42d0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x42d0
movq -0x18(%rbp), %rdi
callq 0x2260
nop