// File: /workspace/github_cpp_makefile_star2_O2/elarielcl[P]ArielsSequitur/TestSequitur.cpp
// Function: ruleUsageTest(char*)
void ruleUsageTest(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;

  getRules(grammar->initialRule, &rules);

  bool correctUsage = true;
  for (r = rules.begin(); r != rules.end(); ++r) {
    if (r->first!= grammar->initialRule && r->first->usage <= 1) {
      correctUsage = false;
      cout << "WRONG TEST" << endl;
      cout << "Rule for " << r->first->symbol << " referenced " << r->first->usage << " times" << endl;
      exit(1);
    }
    if(rules.find(r->first) == rules.end()) rules[r->first] = 0;
    for (Node* current = r->first->guard->next; !current->isGuard(); current = current->next)
      if (current->symbol >= grammar->M)
        if(rules.find(current->rule) == rules.end()) rules[current->rule] = 1;
        else rules[current->rule]++;


  }
  for (r = rules.begin(); r != rules.end(); ++r) {
    if (r->first != grammar->initialRule && r->second <= 1) {
      correctUsage = false;
      cout << "WRONG TEST" << endl;
      cout << "Rule for " << r->first->symbol << " referenced " << r->second << " times" << endl;
      exit(1);
    }


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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movq 0x546a(%rip), %rdi      # 0x7fd8
leaq 0x258a(%rip), %rsi      # 0x50ff
callq 0x2130
movq %rax, %rdi
movq %r14, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
pushq $0x28
popq %rdi
callq 0x2140
movq %rax, %rbx
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x3bf4
jmp 0x2bb7
movq %rbx, %rdi
callq 0x3c7e
incq %r14
movsbl (%r14), %esi
testl %esi, %esi
jne 0x2bac
leaq -0x58(%rbp), %r15
andl $0x0, (%r15)
andq $0x0, 0x8(%r15)
movq %r15, 0x10(%r15)
movq %r15, 0x18(%r15)
andq $0x0, 0x20(%r15)
movq (%rbx), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3082
leaq -0x60(%rbp), %r14
movq 0x18(%r14), %rax
cmpq %r15, %rax
je 0x2c95
leaq 0x20(%rax), %r12
movq %rax, -0x30(%rbp)
movq 0x20(%rax), %rax
cmpq (%rbx), %rax
je 0x2c11
cmpl $0x1, 0x8(%rax)
jle 0x2d15
movq %r14, %rdi
movq %r12, %rsi
callq 0x38d4
cmpq %r15, %rax
jne 0x2c2f
movq %r14, %rdi
movq %r12, %rsi
callq 0x310a
andl $0x0, (%rax)
movq (%r12), %rax
movq (%rax), %r12
movq 0x8(%r12), %r12
movq %r12, %rdi
callq 0x4a88
testb %al, %al
jne 0x2c87
movl (%r12), %eax
cmpl 0x20(%rbx), %eax
jl 0x2c36
leaq 0x18(%r12), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x38d4
cmpq %r15, %rax
je 0x2c74
movq %r14, %rdi
movq %r13, %rsi
callq 0x310a
incl (%rax)
jmp 0x2c36
movq %r14, %rdi
movq %r13, %rsi
callq 0x310a
movl $0x1, (%rax)
jmp 0x2c36
movq -0x30(%rbp), %rdi
callq 0x20d0
jmp 0x2bed
movq -0x48(%rbp), %r14
cmpq %r15, %r14
je 0x2cbf
movq 0x20(%r14), %rax
cmpq (%rbx), %rax
je 0x2cb2
cmpl $0x1, 0x28(%r14)
jle 0x2d89
movq %r14, %rdi
callq 0x20d0
movq %rax, %r14
jmp 0x2c99
movq 0x5312(%rip), %rdi      # 0x7fd8
leaq 0x2462(%rip), %rsi      # 0x512f
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq 0x52f7(%rip), %rdi      # 0x7fd8
leaq 0x23cd(%rip), %rsi      # 0x50b5
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
callq 0x20b0
leaq -0x60(%rbp), %rdi
callq 0x31b6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x52bc(%rip), %rdi      # 0x7fd8
leaq 0x23e3(%rip), %rsi      # 0x5106
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq 0x52a1(%rip), %rdi      # 0x7fd8
leaq 0x23d3(%rip), %rsi      # 0x5111
callq 0x2130
movq (%r12), %rcx
movl 0xc(%rcx), %esi
movq %rax, %rdi
callq 0x21d0
leaq 0x23c2(%rip), %rsi      # 0x511b
movq %rax, %rdi
callq 0x2130
movq (%r12), %rcx
movl 0x8(%rcx), %esi
movq %rax, %rdi
callq 0x21d0
leaq 0x23b1(%rip), %rsi      # 0x5128
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
jmp 0x2df8
movq 0x5248(%rip), %rdi      # 0x7fd8
leaq 0x236f(%rip), %rsi      # 0x5106
callq 0x2130
movq %rax, %rdi
callq 0x20b0
movq 0x522d(%rip), %rdi      # 0x7fd8
leaq 0x235f(%rip), %rsi      # 0x5111
callq 0x2130
movq 0x20(%r14), %rcx
movl 0xc(%rcx), %esi
movq %rax, %rdi
callq 0x21d0
leaq 0x234e(%rip), %rsi      # 0x511b
movq %rax, %rdi
callq 0x2130
movl 0x28(%r14), %esi
movq %rax, %rdi
callq 0x21d0
leaq 0x2340(%rip), %rsi      # 0x5128
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
pushq $0x1
popq %rdi
callq 0x2180
jmp 0x2e1a
movq %rax, %r14
pushq $0x28
popq %rsi
movq %rbx, %rdi
callq 0x2150
jmp 0x2e26
jmp 0x2e1a
jmp 0x2e1a
jmp 0x2e1a
jmp 0x2e1a
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x31b6
movq %r14, %rdi
callq 0x21e0