// File: elarielcl[P]ArielsSequitur/Sequitur.cpp
// Function: main
int main(int argc, char **argv) {
  extern char *optarg;
  extern int optind, opterr;
  FILE *fp = stdin;

  int c;

  while ((c = getopt(argc, argv, "f:")) != -1) {
    switch (c) {
      case 'f':
      fp = fopen(optarg, "r");
      if (fp == NULL) {
        cerr << "Error oppening \"" << optarg << "\" file" << endl;
        exit(1);
      } break;
    }
  }

  SequiturGrammar grammar;
  while (!feof(fp)) {
    int c = fgetc(fp);
    if (c == EOF) break;
    grammar.put(c);
  }

  fprintf (stderr,"\nSequitur succeeded\n\n");
  fprintf (stderr,"Grammar\n\n");
  grammar.print();

  fprintf (stderr,"Original chars: %i\n",grammar.inputSize);
  fprintf (stderr,"Number of rules: %i\n",grammar.numberOfRules);
  fprintf (stderr,"Grammar Size: %i\n",grammar.grammarSize);
  fprintf (stderr,"Compression ratio: %0.2f%%\n",
			100.0*blog(grammar.M+grammar.numberOfRules)*grammar.grammarSize/(8.0*grammar.inputSize)); // In case we code the grammar with log |R|+|$\Sigma$| bits

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x5b83(%rip), %rax      # 0x6fc0
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2bc6(%rip), %rdx      # 0x4018
callq 0x1040
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x14de
movl -0x1c(%rbp), %eax
subl $0x66, %eax
jne 0x14d9
jmp 0x1469
movq 0x5b40(%rip), %rax      # 0x6fb0
movq (%rax), %rdi
leaq 0x2ba1(%rip), %rsi      # 0x401b
callq 0x1110
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x14d7
movq 0x5b5f(%rip), %rdi      # 0x6ff0
leaq 0x2b85(%rip), %rsi      # 0x401d
callq 0x10c0
movq %rax, %rdi
movq 0x5b09(%rip), %rax      # 0x6fb0
movq (%rax), %rsi
callq 0x10c0
movq %rax, %rdi
leaq 0x2b75(%rip), %rsi      # 0x402e
callq 0x10c0
movq %rax, %rdi
movq 0x5ae0(%rip), %rsi      # 0x6fa8
callq 0x10f0
movl $0x1, %edi
callq 0x1120
jmp 0x14d9
jmp 0x1444
leaq -0x48(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x774dfe0, %edx        # imm = 0x774DFE0
callq 0x1620
movq -0x18(%rbp), %rdi
callq 0x1150
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1508
jmp 0x152a
movq -0x18(%rbp), %rdi
callq 0x1160
movl %eax, -0x4c(%rbp)
cmpl $-0x1, -0x4c(%rbp)
jne 0x151c
jmp 0x152a
movl -0x4c(%rbp), %esi
leaq -0x48(%rbp), %rdi
callq 0x1720
jmp 0x14f1
movq 0x5a9f(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
leaq 0x2afa(%rip), %rsi      # 0x4035
movb $0x0, %al
callq 0x1130
movq 0x5a87(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
leaq 0x2af8(%rip), %rsi      # 0x404b
movb $0x0, %al
callq 0x1130
leaq -0x48(%rbp), %rdi
callq 0x1840
movq 0x5a66(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
movl -0x34(%rbp), %edx
leaq 0x2ade(%rip), %rsi      # 0x4055
movb $0x0, %al
callq 0x1130
movq 0x5a4b(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
movl -0x30(%rbp), %edx
leaq 0x2ad7(%rip), %rsi      # 0x4069
movb $0x0, %al
callq 0x1130
movq 0x5a30(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
movl -0x38(%rbp), %edx
leaq 0x2ad1(%rip), %rsi      # 0x407e
movb $0x0, %al
callq 0x1130
movq 0x5a15(%rip), %rax      # 0x6fd0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x28(%rbp), %edi
addl -0x30(%rbp), %edi
callq 0x13f0
movq -0x58(%rbp), %rdi
cvtsi2sd %eax, %xmm1
movsd 0x2a33(%rip), %xmm0     # 0x4010
mulsd %xmm1, %xmm0
cvtsi2sdl -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x34(%rbp), %xmm2
movsd 0x2a11(%rip), %xmm1     # 0x4008
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x2a8a(%rip), %rsi      # 0x4090
movb $0x1, %al
callq 0x1130
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)