// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
cmpl $0x3, %edi
jg 0x122b
movq 0x2dbe(%rip), %rdi      # 0x3fd8
leaq 0xde3(%rip), %rsi       # 0x2004
callq 0x1060
jmp 0x1400
movq %rsi, %rbx
movq 0x8(%rsi), %rax
movzbl (%rax), %eax
addl $-0x42, %eax
cmpl $0x11, %eax
ja 0x1412
movl $0x30801, %ecx          # imm = 0x30801
btl %eax, %ecx
jae 0x1412
movl %edi, %r15d
leaq 0x102c(%rip), %rdi      # 0x2285
leaq 0xdf1(%rip), %rsi       # 0x2051
callq 0x1080
movq %rax, %r14
leaq 0xde4(%rip), %rdi       # 0x2053
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x10b0
movq 0x18(%rbx), %rdx
leaq 0xdea(%rip), %rsi       # 0x2072
movq %r14, %rdi
xorl %eax, %eax
callq 0x1090
movq 0x8(%rbx), %rax
movzbl (%rax), %eax
cmpl $0x42, %eax
je 0x12bc
cmpl $0x4d, %eax
je 0x12b3
cmpl $0x53, %eax
jne 0x12b3
leaq 0xdd8(%rip), %rdi       # 0x2087
pushq $0x19
jmp 0x12c5
leaq 0xde7(%rip), %rdi       # 0x20a1
jmp 0x12c3
leaq 0xdfb(%rip), %rdi       # 0x20be
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x10b0
movq 0x8(%rbx), %rax
cmpb $0x52, (%rax)
jne 0x12e5
leaq 0xdfa(%rip), %rdi       # 0x20db
pushq $0x1c
jmp 0x1302
movq 0x20(%rbx), %rax
cmpb $0x74, (%rax)
jne 0x12f9
leaq 0xe03(%rip), %rdi       # 0x20f8
pushq $0x1f
jmp 0x1302
leaq 0xe18(%rip), %rdi       # 0x2118
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x10b0
leaq 0xe1f(%rip), %rdi       # 0x2134
pushq $0xc
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %r14, %rcx
callq 0x10b0
leaq 0xe13(%rip), %rdi       # 0x2141
pushq $0xf
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x10b0
movq 0x8(%rbx), %rax
cmpb $0x53, (%rax)
jne 0x135a
leaq 0xe05(%rip), %rdi       # 0x2151
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x10b0
leaq 0xe00(%rip), %rdi       # 0x2161
pushq $0x11
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x10b0
movq 0x8(%rbx), %rax
cmpb $0x52, (%rax)
jne 0x1385
movq 0x10(%rbx), %rdx
leaq 0xdf0(%rip), %rsi       # 0x2173
jmp 0x1396
movq 0x10(%rbx), %rdx
cmpl $0x5, %r15d
ja 0x13a2
leaq 0xe0f(%rip), %rsi       # 0x21a5
movq %r14, %rdi
xorl %eax, %eax
callq 0x1090
jmp 0x13b9
leaq 0xe27(%rip), %rsi       # 0x21d0
movq %r14, %rdi
movq %rdx, %rcx
movq %rdx, %r8
xorl %eax, %eax
callq 0x1090
movq %r14, %rdi
callq 0x1070
leaq 0xe95(%rip), %rdi       # 0x225d
callq 0x1040
movq 0x18(%rbx), %rcx
leaq 0xe94(%rip), %rsi       # 0x226c
leaq -0x120(%rbp), %rbx
movq %rbx, %rdi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x1030
movq %rbx, %rdi
callq 0x1040
leaq 0xe87(%rip), %rdi       # 0x2282
callq 0x1040
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x2bbf(%rip), %rdi      # 0x3fd8
leaq 0xc1a(%rip), %rsi       # 0x203a
jmp 0x1221