// File: /workspace/github_cpp_makefile_star2_O1/ashlall[P]StreamStats/ChiSquareExperiments/VaryMemoryOneSample.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc < 10)
  {
    cout << "usage: VaryMemory lower-memory upper-memory num-streams(>0) [N|U|P|E] location scale [0|1] stream-size 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]);
  int stream_size = atoi (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 memory percent must be greater than 0." << endl;
    throw ParameterError();
  }
  if (stream_size <= 0)
  {
    cout << "The stream_size 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
  double memory_percent;
  int num_mems = 0;
  double mem = lower;
  while (mem <= (upper + 0.0000001))
  {
    //cout << mem << endl;
    num_mems++;
    mem *= sqrt(10);
    //cout << mem << " " << upper << endl;
  }

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

  // 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
  {
    memory_percent = lower;
    int j = 0;
    data_file << "Stream " << i+1 << ":" << endl;

    // generates the data based on inputed parameters                                       
    DataGenerator data(distribution_type, stream_size, seed, location, scale);
    double *stream = data.get_stream();

    while (memory_percent <= (upper+0.0000001))  // runs tests for every memory percent
    {
      int sample_size = memory_percent * stream_size;
      if (i == 0)
        percents[j] = memory_percent;
      data_file << "memory_percent = " << memory_percent << endl;
      
      // 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;

      memory_percent *= sqrt(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_mems; i++)
  {
    data_file << percents[i] * 100 << "\t";
	time_file << percents[i] * 100 << "\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 << "memory_percent = " << percents[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_mems; 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_mems; 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_mems; 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_mems; 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 $0x918, %rsp            # imm = 0x918
cmpl $0x9, %edi
jle 0x64df
movq %rsi, %r15
movq 0x8(%rsi), %rdi
callq 0x2250
movsd %xmm0, -0xb8(%rbp)
movq 0x10(%r15), %rdi
callq 0x2250
movsd %xmm0, -0x78(%rbp)
movq 0x18(%r15), %rdi
callq 0x22b0
movl %eax, %ebx
movq 0x20(%r15), %rax
movq 0x28(%r15), %rdi
movb (%rax), %r12b
callq 0x2250
movsd %xmm0, -0xa0(%rbp)
movq 0x30(%r15), %rdi
callq 0x2250
movsd %xmm0, -0x68(%rbp)
movq 0x38(%r15), %rdi
callq 0x22b0
movl %eax, -0x6c(%rbp)
movq 0x40(%r15), %rdi
callq 0x22b0
movl %eax, -0x84(%rbp)
movq 0x48(%r15), %rdi
callq 0x22b0
movq %rax, -0x30(%rbp)
movl %ebx, -0x44(%rbp)
testl %ebx, %ebx
jle 0x64ef
movzbl %r12b, %eax
addl $-0x45, %eax
cmpl $0x10, %eax
ja 0x655a
movl $0x10a01, %ecx          # imm = 0x10A01
btl %eax, %ecx
jae 0x655a
xorpd %xmm0, %xmm0
ucomisd -0xb8(%rbp), %xmm0
jae 0x64ff
cmpl $0x0, -0x84(%rbp)
jle 0x651c
cmpl $0x0, -0x30(%rbp)
jle 0x652c
movsd -0x78(%rbp), %xmm2
addsd 0x3e13(%rip), %xmm2     # 0x9170
xorl %eax, %eax
ucomisd -0xb8(%rbp), %xmm2
jb 0x5387
xorl %eax, %eax
movsd 0x3e05(%rip), %xmm0     # 0x9178
movsd -0xb8(%rbp), %xmm1
incl %eax
mulsd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jae 0x537b
movsd %xmm2, -0x78(%rbp)
movl -0x44(%rbp), %ecx
movl %eax, %edx
imulq %rdx, %rcx
leaq 0xf(,%rcx,8), %rax
andq $-0x10, %rax
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, %rcx
subq %rax, %rcx
movq %rcx, -0xb0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rsp, %rsi
movq %rdx, -0x40(%rbp)
leaq 0xf(,%rdx,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rsi
movq %rsi, -0x118(%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, -0xd0(%rbp)
movq %rcx, %rsp
leaq -0x368(%rbp), %rbx
movq %rbx, %rdi
callq 0x2320
leaq -0x940(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x66a4
movq %rbx, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2060
leaq 0x401a(%rip), %rsi      # 0x9475
leaq -0x368(%rbp), %rdi
movl $0xe, %edx
callq 0x2230
leaq -0x800(%rbp), %rsi
movb %r12b, (%rsi)
leaq -0x368(%rbp), %rdi
movl $0x1, %edx
callq 0x2230
movq %rax, %rbx
leaq 0x3ff3(%rip), %rsi      # 0x9484
movl $0xd, %edx
movq %rax, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0xa0(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
leaq 0x3fda(%rip), %rsi      # 0x9492
movl $0xa, %edx
movq %rax, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0x68(%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
movq %r15, -0x110(%rbp)
movl -0x84(%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x138(%rbp)
cmpl $0x2, %eax
movl $0x1, %ebx
movl %r12d, %ecx
movl %eax, %r12d
cmovll %ebx, %r12d
movl -0x44(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %r13d
cmovgel %eax, %r13d
movq $0x0, -0x58(%rbp)
leaq -0x368(%rbp), %r15
movb %cl, -0x45(%rbp)
movsbl %cl, %eax
movl %eax, -0x80(%rbp)
movq %r13, -0xe0(%rbp)
movl $0x7, %edx
movq %r15, %rdi
leaq 0x3f35(%rip), %rsi      # 0x949d
callq 0x2230
movq -0x58(%rbp), %rax
leaq 0x1(%rax), %rsi
movq %r15, %rdi
movq %rsi, -0x120(%rbp)
callq 0x2340
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3f0f(%rip), %rsi      # 0x94a5
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
leaq -0x8a0(%rbp), %rdi
movl -0x80(%rbp), %esi
movl -0x84(%rbp), %edx
movl %ebx, -0xf4(%rbp)
movl %ebx, %ecx
movsd -0xa0(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
callq 0x251c
movsd -0x78(%rbp), %xmm0
ucomisd -0xb8(%rbp), %xmm0
movq -0x8a0(%rbp), %r14
jb 0x5a30
movq -0x58(%rbp), %rax
imulq -0x40(%rbp), %rax
movq -0xd8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0xf0(%rbp)
movq -0xd0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0xe8(%rbp)
movq -0xc0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x108(%rbp)
movq -0xb0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x130(%rbp)
movq -0xa8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x128(%rbp)
movq -0xc8(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x140(%rbp)
xorl %r13d, %r13d
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x56a4
movq -0x118(%rbp), %rax
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax,%r13,8)
movl $0x11, %edx
movq %r15, %rdi
leaq 0x3df4(%rip), %rsi      # 0x94a7
callq 0x2230
movq %r15, %rdi
movsd -0x38(%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
movsd -0x38(%rbp), %xmm0
mulsd -0x138(%rbp), %xmm0
cvttsd2si %xmm0, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq -0x800(%rbp), %rdi
movsd %xmm0, -0x50(%rbp)
movl $0x1, %esi
callq 0x46b4
leaq -0x168(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq -0x7e0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x572d
leaq -0x158(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movq -0x158(%rbp), %rax
movq -0x150(%rbp), %rcx
subq -0x168(%rbp), %rax
subq -0x160(%rbp), %rcx
movq -0xf0(%rbp), %rdx
movq %rax, (%rdx,%r13,8)
movq -0xe8(%rbp), %rax
movq %rcx, (%rax,%r13,8)
leaq -0x800(%rbp), %rdi
movl -0x80(%rbp), %esi
movq -0x30(%rbp), %rdx
movsd -0xa0(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
callq 0x68d1
movq -0x108(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x5, %edx
movq %r15, %rdi
leaq 0x3cf6(%rip), %rsi      # 0x94b9
movsd %xmm0, -0x60(%rbp)
callq 0x2230
movsd -0x60(%rbp), %xmm0
movq %r15, %rdi
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
cmpl $0x0, -0x6c(%rbp)
je 0x5984
leaq -0x600(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
movl $0x2, %esi
callq 0x46b4
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq -0x5e0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x5826
leaq -0x600(%rbp), %rdi
movl -0x80(%rbp), %esi
movq -0x30(%rbp), %rdx
movsd -0xa0(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
callq 0x68d1
movq -0x130(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0xa, %edx
movq %r15, %rdi
leaq 0x3c43(%rip), %rsi      # 0x94bf
movsd %xmm0, -0x60(%rbp)
callq 0x2230
movsd -0x60(%rbp), %xmm0
movq %r15, %rdi
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
leaq -0x400(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
movl $0x3, %esi
callq 0x46b4
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq -0x3e0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x58d5
leaq -0x400(%rbp), %rdi
movl -0x80(%rbp), %esi
movq -0x30(%rbp), %rdx
movsd -0xa0(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
callq 0x68d1
movq -0x128(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x15, %edx
movq %r15, %rdi
leaq 0x3b9f(%rip), %rsi      # 0x94ca
movsd %xmm0, -0x50(%rbp)
callq 0x2230
movsd -0x50(%rbp), %xmm0
movq %r15, %rdi
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
leaq -0x400(%rbp), %rdi
callq 0x4854
leaq -0x600(%rbp), %rdi
callq 0x4854
movq -0x7f0(%rbp), %rdx
movq -0x7e8(%rbp), %rcx
leaq -0x8a0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x2762
movq -0x140(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x7, %edx
movq %r15, %rdi
leaq 0x3b22(%rip), %rsi      # 0x94e0
movsd %xmm0, -0x50(%rbp)
callq 0x2230
movsd -0x50(%rbp), %xmm0
movq %r15, %rdi
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
movsd -0x38(%rbp), %xmm0
mulsd 0x376c(%rip), %xmm0     # 0x9178
movsd %xmm0, -0x38(%rbp)
incq %r13
leaq -0x800(%rbp), %rdi
callq 0x4854
movsd -0x78(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jae 0x568b
testq %r14, %r14
je 0x5a3d
movq %r14, %rdi
callq 0x2260
movl -0xf4(%rbp), %ebx
incl %ebx
movq -0x120(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq -0xe0(%rbp), %r13
cmpq %r13, %rcx
jne 0x5559
leaq -0x368(%rbp), %rdi
callq 0x2280
movq -0x110(%rbp), %r14
movb -0x45(%rbp), %r15b
leaq -0x940(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x66a4
leaq -0x368(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
leaq -0x800(%rbp), %rdi
callq 0x2320
leaq -0x400(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x5, %edx
callq 0x66a4
leaq -0x800(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
leaq -0x600(%rbp), %rdi
callq 0x2320
leaq -0x8a0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0x66a4
leaq -0x600(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
xorl %eax, %eax
cmpb $0x45, %r15b
sete %cl
cmpq $0x0, -0x40(%rbp)
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rsi
je 0x60e5
movb %cl, %al
movq -0x30(%rbp), %rcx
leal (%rax,%rcx), %r12d
addl $-0x3, %r12d
movl -0x44(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x78(%rbp)
movl %eax, -0xf8(%rbp)
fildl -0xf8(%rbp)
fstpt -0x108(%rbp)
movq -0x40(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %ecx, %ecx
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %r9
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %r8
movq %rbx, -0x60(%rbp)
movl %r12d, -0x58(%rbp)
movq %r9, -0x68(%rbp)
movq %r8, -0x50(%rbp)
movq %rdi, -0x38(%rbp)
movq %rax, -0x80(%rbp)
movq %rsi, -0xd0(%rbp)
movq %rdx, -0xd8(%rbp)
movq -0x118(%rbp), %rax
movq %rcx, -0xe8(%rbp)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xf0(%rbp)
mulsd 0x35af(%rip), %xmm0     # 0x9180
leaq -0x368(%rbp), %rdi
movsd %xmm0, -0x30(%rbp)
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38f7(%rip), %rsi      # 0x94e8
callq 0x2230
leaq -0x800(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x38d2(%rip), %rsi      # 0x94e8
callq 0x2230
xorpd %xmm1, %xmm1
movq %r13, %r14
xorl %r15d, %r15d
movq -0x50(%rbp), %rbx
movq -0x60(%rbp), %r12
movl -0x58(%rbp), %r13d
movsd %xmm1, -0x30(%rbp)
movq -0x38(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movaps %xmm0, -0xa0(%rbp)
movsd (%rbx,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movsd -0x30(%rbp), %xmm1
movapd -0xa0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x354a(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq %r12, %r15
decq %r14
jne 0x5c31
divsd -0x78(%rbp), %xmm1
leaq -0x368(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rsi
movq -0xe0(%rbp), %r13
movq %r13, %rax
xorl %ecx, %ecx
fldz
movsd 0x34cd(%rip), %xmm2     # 0x9188
movq -0x60(%rbp), %rdi
xorps %xmm0, %xmm0
cvtsi2sdq (%rdx,%rcx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%rsi,%rcx), %xmm1
divsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x148(%rbp)
faddl -0x148(%rbp)
addq %rdi, %rcx
decq %rax
jne 0x5cbf
fldt -0x108(%rbp)
fdivrp %st, %st(1)
subq $0x10, %rsp
fstpt (%rsp)
leaq -0x800(%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 0x5e77
xorpd %xmm1, %xmm1
movq %r13, %r14
xorl %r15d, %r15d
movq -0x50(%rbp), %rbx
movq -0x60(%rbp), %r12
movl -0x58(%rbp), %r13d
movsd %xmm1, -0x30(%rbp)
movq -0x68(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movaps %xmm0, -0xa0(%rbp)
movsd (%rbx,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movsd -0x30(%rbp), %xmm1
movapd -0xa0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x3423(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq %r12, %r15
decq %r14
jne 0x5d58
movsd %xmm1, -0x30(%rbp)
movl $0x1, %edx
leaq -0x368(%rbp), %rdi
leaq 0x3727(%rip), %rsi      # 0x94e8
callq 0x2230
movq -0xe0(%rbp), %r14
movsd -0x30(%rbp), %xmm0
divsd -0x78(%rbp), %xmm0
leaq -0x368(%rbp), %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x36f6(%rip), %rsi      # 0x94e8
callq 0x2230
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
movq -0x50(%rbp), %rbx
movq -0x60(%rbp), %r12
movl -0x58(%rbp), %r13d
movsd %xmm1, -0x30(%rbp)
movq -0x80(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movaps %xmm0, -0xa0(%rbp)
movsd (%rbx,%r15), %xmm0
movl %r13d, %edi
callq 0x422e
movsd -0x30(%rbp), %xmm1
movapd -0xa0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x3371(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq %r12, %r15
decq %r14
jne 0x5e0a
divsd -0x78(%rbp), %xmm1
leaq -0x368(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0xe0(%rbp), %r13
movq -0x368(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x368(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x368(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x11, %edx
leaq -0x600(%rbp), %rdi
leaq 0x35e7(%rip), %rsi      # 0x94a7
callq 0x2230
leaq -0x600(%rbp), %rdi
movsd -0xf0(%rbp), %xmm0
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
xorl %r15d, %r15d
movq -0x60(%rbp), %rbx
movl -0x58(%rbp), %r12d
movq -0x50(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x35ac(%rip), %rsi      # 0x94ea
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 -0x38(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3558(%rip), %rsi      # 0x94f2
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 0x6088
movq -0x68(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x34f6(%rip), %rsi      # 0x94f6
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 -0x80(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl %r12d, %edi
callq 0x422e
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x349e(%rip), %rsi      # 0x94fa
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 0x5f0e
movq -0xe8(%rbp), %rcx
incq %rcx
movq -0x50(%rbp), %r8
addq $0x8, %r8
movq -0x38(%rbp), %rdi
addq $0x8, %rdi
movq -0xd0(%rbp), %rsi
addq $0x8, %rsi
movq -0xd8(%rbp), %rdx
addq $0x8, %rdx
movq -0x68(%rbp), %r9
addq $0x8, %r9
movq -0x80(%rbp), %rax
addq $0x8, %rax
cmpq -0x40(%rbp), %rcx
movq -0xe0(%rbp), %r13
jne 0x5b90
leaq -0x600(%rbp), %rdi
callq 0x2280
leaq -0x368(%rbp), %rdi
callq 0x2280
leaq -0x800(%rbp), %rdi
callq 0x2280
leaq -0x940(%rbp), %r12
movq %r12, %rdi
movq -0x110(%rbp), %rsi
movl $0x2, %edx
callq 0x66a4
leaq -0x368(%rbp), %rdi
movq %r12, %rsi
movl $0x10, %edx
callq 0x2060
cmpq $0x0, -0x40(%rbp)
movq -0xc8(%rbp), %r15
je 0x61c0
movl -0x44(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x30(%rbp)
movq -0x40(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x368(%rbp), %r12
leaq 0x3374(%rip), %r13      # 0x94e8
movq %rax, -0x38(%rbp)
movq -0x30(%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 0x6183
movq -0x38(%rbp), %rax
incq %rax
movq -0xc8(%rbp), %r15
addq $0x8, %r15
cmpq -0x40(%rbp), %rax
jne 0x6174
movq -0x368(%rbp), %rax
leaq -0x368(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x368(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpq $0x0, -0x40(%rbp)
movq -0xc0(%rbp), %r15
je 0x627b
movl -0x44(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x30(%rbp)
movq -0x40(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x368(%rbp), %r12
leaq 0x32b9(%rip), %r13      # 0x94e8
movq %rax, -0x38(%rbp)
movq -0x30(%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 0x623e
movq -0x38(%rbp), %rax
incq %rax
movq -0xc0(%rbp), %r15
addq $0x8, %r15
cmpq -0x40(%rbp), %rax
jne 0x622f
movq -0x368(%rbp), %rax
leaq -0x368(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x368(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x6c(%rbp)
je 0x642e
cmpq $0x0, -0x40(%rbp)
movq -0xb0(%rbp), %r15
je 0x6340
movl -0x44(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x30(%rbp)
movq -0x40(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x368(%rbp), %r12
leaq 0x31f4(%rip), %r13      # 0x94e8
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rbx
movq %r15, -0xb0(%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 0x6303
movq -0x38(%rbp), %rax
incq %rax
movq -0xb0(%rbp), %r15
addq $0x8, %r15
cmpq -0x40(%rbp), %rax
jne 0x62f4
movq -0x368(%rbp), %rax
leaq -0x368(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x368(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpq $0x0, -0x40(%rbp)
movq -0xa8(%rbp), %r15
je 0x63fb
movl -0x44(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x30(%rbp)
movq -0x40(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x368(%rbp), %r12
leaq 0x3139(%rip), %r13      # 0x94e8
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rbx
movq %r15, -0xa8(%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 0x63be
movq -0x38(%rbp), %rax
incq %rax
movq -0xa8(%rbp), %r15
addq $0x8, %r15
cmpq -0x40(%rbp), %rax
jne 0x63af
movq -0x368(%rbp), %rax
leaq -0x368(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x368(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x368(%rbp), %r15
movq %r15, %rdi
callq 0x2280
movq 0x6b84(%rip), %rax      # 0xcfc8
movq (%rax), %rbx
movq 0x18(%rax), %r14
leaq -0x5f8(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x600(%rbp,%rax)
callq 0x21c0
movl $0xf8, %r12d
leaq -0x600(%rbp), %rdi
addq %r12, %rdi
callq 0x20b0
leaq -0x7f8(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x800(%rbp,%rax)
callq 0x21c0
leaq -0x800(%rbp), %rdi
addq %r12, %rdi
callq 0x20b0
leaq -0x360(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x368(%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 0x6aea(%rip), %rdi      # 0xcfd0
leaq 0x2e34(%rip), %rsi      # 0x9321
jmp 0x650d
movq 0x6ada(%rip), %rdi      # 0xcfd0
leaq 0x2e97(%rip), %rsi      # 0x9394
jmp 0x650d
movq 0x6aca(%rip), %rdi      # 0xcfd0
leaq 0x2ee2(%rip), %rsi      # 0x93ef
callq 0x2210
movq %rax, %rdi
callq 0x20f0
jmp 0x653f
movq 0x6aad(%rip), %rdi      # 0xcfd0
leaq 0x2ef6(%rip), %rsi      # 0x9420
jmp 0x653a
movq 0x6a9d(%rip), %rdi      # 0xcfd0
leaq 0x2f0f(%rip), %rsi      # 0x9449
callq 0x2210
movl $0x1, %edi
callq 0x2100
leaq 0x6728(%rip), %rsi      # 0xcc78
movq %rax, %rdi
xorl %edx, %edx
callq 0x2330
movq 0x6a6f(%rip), %rdi      # 0xcfd0
leaq 0x2e5d(%rip), %rsi      # 0x93c5
jmp 0x650d
jmp 0x65d5
jmp 0x656e
movq %rax, %rbx
jmp 0x660e
jmp 0x6582
jmp 0x6582
jmp 0x65d5
jmp 0x65d5
jmp 0x6582
jmp 0x65d5
movq %rax, %rbx
jmp 0x6666
jmp 0x65d5
jmp 0x65c4
jmp 0x6646
jmp 0x65a1
jmp 0x65d5
jmp 0x65d5
jmp 0x65d5
jmp 0x65d5
jmp 0x65b3
jmp 0x65c4
movq %rax, %rbx
jmp 0x6655
jmp 0x6646
jmp 0x6646
movq %rax, %rbx
leaq -0x400(%rbp), %rdi
callq 0x4854
jmp 0x65c7
movq %rax, %rbx
leaq -0x600(%rbp), %rdi
callq 0x4854
jmp 0x6649
movq %rax, %rbx
movq 0x69e9(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x5f8(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x600(%rbp,%rcx)
callq 0x21c0
leaq -0x508(%rbp), %rdi
callq 0x20b0
movq 0x69b3(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x7f8(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x800(%rbp,%rcx)
callq 0x21c0
leaq -0x708(%rbp), %rdi
callq 0x20b0
jmp 0x6666
movq %rax, %rbx
leaq -0x800(%rbp), %rdi
callq 0x4854
movq -0x8a0(%rbp), %rdi
testq %rdi, %rdi
je 0x6666
callq 0x2260
movq 0x695b(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x360(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x368(%rbp,%rcx)
callq 0x21c0
leaq -0x270(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2360