// File: ashlall[P]StreamStats/ChiSquareExperiments/MakePlot.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc < 4)
  {
    cout << "usage: MakePlot [S|M|B] input-file output-file [0|1]\n";
    return 0;
  }
  if (argv[1][0] != 'S' && argv[1][0] != 'M' && argv[1][0] != 'B' && argv[1][0] != 'R')
  {
    cout << "Must be S, M, R, or B\n";
    return 0;
  }
  FILE* file;
  char command[256];

  file = fopen("plot.p", "w");

  fprintf(file, "set term postscript eps color\n");
  fprintf(file, "set output \"%s.eps\"\n", argv[3]);

  if (argv[1][0] == 'S')
    fprintf(file, "set xlabel 'Stream Size'\n");
  else if (argv[1][0] == 'M')
    fprintf(file, "set xlabel 'Percent Memory'\n");
  else if (argv[1][0] == 'B')
    fprintf(file, "set xlabel 'Number of Bins'\n");
  else
	fprintf(file, "set xlabel 'Percent Memory'\n");
  
  if (argv[1][0] == 'R')
	fprintf(file, "set ylabel 'Relative Error'\n");
  else if (argv[4][0] == 't')
	fprintf(file, "set ylabel 'Time (in seconds)'\n");
  else
    fprintf(file, "set ylabel 'P-value Error'\n");

  fprintf(file, "set key box\n");
  fprintf(file, "set size .5,.5\n");

  if (argv[1][0] == 'S')
    fprintf(file, "set logscale x\n");
  fprintf(file, "set yrange [0:*]\n");

  if (argv[1][0] == 'R')
	fprintf(file, "plot \"%s\" u 1:2 t 'estimated' w linespoints lw 2\n", argv[2]);
  else if (argc <= 5)
    fprintf(file, "plot \"%s\" u 1:2 t 'GK' w linespoints lw 2\n", argv[2]);
  else
    fprintf(file, "plot \"%s\" u 1:2 t 'GK' w linespoints lw 2, \"%s\" u 1:3 t 'Q-Digest' w linespoints lw 2, \"%s\" u 1:4 t 'Reservoir-Sampling' w linespoints lw 2\n", argv[2], argv[2], argv[2]);

  fclose(file);
  
  system("gnuplot plot.p");
  sprintf(command, "convert %s.eps %s.pdf", argv[3], argv[3]);
  system(command);

  system("rm plot.p");
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x122e
movq 0x2dc2(%rip), %rdi      # 0x3fd8
leaq 0xde7(%rip), %rsi       # 0x2004
callq 0x1060
movl $0x0, -0x4(%rbp)
jmp 0x14d9
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x53, %eax
je 0x128d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x4d, %eax
je 0x128d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x42, %eax
je 0x128d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x52, %eax
je 0x128d
movq 0x2d63(%rip), %rdi      # 0x3fd8
leaq 0xdbe(%rip), %rsi       # 0x203a
callq 0x1060
movl $0x0, -0x4(%rbp)
jmp 0x14d9
leaq 0xff1(%rip), %rdi       # 0x2285
leaq 0xdb6(%rip), %rsi       # 0x2051
callq 0x1080
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq 0xda4(%rip), %rsi       # 0x2053
movb $0x0, %al
callq 0x1090
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0xda9(%rip), %rsi       # 0x2072
movb $0x0, %al
callq 0x1090
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x53, %eax
jne 0x12f4
movq -0x18(%rbp), %rdi
leaq 0xd9c(%rip), %rsi       # 0x2087
movb $0x0, %al
callq 0x1090
jmp 0x1352
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x4d, %eax
jne 0x1318
movq -0x18(%rbp), %rdi
leaq 0xd92(%rip), %rsi       # 0x20a1
movb $0x0, %al
callq 0x1090
jmp 0x1350
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x42, %eax
jne 0x133c
movq -0x18(%rbp), %rdi
leaq 0xd8b(%rip), %rsi       # 0x20be
movb $0x0, %al
callq 0x1090
jmp 0x134e
movq -0x18(%rbp), %rdi
leaq 0xd5a(%rip), %rsi       # 0x20a1
movb $0x0, %al
callq 0x1090
jmp 0x1350
jmp 0x1352
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x52, %eax
jne 0x1376
movq -0x18(%rbp), %rdi
leaq 0xd6e(%rip), %rsi       # 0x20db
movb $0x0, %al
callq 0x1090
jmp 0x13ae
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movsbl (%rax), %eax
cmpl $0x74, %eax
jne 0x139a
movq -0x18(%rbp), %rdi
leaq 0xd67(%rip), %rsi       # 0x20f8
movb $0x0, %al
callq 0x1090
jmp 0x13ac
movq -0x18(%rbp), %rdi
leaq 0xd73(%rip), %rsi       # 0x2118
movb $0x0, %al
callq 0x1090
jmp 0x13ae
movq -0x18(%rbp), %rdi
leaq 0xd7b(%rip), %rsi       # 0x2134
movb $0x0, %al
callq 0x1090
movq -0x18(%rbp), %rdi
leaq 0xd76(%rip), %rsi       # 0x2141
movb $0x0, %al
callq 0x1090
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x53, %eax
jne 0x13f4
movq -0x18(%rbp), %rdi
leaq 0xd64(%rip), %rsi       # 0x2151
movb $0x0, %al
callq 0x1090
movq -0x18(%rbp), %rdi
leaq 0xd62(%rip), %rsi       # 0x2161
movb $0x0, %al
callq 0x1090
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x52, %eax
jne 0x1432
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0xd4a(%rip), %rsi       # 0x2173
movb $0x0, %al
callq 0x1090
jmp 0x1480
cmpl $0x5, -0x8(%rbp)
jg 0x1454
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0xd5a(%rip), %rsi       # 0x21a5
movb $0x0, %al
callq 0x1090
jmp 0x147e
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r8
leaq 0xd59(%rip), %rsi       # 0x21d0
movb $0x0, %al
callq 0x1090
jmp 0x1480
movq -0x18(%rbp), %rdi
callq 0x1070
leaq 0xdcd(%rip), %rdi       # 0x225d
callq 0x1040
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0xdb9(%rip), %rsi       # 0x226c
movb $0x0, %al
callq 0x1030
leaq -0x120(%rbp), %rdi
callq 0x1040
leaq 0xdb5(%rip), %rdi       # 0x2282
callq 0x1040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq