// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
cmpl $0x3, %edi
jg 0x122e
movq 0x2dc0(%rip), %rdi      # 0x3fd8
leaq 0xde5(%rip), %rsi       # 0x2004
movl $0x35, %edx
callq 0x1070
jmp 0x1424
movq %rsi, %rbx
movq 0x8(%rsi), %rax
movzbl (%rax), %eax
addl $-0x42, %eax
cmpl $0x11, %eax
ja 0x1434
movl $0x30801, %ecx          # imm = 0x30801
btl %eax, %ecx
jae 0x1434
movl %edi, %r15d
leaq 0x1029(%rip), %rdi      # 0x2285
leaq 0xdee(%rip), %rsi       # 0x2051
callq 0x1080
movq %rax, %r14
leaq 0xde1(%rip), %rdi       # 0x2053
movl $0x1e, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x10b0
movq 0x18(%rbx), %rdx
leaq 0xde3(%rip), %rsi       # 0x2072
movq %r14, %rdi
xorl %eax, %eax
callq 0x1090
movq 0x8(%rbx), %rax
movzbl (%rax), %eax
cmpl $0x42, %eax
je 0x12c6
cmpl $0x4d, %eax
je 0x12bd
cmpl $0x53, %eax
jne 0x12bd
leaq 0xdd1(%rip), %rdi       # 0x2087
movl $0x19, %esi
jmp 0x12d2
leaq 0xddd(%rip), %rdi       # 0x20a1
jmp 0x12cd
leaq 0xdf1(%rip), %rdi       # 0x20be
movl $0x1c, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x10b0
movq 0x8(%rbx), %rax
cmpb $0x52, (%rax)
jne 0x12f6
leaq 0xdec(%rip), %rdi       # 0x20db
movl $0x1c, %esi
jmp 0x1319
movq 0x20(%rbx), %rax
cmpb $0x74, (%rax)
jne 0x130d
leaq 0xdf2(%rip), %rdi       # 0x20f8
movl $0x1f, %esi
jmp 0x1319
leaq 0xe04(%rip), %rdi       # 0x2118
movl $0x1b, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x10b0
leaq 0xe07(%rip), %rdi       # 0x2134
movl $0xc, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x10b0
leaq 0xdfb(%rip), %rdi       # 0x2141
movl $0xf, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x10b0
movq 0x8(%rbx), %rax
cmpb $0x53, (%rax)
jne 0x137a
leaq 0xde9(%rip), %rdi       # 0x2151
movl $0xf, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x10b0
leaq 0xde0(%rip), %rdi       # 0x2161
movl $0x11, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x10b0
movq 0x8(%rbx), %rax
cmpb $0x52, (%rax)
jne 0x13a9
movq 0x10(%rbx), %rdx
leaq 0xdcc(%rip), %rsi       # 0x2173
jmp 0x13ba
movq 0x10(%rbx), %rdx
cmpl $0x5, %r15d
jg 0x13c6
leaq 0xdeb(%rip), %rsi       # 0x21a5
movq %r14, %rdi
xorl %eax, %eax
callq 0x1090
jmp 0x13dd
leaq 0xe03(%rip), %rsi       # 0x21d0
movq %r14, %rdi
movq %rdx, %rcx
movq %rdx, %r8
xorl %eax, %eax
callq 0x1090
movq %r14, %rdi
callq 0x1060
leaq 0xe71(%rip), %rdi       # 0x225d
callq 0x1040
movq 0x18(%rbx), %rcx
leaq 0xe70(%rip), %rsi       # 0x226c
leaq -0x120(%rbp), %rbx
movq %rbx, %rdi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x1030
movq %rbx, %rdi
callq 0x1040
leaq 0xe63(%rip), %rdi       # 0x2282
callq 0x1040
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x2b9d(%rip), %rdi      # 0x3fd8
leaq 0xbf8(%rip), %rsi       # 0x203a
movl $0x16, %edx
jmp 0x1224