// File: /workspace/github_cpp_makefile_star2_O1/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 0x5d54(%rip), %rbx      # 0x8fd8
leaq 0x2e74(%rip), %rsi      # 0x60ff
movl $0x6, %edx
movq %rbx, %rdi
callq 0x2190
testq %r14, %r14
je 0x32b9
movq %r14, %rdi
callq 0x20a0
movq 0x5d2c(%rip), %rdi      # 0x8fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x2190
jmp 0x32d0
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x21f0
movq (%rbx), %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
movl $0x28, %edi
callq 0x2160
movq %rax, %rbx
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x430c
movb (%r14), %al
testb %al, %al
je 0x3335
incq %r14
movsbl %al, %esi
movq %rbx, %rdi
callq 0x43a2
movb (%r14), %al
incq %r14
testb %al, %al
jne 0x3320
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 (%rbx), %rdi
leaq -0x58(%rbp), %rsi
callq 0x3a1a
movq -0x40(%rbp), %r14
cmpq %r13, %r14
je 0x3472
leaq -0x58(%rbp), %r15
leaq 0x20(%r14), %r12
movq 0x20(%r14), %rax
cmpq (%rbx), %rax
je 0x3387
cmpl $0x1, 0x8(%rax)
jle 0x3603
movq -0x48(%rbp), %rdx
movq %r13, %rcx
testq %rdx, %rdx
je 0x33ae
movq %r13, %rcx
xorl %esi, %esi
cmpq %rax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x3396
movq %r13, %rdx
cmpq %r13, %rcx
je 0x33c1
cmpq 0x20(%rcx), %rax
cmovbq %r13, %rcx
movq %rcx, %rdx
cmpq %r13, %rdx
jne 0x33d7
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ab2
movl $0x0, (%rax)
movq (%r12), %rax
movq (%rax), %r12
movq 0x8(%r12), %r12
movq %r12, %rdi
callq 0x5314
testb %al, %al
jne 0x345e
movl (%r12), %eax
cmpl 0x20(%rbx), %eax
jl 0x33de
leaq 0x18(%r12), %rsi
movq -0x48(%rbp), %rcx
movq %r13, %rax
testq %rcx, %rcx
je 0x3427
movq (%rsi), %rdx
movq %r13, %rax
xorl %edi, %edi
cmpq %rdx, 0x20(%rcx)
setb %dil
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdi,8), %rcx
testq %rcx, %rcx
jne 0x340f
movq %r13, %rcx
cmpq %r13, %rax
je 0x343d
movq (%rsi), %rcx
cmpq 0x20(%rax), %rcx
cmovbq %r13, %rax
movq %rax, %rcx
cmpq %r13, %rcx
je 0x344e
movq %r15, %rdi
callq 0x3ab2
incl (%rax)
jmp 0x33de
movq %r15, %rdi
callq 0x3ab2
movl $0x1, (%rax)
jmp 0x33de
movq %r14, %rdi
callq 0x20e0
movq %rax, %r14
cmpq %r13, %rax
jne 0x3370
movq -0x40(%rbp), %r14
cmpq %r13, %r14
je 0x349f
movq (%rbx), %rbx
cmpq %rbx, 0x20(%r14)
je 0x348f
cmpl $0x1, 0x28(%r14)
jle 0x356d
movq %r14, %rdi
callq 0x20e0
movq %rax, %r14
cmpq %r13, %rax
jne 0x347e
movq 0x5b32(%rip), %rbx      # 0x8fd8
leaq 0x2c82(%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 0x5b00(%rip), %rdi      # 0x8fd8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq 0x5aec(%rip), %rbx      # 0x8fd8
leaq 0x2bc2(%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 0x5aba(%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 0x3b2a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5a64(%rip), %rdi      # 0x8fd8
leaq 0x2b8b(%rip), %rsi      # 0x6106
movl $0xa, %edx
callq 0x2190
movq 0x5a4c(%rip), %rdi      # 0x8fd8
callq 0x20b0
movq 0x5a40(%rip), %rdi      # 0x8fd8
leaq 0x2b72(%rip), %rsi      # 0x6111
movl $0x9, %edx
callq 0x2190
movq 0x20(%r14), %rax
movl 0xc(%rax), %esi
movq 0x5a21(%rip), %rdi      # 0x8fd8
callq 0x2200
movq %rax, %rbx
leaq 0x2b55(%rip), %rsi      # 0x611b
movl $0xc, %edx
movq %rax, %rdi
callq 0x2190
movl 0x28(%r14), %esi
movq %rbx, %rdi
callq 0x2200
movq %rax, %rbx
leaq 0x2b3f(%rip), %rsi      # 0x6128
movl $0x6, %edx
movq %rax, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x20b0
jmp 0x3697
movq 0x59ce(%rip), %rdi      # 0x8fd8
leaq 0x2af5(%rip), %rsi      # 0x6106
movl $0xa, %edx
callq 0x2190
movq 0x59b6(%rip), %rdi      # 0x8fd8
callq 0x20b0
movq 0x59aa(%rip), %rdi      # 0x8fd8
leaq 0x2adc(%rip), %rsi      # 0x6111
movl $0x9, %edx
callq 0x2190
movq (%r12), %rax
movl 0xc(%rax), %esi
movq 0x598b(%rip), %rdi      # 0x8fd8
callq 0x2200
movq %rax, %rbx
leaq 0x2abf(%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 0x2aa6(%rip), %rsi      # 0x6128
movl $0x6, %edx
movq %rax, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x20b0
movl $0x1, %edi
callq 0x21a0
jmp 0x36b9
movq %rax, %r14
movl $0x28, %esi
movq %rbx, %rdi
callq 0x2170
jmp 0x36c5
jmp 0x36b9
jmp 0x36b9
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0x3b2a
movq %r14, %rdi
callq 0x2210