// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq 0x5d7e(%rip), %r14      # 0x8fd8
leaq 0x2e9e(%rip), %rsi      # 0x60ff
movl $0x6, %edx
movq %r14, %rdi
callq 0x2190
testq %rbx, %rbx
je 0x328f
movq %rbx, %rdi
callq 0x20a0
movq 0x5d56(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2190
jmp 0x32a7
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 0x330a
incq %rbx
movsbl %al, %esi
movq %r14, %rdi
callq 0x4372
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x32f6
leaq -0x50(%rbp), %r13
movl $0x0, (%r13)
xorl %eax, %eax
movq %rax, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rax, 0x20(%r13)
movq (%r14), %rdi
leaq -0x58(%rbp), %rsi
callq 0x39f5
movq -0x40(%rbp), %rbx
cmpq %r13, %rbx
je 0x3453
leaq -0x58(%rbp), %r15
leaq 0x20(%rbx), %r12
movq 0x20(%rbx), %rax
cmpq (%r14), %rax
je 0x335c
cmpl $0x1, 0x8(%rax)
jle 0x35de
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x339e
movq %r13, %r8
movq %r8, %rcx
movq %rdi, %rdx
movq 0x20(%rdi), %rsi
xorl %edi, %edi
cmpq %rax, %rsi
setb %dil
movq %rdx, %r8
cmovbq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3368
cmpq %r13, %r8
je 0x339e
cmpq %rax, %rsi
cmovbq %rcx, %rdx
cmpq 0x20(%rdx), %rax
jae 0x33b3
movq %r15, %rdi
movq %r12, %rsi
callq 0x3a8e
movl $0x0, (%rax)
movq (%r12), %rax
movq (%rax), %r12
movq 0x8(%r12), %r12
movq %r12, %rdi
callq 0x527c
testb %al, %al
jne 0x343b
movl (%r12), %eax
cmpl 0x20(%r14), %eax
jl 0x33b6
leaq 0x18(%r12), %rsi
movq -0x48(%rbp), %r8
testq %r8, %r8
je 0x341c
movq (%rsi), %rax
movq %r13, %r9
movq %r9, %rcx
movq %r8, %rdx
movq 0x20(%r8), %rdi
xorl %r8d, %r8d
cmpq %rax, %rdi
setb %r8b
movq %rdx, %r9
cmovbq %rcx, %r9
movq 0x10(%rdx,%r8,8), %r8
testq %r8, %r8
jne 0x33e5
cmpq %r13, %r9
je 0x341c
cmpq %rax, %rdi
cmovbq %rcx, %rdx
cmpq 0x20(%rdx), %rax
jae 0x342c
movq %r15, %rdi
callq 0x3a8e
movl $0x1, (%rax)
jmp 0x33b6
movq %r15, %rdi
callq 0x3a8e
incl (%rax)
jmp 0x33b6
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rbx
cmpq %r13, %rax
jne 0x3345
movq -0x40(%rbp), %rbx
cmpq %r13, %rbx
je 0x347b
movq (%r14), %r14
cmpq %r14, 0x20(%rbx)
je 0x346b
cmpl $0x1, 0x28(%rbx)
jle 0x3549
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rbx
cmpq %r13, %rax
jne 0x345b
movq 0x5b56(%rip), %rbx      # 0x8fd8
leaq 0x2ca6(%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 0x5b24(%rip), %rdi      # 0x8fd8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq 0x5b10(%rip), %rbx      # 0x8fd8
leaq 0x2be6(%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 0x5ade(%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 -0x58(%rbp), %rdi
callq 0x3b04
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5a88(%rip), %rdi      # 0x8fd8
leaq 0x2baf(%rip), %rsi      # 0x6106
movl $0xa, %edx
callq 0x2190
movq 0x5a70(%rip), %rdi      # 0x8fd8
callq 0x20b0
movq 0x5a64(%rip), %rdi      # 0x8fd8
leaq 0x2b96(%rip), %rsi      # 0x6111
movl $0x9, %edx
callq 0x2190
movq 0x20(%rbx), %rax
movl 0xc(%rax), %esi
movq 0x5a45(%rip), %rdi      # 0x8fd8
callq 0x2200
movq %rax, %r14
leaq 0x2b79(%rip), %rsi      # 0x611b
movl $0xc, %edx
movq %rax, %rdi
callq 0x2190
movl 0x28(%rbx), %esi
movq %r14, %rdi
callq 0x2200
movq %rax, %rbx
leaq 0x2b64(%rip), %rsi      # 0x6128
movl $0x6, %edx
movq %rax, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x20b0
jmp 0x3672
movq 0x59f3(%rip), %rdi      # 0x8fd8
leaq 0x2b1a(%rip), %rsi      # 0x6106
movl $0xa, %edx
callq 0x2190
movq 0x59db(%rip), %rdi      # 0x8fd8
callq 0x20b0
movq 0x59cf(%rip), %rdi      # 0x8fd8
leaq 0x2b01(%rip), %rsi      # 0x6111
movl $0x9, %edx
callq 0x2190
movq (%r12), %rax
movl 0xc(%rax), %esi
movq 0x59b0(%rip), %rdi      # 0x8fd8
callq 0x2200
movq %rax, %rbx
leaq 0x2ae4(%rip), %rsi      # 0x611b
movl $0xc, %edx
movq %rax, %rdi
callq 0x2190
movq (%r12), %rax
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x2200
movq %rax, %rbx
leaq 0x2acb(%rip), %rsi      # 0x6128
movl $0x6, %edx
movq %rax, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x20b0
movl $0x1, %edi
callq 0x21a0
jmp 0x3694
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
callq 0x2170
jmp 0x36a0
jmp 0x3694
jmp 0x3694
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x3b04
movq %rbx, %rdi
callq 0x2210