// File: /workspace/github_cpp_makefile_star2_O1/ashlall[P]StreamStats/ChiSquareExperiments/VarySizeOneSample.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc < 10)
  {
    cout << "usage: VarySize lower-size upper-size num-streams(>0) [N|U|P|E] location scale [0|1] memory-percent num-buckets" << endl;
    throw ParameterError();
  }
  
  double lower = atof (argv[1]);
  double upper = atof (argv[2]);
  int data_repeats = atoi (argv[3]);
  char distribution_type = argv[4][0];
  double location = atof (argv[5]);
  double scale = atof (argv[6]);
  int all_quantiles = atoi (argv[7]);
  double memory_percent = atof (argv[8]);
  int num_buckets = atoi(argv[9]);
  int seed = 1; 

  // ensures that the parameters will not create error
  if (data_repeats <= 0)
  {
    cout << "The number of streams must be greater than zero." << endl;
    throw ParameterError();
  }
  if (distribution_type != 'N' && distribution_type != 'U' && distribution_type != 'P' && distribution_type != 'E')
  {
    cout << "The distribution is either N, U, P, or E." << endl;
    throw ParameterError();
  }
  if (lower <= 0)
  {
    cout << "The lower stream size must be greater than 0." << endl;
    throw ParameterError();
  }
  if (memory_percent <= 0)
  {
    cout << "The memory percent must be greater than 0.\n";
    throw ParameterError();
  }
  if (num_buckets <= 0)
  {
    cout << "The number of bins must be greater than 0.\n";
    throw ParameterError();
  }

  // finds the number of different sizes the experiment will run on
  int stream_size;
  int num_sizes = 0, size = lower;
  while (size <= upper)
  {
    num_sizes++;
    size *= 10;
  }

  // creates the arrays that will hold the calculated statistics
  double actual_values[data_repeats][num_sizes];
  double GK_values[data_repeats][num_sizes];
  double QD_values[data_repeats][num_sizes];
  double RS_values[data_repeats][num_sizes];
  int sizes[num_sizes];
  long times[data_repeats][num_sizes];
  long times2[data_repeats][num_sizes];

  // creates and initializes the log file
  ofstream data_file;
  char str[150];
  name_file(str, argv, 0);
  data_file.open(str);
  data_file << "Distribution: " << distribution_type << ", location = " << location << ", scale = " << scale << endl;

  for (int i = 0; i < data_repeats; i++) // runs all tests data_repeats times
  {
    stream_size = lower;
    int j = 0;
    data_file << "Stream " << i+1 << ":" << endl;
    while (stream_size <= upper)  // runs tests for every stream size
    {
      int sample_size = memory_percent * stream_size;
      if (i == 0)
        sizes[j] = stream_size;
      data_file << "stream_size = " << stream_size << endl;
      
      // generates the data based on inputed parameters
      DataGenerator data(distribution_type, stream_size, seed, location, scale);
      double *stream = data.get_stream();

      // computes GK estimate
      ChiSquareContinuous sketch1(sample_size, 1); 

	  timeval timeBefore, timeAfter; // initializes variables
  	  long diffSeconds, diffUSeconds;
 	  gettimeofday(&timeBefore, NULL); 

      for (int i = 0; i < stream_size; i++)
	      sketch1.insert(stream[i]);

	  gettimeofday(&timeAfter, NULL); // get time for insertion
  	  diffSeconds = timeAfter.tv_sec - timeBefore.tv_sec;
  	  diffUSeconds = timeAfter.tv_usec - timeBefore.tv_usec;

	  times[i][j] = diffSeconds;
	  times2[i][j] = diffUSeconds;


      double GK_stat = get_estimate(&sketch1, distribution_type, num_buckets, location, scale);
      GK_values[i][j] = GK_stat;
      data_file << "GK = " << GK_stat << endl;

      if (all_quantiles)
      {
      	// computes QDigest estimate
	ChiSquareContinuous sketch2(sample_size, 2);
	for (int i = 0; i < stream_size; i++)
          sketch2.insert(stream[i]);
	double QD_stat = get_estimate(&sketch2, distribution_type, num_buckets, location, scale);
	QD_values[i][j] = QD_stat;
        data_file << "QDigest = " << QD_stat << endl;

	// computes ReservoirSampling estimate
	ChiSquareContinuous sketch3(sample_size, 3);
	for (int i = 0; i < stream_size; i++)
	  sketch3.insert(stream[i]);
	double RS_stat = get_estimate(&sketch3, distribution_type, num_buckets, location, scale);
	RS_values[i][j] = RS_stat;
        data_file << "Reservoir Sampling = " << RS_stat << endl;
      }

      // computes actual statistic
      double *upper_interval = sketch1.get_upper();
      double *lower_interval = sketch1.get_lower();
      double actual = data.get_stat_one_sample(num_buckets, upper_interval, lower_interval);
      actual_values[i][j] = actual;
      data_file << "Real = " << actual << endl;

      stream_size *= 10;
      j++;
    }
    seed++; // changes seed for next repeat?
  }
  data_file.close();

  // creates table file
  name_file(str, argv, 1);
  data_file.open(str);

  // creates time table file
  ofstream time_file;
  char str2[150];
  name_file(str2, argv, 5);
  time_file.open(str2);

  // creates pvalues file
  ofstream data2_file;
  char st[150];
  name_file(st, argv, 3);
  data2_file.open(st);

  int deg_freedom = num_buckets - get_DOF(distribution_type);
  for (int i = 0; i < num_sizes; i++)
  {
    data_file << sizes[i] << "\t";
	time_file << sizes[i] << "\t";

    // adds pvalue error from the GK sketch to the table file
    double error = 0;
    for (int j = 0; j < data_repeats; j++)
      error += abs(pochisq(GK_values[j][i], deg_freedom) - pochisq(actual_values[j][i], deg_freedom));
    data_file << error / data_repeats;

	// adds times to the time table
	long double avg_time = 0.0;
	for (int j = 0; j < data_repeats; j++)
		avg_time += times[j][i] + times2[j][i]/1000000.0;// diffSeconds + diffUSeconds/1000000.0
	time_file << avg_time / data_repeats << endl;

    if (all_quantiles)
    {
      // adds pvalue error from the QDigest sketch to the table file
      error = 0;
      for (int j = 0; j < data_repeats; j++)
	error += abs(pochisq(QD_values[j][i], deg_freedom) - pochisq(actual_values[j][i], deg_freedom));
      data_file << "\t" << error / data_repeats << "\t";

      // adds pvalue error from the Reservoir Sampling sketch to the table file
      error = 0;
      for (int j = 0; j < data_repeats; j++)
	error += abs(pochisq(RS_values[j][i], deg_freedom) - pochisq(actual_values[j][i], deg_freedom));
      data_file << error / data_repeats;
    }
    data_file << endl;

    // adds all pvalues to the pvalue file
    data2_file << "streamsize = " << sizes[i] << endl;
    for (int j = 0; j < data_repeats; j++)
    {
      data2_file << pochisq(actual_values[j][i], deg_freedom) << " actual" << endl;
      data2_file << pochisq(GK_values[j][i], deg_freedom) << " GK" << endl;
      if (all_quantiles)
      {
	data2_file << pochisq(QD_values[j][i], deg_freedom) << " QD" << endl;
	data2_file << pochisq(RS_values[j][i], deg_freedom) << " RS" << endl;
      }
    }
  }
  data2_file.close();
  data_file.close();
  time_file.close();

  // Creates extra file
  name_file(str, argv, 2);
  data_file.open(str);

  // adds actual statistics to the extra file
  for (int i = 0; i < num_sizes; i++)
  {
    for (int j = 0; j < data_repeats; j++)
	    data_file << actual_values[j][i] << "\t";
  }
  data_file << endl;

  // adds GK statistics to the extra file
  for (int i = 0; i < num_sizes; i++)
  {
    for(int j = 0; j <data_repeats; j++)
      data_file << GK_values[j][i] << "\t";
  }
  data_file << endl;
  if (all_quantiles)
  {
    // adds QDigest statistics to the extra file
    for (int i = 0; i < num_sizes; i++)
    {
	    for(int j = 0; j <data_repeats; j++)
	      data_file << QD_values[j][i] << "\t";
    }
    data_file << endl;

    // adds Reservoir Sampling statistcs to the extra file
    for (int i = 0; i < num_sizes; i++)
    {
	    for(int j = 0; j <data_repeats; j++)
	     data_file << RS_values[j][i] << "\t";
    }
    data_file << endl;
  }
  data_file.close();
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x928, %rsp            # imm = 0x928
cmpl $0x9, %edi
jle 0x650e
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x2250
movapd %xmm0, -0x90(%rbp)
movq 0x10(%r14), %rdi
callq 0x2250
movsd %xmm0, -0x78(%rbp)
movq 0x18(%r14), %rdi
callq 0x22b0
movl %eax, %ebx
movq 0x20(%r14), %rax
movq 0x28(%r14), %rdi
movb (%rax), %r15b
callq 0x2250
movsd %xmm0, -0x38(%rbp)
movq 0x30(%r14), %rdi
callq 0x2250
movsd %xmm0, -0xb0(%rbp)
movq 0x38(%r14), %rdi
callq 0x22b0
movl %eax, -0x6c(%rbp)
movq 0x40(%r14), %rdi
callq 0x2250
movsd %xmm0, -0x128(%rbp)
movq 0x48(%r14), %rdi
callq 0x22b0
movq %rax, -0x40(%rbp)
movl %ebx, -0x4c(%rbp)
testl %ebx, %ebx
jle 0x651e
movzbl %r15b, %eax
addl $-0x45, %eax
cmpl $0x10, %eax
ja 0x6563
movl $0x10a01, %ecx          # imm = 0x10A01
btl %eax, %ecx
jae 0x6563
xorpd %xmm0, %xmm0
movapd -0x90(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jae 0x652e
ucomisd -0x128(%rbp), %xmm0
jae 0x653e
cmpl $0x0, -0x40(%rbp)
jle 0x654e
movb %r15b, -0x29(%rbp)
movq %r14, -0xe8(%rbp)
cvttsd2si %xmm1, %eax
movl %eax, -0x7c(%rbp)
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
xorl %eax, %eax
movsd -0x78(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x5397
xorl %eax, %eax
movl -0x7c(%rbp), %ecx
incl %eax
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
ucomisd %xmm0, %xmm1
jae 0x5383
movl -0x4c(%rbp), %ecx
movl %eax, %edx
imulq %rdx, %rcx
leaq 0xf(,%rcx,8), %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xd0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %rsi
movq %rdx, -0x48(%rbp)
leaq 0xf(,%rdx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rsi
movq %rsi, -0x120(%rbp)
movq %rsi, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xd8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xf0(%rbp)
movq %rcx, %rsp
leaq -0x370(%rbp), %rbx
movq %rbx, %rdi
callq 0x2320
leaq -0x950(%rbp), %r14
movq %r14, %rdi
movq -0xe8(%rbp), %rsi
xorl %edx, %edx
callq 0x66c7
movq %rbx, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2060
leaq 0x3fef(%rip), %rsi      # 0x9452
leaq -0x370(%rbp), %rdi
movl $0xe, %edx
callq 0x2230
leaq -0x810(%rbp), %rsi
movb -0x29(%rbp), %al
movb %al, (%rsi)
leaq -0x370(%rbp), %rdi
movl $0x1, %edx
callq 0x2230
movq %rax, %rbx
leaq 0x3fc6(%rip), %rsi      # 0x9461
movl $0xd, %edx
movq %rax, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
leaq 0x3fb0(%rip), %rsi      # 0x946f
movl $0xa, %edx
movq %rax, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0xb0(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
xorps %xmm0, %xmm0
cvtsi2sdl -0x7c(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movl -0x4c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %r13d
cmovgel %eax, %r13d
movl $0x1, -0x98(%rbp)
movq $0x0, -0x58(%rbp)
movq %r15, -0xb8(%rbp)
movq %r13, -0xe0(%rbp)
movl $0x7, %edx
leaq -0x370(%rbp), %rdi
leaq 0x3f21(%rip), %rsi      # 0x947a
callq 0x2230
movq -0x58(%rbp), %rax
leaq 0x1(%rax), %rsi
leaq -0x370(%rbp), %rdi
movq %rsi, -0x130(%rbp)
callq 0x2340
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3ef7(%rip), %rsi      # 0x9482
callq 0x2230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movsd -0x78(%rbp), %xmm0
ucomisd -0x118(%rbp), %xmm0
jb 0x5a81
movq -0x58(%rbp), %rax
imulq -0x48(%rbp), %rax
movq -0xd8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x100(%rbp)
movq -0xf0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0xf8(%rbp)
movq -0xc8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x110(%rbp)
movq -0xc0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x140(%rbp)
movq -0xb8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x138(%rbp)
movq -0xd0(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x148(%rbp)
xorl %r13d, %r13d
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %r15d
cmpq $0x0, -0x58(%rbp)
jne 0x5667
movq -0x120(%rbp), %rax
movl %r15d, (%rax,%r13,4)
movl $0xe, %edx
leaq -0x370(%rbp), %rdi
leaq 0x3e0a(%rip), %rsi      # 0x9484
callq 0x2230
leaq -0x370(%rbp), %rdi
movl %r15d, %esi
callq 0x2340
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movsbl -0x29(%rbp), %esi
leaq -0x8b0(%rbp), %rdi
movl %esi, -0x90(%rbp)
movl %r15d, %edx
movl -0x98(%rbp), %ecx
movsd -0x38(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
callq 0x251c
movsd -0x68(%rbp), %xmm0
mulsd -0x128(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movq -0x8b0(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq -0x810(%rbp), %rdi
movsd %xmm0, -0x68(%rbp)
movl $0x1, %esi
callq 0x46b4
leaq -0x170(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movl %r15d, %r14d
testl %r15d, %r15d
jle 0x574c
xorl %r12d, %r12d
movsd (%rbx,%r12,8), %xmm0
movq -0x7f0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %r12
cmpq %r12, %r14
jne 0x5732
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movq -0x160(%rbp), %rax
movq -0x158(%rbp), %rcx
subq -0x170(%rbp), %rax
subq -0x168(%rbp), %rcx
movq -0x100(%rbp), %rdx
movq %rax, (%rdx,%r13,8)
movq -0xf8(%rbp), %rax
movq %rcx, (%rax,%r13,8)
leaq -0x810(%rbp), %rdi
movl -0x90(%rbp), %esi
movq -0x40(%rbp), %rdx
movsd -0x38(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
callq 0x68f4
movq -0x110(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x5, %edx
leaq -0x370(%rbp), %rdi
leaq 0x3cc4(%rip), %rsi      # 0x9493
movsd %xmm0, -0x60(%rbp)
callq 0x2230
movsd -0x60(%rbp), %xmm0
leaq -0x370(%rbp), %rdi
callq 0x22c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x6c(%rbp)
je 0x59bc
leaq -0x610(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movl $0x2, %esi
callq 0x46b4
testl %r15d, %r15d
jle 0x5856
xorl %r12d, %r12d
movsd (%rbx,%r12,8), %xmm0
movq -0x5f0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %r12
cmpq %r12, %r14
jne 0x583c
leaq -0x610(%rbp), %rdi
movl -0x90(%rbp), %esi
movq -0x40(%rbp), %rdx
movsd -0x38(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
callq 0x68f4
movq -0x140(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0xa, %edx
leaq -0x370(%rbp), %rdi
leaq 0x3c00(%rip), %rsi      # 0x9499
movsd %xmm0, -0x60(%rbp)
callq 0x2230
movsd -0x60(%rbp), %xmm0
leaq -0x370(%rbp), %rdi
callq 0x22c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x410(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movl $0x3, %esi
callq 0x46b4
testl %r15d, %r15d
jle 0x5916
xorl %r12d, %r12d
movsd (%rbx,%r12,8), %xmm0
movq -0x3f0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %r12
cmpq %r12, %r14
jne 0x58fc
leaq -0x410(%rbp), %rdi
movl -0x90(%rbp), %esi
movq -0x40(%rbp), %rdx
movsd -0x38(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
callq 0x68f4
movq -0x138(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x15, %edx
leaq -0x370(%rbp), %rdi
leaq 0x3b4b(%rip), %rsi      # 0x94a4
movsd %xmm0, -0x90(%rbp)
callq 0x2230
movsd -0x90(%rbp), %xmm0
leaq -0x370(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x410(%rbp), %rdi
callq 0x4854
leaq -0x610(%rbp), %rdi
callq 0x4854
movq -0x800(%rbp), %rdx
movq -0x7f8(%rbp), %rcx
leaq -0x8b0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2762
movq -0x148(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x7, %edx
leaq -0x370(%rbp), %rdi
leaq 0x3ac0(%rip), %rsi      # 0x94ba
movsd %xmm0, -0x90(%rbp)
callq 0x2230
movsd -0x90(%rbp), %xmm0
leaq -0x370(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x810(%rbp), %rdi
callq 0x4854
testq %rbx, %rbx
je 0x5a5e
movq %rbx, %rdi
callq 0x2260
addl %r15d, %r15d
leal (%r15,%r15,4), %r15d
incq %r13
cvtsi2sd %r15d, %xmm1
movsd -0x78(%rbp), %xmm0
movsd %xmm1, -0x68(%rbp)
ucomisd %xmm1, %xmm0
jae 0x5655
incl -0x98(%rbp)
movq -0x130(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq -0xe0(%rbp), %r13
cmpq %r13, %rcx
jne 0x5546
leaq -0x370(%rbp), %rdi
callq 0x2280
leaq -0x950(%rbp), %rbx
movq %rbx, %rdi
movq -0xe8(%rbp), %rsi
movl $0x1, %edx
callq 0x66c7
leaq -0x370(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
leaq -0x810(%rbp), %rdi
callq 0x2320
leaq -0x410(%rbp), %rbx
movq %rbx, %rdi
movq -0xe8(%rbp), %r14
movq %r14, %rsi
movl $0x5, %edx
callq 0x66c7
leaq -0x810(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
movq -0xd8(%rbp), %r15
leaq -0x610(%rbp), %rdi
callq 0x2320
leaq -0x8b0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0x66c7
leaq -0x610(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
xorl %eax, %eax
cmpb $0x45, -0x29(%rbp)
sete %cl
cmpq $0x0, -0x48(%rbp)
je 0x6114
movb %cl, %al
movl -0x4c(%rbp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x40(%rbp), %rdx
leal -0x3(%rax,%rdx), %r12d
movl %ecx, -0x104(%rbp)
fildl -0x104(%rbp)
fstpt -0x110(%rbp)
movq -0x48(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %ecx, %ecx
movq -0xb8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0xd0(%rbp), %rax
movq %rbx, -0x58(%rbp)
movl %r12d, -0x78(%rbp)
movq %rdx, -0x90(%rbp)
movq %rax, -0x60(%rbp)
movq %r15, -0xd8(%rbp)
movq -0x120(%rbp), %rax
movq %rcx, -0xf8(%rbp)
movl (%rax,%rcx,4), %ebx
leaq -0x370(%rbp), %rdi
movl %ebx, %esi
callq 0x2340
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38ac(%rip), %rsi      # 0x94c2
callq 0x2230
leaq -0x810(%rbp), %rdi
movl %ebx, %esi
callq 0x2340
movl $0x1, %edx
movq %rax, %rdi
leaq 0x388a(%rip), %rsi      # 0x94c2
callq 0x2230
movl %ebx, -0x100(%rbp)
xorpd %xmm1, %xmm1
movq %r13, %r14
xorl %r15d, %r15d
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r12
movl -0x78(%rbp), %r13d
movsd %xmm1, -0x38(%rbp)
movq -0x40(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movaps %xmm0, -0xb0(%rbp)
movsd (%rbx,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movsd -0x38(%rbp), %xmm1
movapd -0xb0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x3502(%rip), %xmm2     # 0x91a0
addsd %xmm2, %xmm1
addq %r12, %r15
decq %r14
jne 0x5c59
divsd -0x98(%rbp), %xmm1
leaq -0x370(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0xd8(%rbp), %rdx
movq -0xe0(%rbp), %r13
movq %r13, %rax
xorl %ecx, %ecx
fldz
movq -0xf0(%rbp), %rsi
movsd 0x348a(%rip), %xmm2     # 0x9170
movq -0x58(%rbp), %rdi
xorps %xmm0, %xmm0
cvtsi2sdq (%rdx,%rcx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%rsi,%rcx), %xmm1
divsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x150(%rbp)
faddl -0x150(%rbp)
addq %rdi, %rcx
decq %rax
jne 0x5cea
fldt -0x110(%rbp)
fdivrp %st, %st(1)
subq $0x10, %rsp
fstpt (%rsp)
leaq -0x810(%rbp), %rdi
callq 0x2120
addq $0x10, %rsp
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x6c(%rbp)
je 0x5eab
xorpd %xmm1, %xmm1
movq %r13, %r14
xorl %r15d, %r15d
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r12
movl -0x78(%rbp), %r13d
movsd %xmm1, -0x38(%rbp)
movq -0x90(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movaps %xmm0, -0xb0(%rbp)
movsd (%rbx,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movsd -0x38(%rbp), %xmm1
movapd -0xb0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x33d5(%rip), %xmm2     # 0x91a0
addsd %xmm2, %xmm1
addq %r12, %r15
decq %r14
jne 0x5d83
movsd %xmm1, -0x38(%rbp)
movl $0x1, %edx
leaq -0x370(%rbp), %rdi
leaq 0x36d3(%rip), %rsi      # 0x94c2
callq 0x2230
movq -0xe0(%rbp), %r14
movsd -0x38(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
leaq -0x370(%rbp), %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x369f(%rip), %rsi      # 0x94c2
callq 0x2230
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r12
movl -0x78(%rbp), %r13d
movsd %xmm1, -0x38(%rbp)
movq -0x68(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movaps %xmm0, -0xb0(%rbp)
movsd (%rbx,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movsd -0x38(%rbp), %xmm1
movapd -0xb0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x3320(%rip), %xmm2     # 0x91a0
addsd %xmm2, %xmm1
addq %r12, %r15
decq %r14
jne 0x5e3b
divsd -0x98(%rbp), %xmm1
leaq -0x370(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0xe0(%rbp), %r13
movq -0x370(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x370(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x370(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0xd, %edx
leaq -0x610(%rbp), %rdi
leaq 0x35d0(%rip), %rsi      # 0x94c4
callq 0x2230
leaq -0x610(%rbp), %rdi
movl -0x100(%rbp), %esi
callq 0x2340
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
xorl %r15d, %r15d
movq -0x58(%rbp), %rbx
movl -0x78(%rbp), %r12d
movq -0x60(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x610(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x3562(%rip), %rsi      # 0x94d2
callq 0x2230
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq -0x40(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x610(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x350e(%rip), %rsi      # 0x94da
callq 0x2230
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x6c(%rbp)
je 0x60bd
movq -0x90(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x610(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x34a9(%rip), %rsi      # 0x94de
callq 0x2230
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq -0x68(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x610(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3451(%rip), %rsi      # 0x94e2
callq 0x2230
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
addq %rbx, %r15
decq %r13
jne 0x5f40
movq -0xf8(%rbp), %rcx
incq %rcx
movq -0x60(%rbp), %rax
addq $0x8, %rax
addq $0x8, -0x40(%rbp)
addq $0x8, -0xf0(%rbp)
movq -0xd8(%rbp), %r15
addq $0x8, %r15
movq -0x90(%rbp), %rdx
addq $0x8, %rdx
addq $0x8, -0x68(%rbp)
cmpq -0x48(%rbp), %rcx
movq -0xe0(%rbp), %r13
jne 0x5bd6
leaq -0x610(%rbp), %rdi
callq 0x2280
leaq -0x370(%rbp), %rdi
callq 0x2280
leaq -0x810(%rbp), %rdi
callq 0x2280
leaq -0x950(%rbp), %r12
movq %r12, %rdi
movq -0xe8(%rbp), %rsi
movl $0x2, %edx
callq 0x66c7
leaq -0x370(%rbp), %rdi
movq %r12, %rsi
movl $0x10, %edx
callq 0x2060
cmpq $0x0, -0x48(%rbp)
movq -0xd0(%rbp), %r15
je 0x61ef
movl -0x4c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x48(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x370(%rbp), %r12
leaq 0x331f(%rip), %r13      # 0x94c2
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r15, -0xd0(%rbp)
movsd (%r15), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %r14, %r15
decq %rbx
jne 0x61b2
movq -0x40(%rbp), %rax
incq %rax
movq -0xd0(%rbp), %r15
addq $0x8, %r15
cmpq -0x48(%rbp), %rax
jne 0x61a3
movq -0x370(%rbp), %rax
leaq -0x370(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x370(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpq $0x0, -0x48(%rbp)
movq -0xc8(%rbp), %r15
je 0x62aa
movl -0x4c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x48(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x370(%rbp), %r12
leaq 0x3264(%rip), %r13      # 0x94c2
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r15, -0xc8(%rbp)
movsd (%r15), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %r14, %r15
decq %rbx
jne 0x626d
movq -0x40(%rbp), %rax
incq %rax
movq -0xc8(%rbp), %r15
addq $0x8, %r15
cmpq -0x48(%rbp), %rax
jne 0x625e
movq -0x370(%rbp), %rax
leaq -0x370(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x370(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x6c(%rbp)
je 0x645d
cmpq $0x0, -0x48(%rbp)
movq -0xc0(%rbp), %r15
je 0x636f
movl -0x4c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x48(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x370(%rbp), %r12
leaq 0x319f(%rip), %r13      # 0x94c2
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r15, -0xc0(%rbp)
movsd (%r15), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %r14, %r15
decq %rbx
jne 0x6332
movq -0x40(%rbp), %rax
incq %rax
movq -0xc0(%rbp), %r15
addq $0x8, %r15
cmpq -0x48(%rbp), %rax
jne 0x6323
movq -0x370(%rbp), %rax
leaq -0x370(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x370(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpq $0x0, -0x48(%rbp)
movq -0xb8(%rbp), %r15
je 0x642a
movl -0x4c(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x48(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x370(%rbp), %r12
leaq 0x30e4(%rip), %r13      # 0x94c2
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r15, -0xb8(%rbp)
movsd (%r15), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %r14, %r15
decq %rbx
jne 0x63ed
movq -0x40(%rbp), %rax
incq %rax
movq -0xb8(%rbp), %r15
addq $0x8, %r15
cmpq -0x48(%rbp), %rax
jne 0x63de
movq -0x370(%rbp), %rax
leaq -0x370(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x370(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x370(%rbp), %r15
movq %r15, %rdi
callq 0x2280
movq 0x6b55(%rip), %rax      # 0xcfc8
movq (%rax), %rbx
movq 0x18(%rax), %r14
leaq -0x608(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x610(%rbp,%rax)
callq 0x21c0
movl $0xf8, %r12d
leaq -0x610(%rbp), %rdi
addq %r12, %rdi
callq 0x20b0
leaq -0x808(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x810(%rbp,%rax)
callq 0x21c0
leaq -0x810(%rbp), %rdi
addq %r12, %rdi
callq 0x20b0
leaq -0x368(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x370(%rbp,%rax)
callq 0x21c0
addq %r12, %r15
movq %r15, %rdi
callq 0x20b0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6abb(%rip), %rdi      # 0xcfd0
leaq 0x2de5(%rip), %rsi      # 0x9301
jmp 0x6571
movq 0x6aab(%rip), %rdi      # 0xcfd0
leaq 0x2e45(%rip), %rsi      # 0x9371
jmp 0x6571
movq 0x6a9b(%rip), %rdi      # 0xcfd0
leaq 0x2e90(%rip), %rsi      # 0x93cc
jmp 0x6571
movq 0x6a8b(%rip), %rdi      # 0xcfd0
leaq 0x2eae(%rip), %rsi      # 0x93fa
jmp 0x655c
movq 0x6a7b(%rip), %rdi      # 0xcfd0
leaq 0x2eca(%rip), %rsi      # 0x9426
callq 0x2210
jmp 0x657e
movq 0x6a66(%rip), %rdi      # 0xcfd0
leaq 0x2e31(%rip), %rsi      # 0x93a2
callq 0x2210
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2100
leaq 0x66e9(%rip), %rsi      # 0xcc78
movq %rax, %rdi
xorl %edx, %edx
callq 0x2330
jmp 0x661a
jmp 0x659d
movq %rax, %rbx
jmp 0x6653
jmp 0x65ca
jmp 0x65ca
jmp 0x661a
jmp 0x661a
jmp 0x661a
jmp 0x65ca
jmp 0x661a
jmp 0x65f8
jmp 0x65e7
jmp 0x65ca
movq %rax, %rbx
jmp 0x6607
jmp 0x661a
jmp 0x661a
jmp 0x661a
jmp 0x661a
jmp 0x65d6
jmp 0x65e7
movq %rax, %rbx
jmp 0x6689
jmp 0x65f8
jmp 0x65f8
movq %rax, %rbx
leaq -0x410(%rbp), %rdi
callq 0x4854
jmp 0x65ea
movq %rax, %rbx
leaq -0x610(%rbp), %rdi
callq 0x4854
jmp 0x65fb
movq %rax, %rbx
leaq -0x810(%rbp), %rdi
callq 0x4854
movq -0x8b0(%rbp), %rdi
testq %rdi, %rdi
je 0x6689
callq 0x2260
jmp 0x6689
movq %rax, %rbx
movq 0x69a4(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x608(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x610(%rbp,%rcx)
callq 0x21c0
leaq -0x518(%rbp), %rdi
callq 0x20b0
movq 0x696e(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x808(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x810(%rbp,%rcx)
callq 0x21c0
leaq -0x718(%rbp), %rdi
callq 0x20b0
movq 0x6938(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x368(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x370(%rbp,%rcx)
callq 0x21c0
leaq -0x278(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2360