// File: 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
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq 0xddd2(%rip), %rdi      # 0x10fd8
leaq 0x7ef2(%rip), %rsi      # 0xb0ff
callq 0x2150
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
movq 0xdda0(%rip), %rsi      # 0x10fc8
callq 0x2190
movl $0x28, %edi
callq 0x2160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x7ef0
jmp 0x3255
movq -0xb0(%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 0x32ba
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 0x3267
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x2170
jmp 0x3801
leaq -0x50(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x4150
leaq -0x58(%rbp), %rdi
callq 0x4170
movq -0xb8(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3cd0
jmp 0x32e8
movb $0x1, -0x59(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4190
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x41f0
movq %rax, -0x70(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x41c0
testb $0x1, %al
jne 0x3324
jmp 0x35fc
leaq -0x58(%rbp), %rdi
callq 0x4220
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
je 0x345d
leaq -0x58(%rbp), %rdi
callq 0x4220
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jg 0x345d
movb $0x0, -0x59(%rbp)
movq 0xdc7a(%rip), %rdi      # 0x10fd8
leaq 0x7da1(%rip), %rsi      # 0xb106
callq 0x2150
movq %rax, -0xc0(%rbp)
jmp 0x3373
movq -0xc0(%rbp), %rdi
movq 0xdc47(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x3388
movq 0xdc49(%rip), %rdi      # 0x10fd8
leaq 0x7d7b(%rip), %rsi      # 0xb111
callq 0x2150
movq %rax, -0xc8(%rbp)
jmp 0x33a4
leaq -0x58(%rbp), %rdi
callq 0x4220
movq -0xc8(%rbp), %rdi
movq (%rax), %rax
movl 0xc(%rax), %esi
callq 0x2250
movq %rax, -0xd0(%rbp)
jmp 0x33c8
movq -0xd0(%rbp), %rdi
leaq 0x7d45(%rip), %rsi      # 0xb11b
callq 0x2150
movq %rax, -0xd8(%rbp)
jmp 0x33e4
leaq -0x58(%rbp), %rdi
callq 0x4220
movq -0xd8(%rbp), %rdi
movq (%rax), %rax
movl 0x8(%rax), %esi
callq 0x2250
movq %rax, -0xe0(%rbp)
jmp 0x3408
movq -0xe0(%rbp), %rdi
leaq 0x7d12(%rip), %rsi      # 0xb128
callq 0x2150
movq %rax, -0xe8(%rbp)
jmp 0x3424
movq -0xe8(%rbp), %rdi
movq 0xdb96(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x3439
movl $0x1, %edi
callq 0x21f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x42d0
jmp 0x3801
leaq -0x58(%rbp), %rdi
callq 0x4220
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4270
movq %rax, -0xf0(%rbp)
jmp 0x347b
movq -0xf0(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x41f0
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x4240
testb $0x1, %al
jne 0x34a6
jmp 0x34d1
leaq -0x58(%rbp), %rdi
callq 0x4220
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4070
movq %rax, -0xf8(%rbp)
jmp 0x34c4
movq -0xf8(%rbp), %rax
movl $0x0, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x4220
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x9e50
movb %al, -0xf9(%rbp)
jmp 0x34ff
movb -0xf9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3510
jmp 0x35ec
movq -0x88(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jl 0x35d3
movq -0x88(%rbp), %rsi
addq $0x18, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4270
movq %rax, -0x108(%rbp)
jmp 0x3543
movq -0x108(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x41f0
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4240
testb $0x1, %al
jne 0x357a
jmp 0x35a6
movq -0x88(%rbp), %rsi
addq $0x18, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4070
movq %rax, -0x110(%rbp)
jmp 0x3597
movq -0x110(%rbp), %rax
movl $0x1, (%rax)
jmp 0x35d1
movq -0x88(%rbp), %rsi
addq $0x18, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4070
movq %rax, -0x118(%rbp)
jmp 0x35c3
movq -0x118(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x35d3
jmp 0x35d5
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0x34eb
jmp 0x35ee
leaq -0x58(%rbp), %rdi
callq 0x42a0
jmp 0x3301
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 0x3640
jmp 0x3769
leaq -0x58(%rbp), %rdi
callq 0x4220
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
je 0x3759
leaq -0x58(%rbp), %rdi
callq 0x4220
cmpl $0x1, 0x8(%rax)
jg 0x3759
movb $0x0, -0x59(%rbp)
movq 0xd961(%rip), %rdi      # 0x10fd8
leaq 0x7a88(%rip), %rsi      # 0xb106
callq 0x2150
movq %rax, -0x120(%rbp)
jmp 0x368c
movq -0x120(%rbp), %rdi
movq 0xd92e(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x36a1
movq 0xd930(%rip), %rdi      # 0x10fd8
leaq 0x7a62(%rip), %rsi      # 0xb111
callq 0x2150
movq %rax, -0x128(%rbp)
jmp 0x36bd
leaq -0x58(%rbp), %rdi
callq 0x4220
movq -0x128(%rbp), %rdi
movq (%rax), %rax
movl 0xc(%rax), %esi
callq 0x2250
movq %rax, -0x130(%rbp)
jmp 0x36e1
movq -0x130(%rbp), %rdi
leaq 0x7a2c(%rip), %rsi      # 0xb11b
callq 0x2150
movq %rax, -0x138(%rbp)
jmp 0x36fd
leaq -0x58(%rbp), %rdi
callq 0x4220
movq -0x138(%rbp), %rdi
movl 0x8(%rax), %esi
callq 0x2250
movq %rax, -0x140(%rbp)
jmp 0x371e
movq -0x140(%rbp), %rdi
leaq 0x79fc(%rip), %rsi      # 0xb128
callq 0x2150
movq %rax, -0x148(%rbp)
jmp 0x373a
movq -0x148(%rbp), %rdi
movq 0xd880(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x374f
movl $0x1, %edi
callq 0x21f0
jmp 0x375b
leaq -0x58(%rbp), %rdi
callq 0x42a0
jmp 0x3617
testb $0x1, -0x59(%rbp)
je 0x37a2
movq 0xd862(%rip), %rdi      # 0x10fd8
leaq 0x79b2(%rip), %rsi      # 0xb12f
callq 0x2150
movq %rax, -0x150(%rbp)
jmp 0x378b
movq -0x150(%rbp), %rdi
movq 0xd82f(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x37a0
jmp 0x37a2
movq 0xd82f(%rip), %rdi      # 0x10fd8
leaq 0x7905(%rip), %rsi      # 0xb0b5
callq 0x2150
movq %rax, -0x158(%rbp)
jmp 0x37be
movq -0x158(%rbp), %rdi
movq 0xd7fc(%rip), %rsi      # 0x10fc8
callq 0x2190
movq %rax, -0x160(%rbp)
jmp 0x37da
movq -0x160(%rbp), %rdi
movq 0xd7e0(%rip), %rsi      # 0x10fc8
callq 0x2190
jmp 0x37ef
leaq -0x50(%rbp), %rdi
callq 0x42d0
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x2260
nopw (%rax,%rax)