// File: /workspace/github_cpp_makefile_star2_O3/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 0x630b
movq %rsi, %r15
movq 0x8(%rsi), %rdi
callq 0x2250
movsd %xmm0, -0xd0(%rbp)
movq 0x10(%r15), %rdi
callq 0x2250
movsd %xmm0, -0x80(%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, -0x70(%rbp)
movq 0x38(%r15), %rdi
callq 0x22b0
movl %eax, -0x74(%rbp)
movq 0x40(%r15), %rdi
callq 0x22b0
movl %eax, -0x8c(%rbp)
movq 0x48(%r15), %rdi
callq 0x22b0
movq %rax, -0x40(%rbp)
testl %ebx, %ebx
jle 0x631b
movzbl %r12b, %eax
addl $-0x45, %eax
cmpl $0x10, %eax
ja 0x6386
movl $0x10a01, %ecx          # imm = 0x10A01
btl %eax, %ecx
jae 0x6386
xorpd %xmm0, %xmm0
ucomisd -0xd0(%rbp), %xmm0
jae 0x632b
cmpl $0x0, -0x8c(%rbp)
jle 0x6348
cmpl $0x0, -0x40(%rbp)
jle 0x6358
movsd -0x80(%rbp), %xmm2
addsd 0x3fe0(%rip), %xmm2     # 0x9170
xorl %eax, %eax
ucomisd -0xd0(%rbp), %xmm2
jb 0x51ba
xorl %eax, %eax
movsd 0x3fd2(%rip), %xmm0     # 0x9178
movsd -0xd0(%rbp), %xmm1
incl %eax
mulsd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jae 0x51ae
movsd %xmm2, -0x80(%rbp)
movl %ebx, -0xec(%rbp)
movl %ebx, %ecx
movl %eax, %edx
movq %rdx, %rax
movq %rcx, -0x58(%rbp)
imulq %rcx, %rax
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xb8(%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, -0x38(%rbp)
leaq 0xf(,%rdx,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rsi
movq %rsi, -0x110(%rbp)
movq %rsi, %rsp
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc8(%rbp)
movq %rcx, %rsp
leaq -0x360(%rbp), %rbx
movq %rbx, %rdi
callq 0x2320
leaq -0x940(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x64ff
movq %rbx, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2060
leaq 0x41e2(%rip), %rsi      # 0x9475
leaq -0x360(%rbp), %rdi
movl $0xe, %edx
callq 0x2230
leaq -0x800(%rbp), %rsi
movb %r12b, (%rsi)
leaq -0x360(%rbp), %rdi
movl $0x1, %edx
callq 0x2230
movq %rax, %rbx
leaq 0x41bb(%rip), %rsi      # 0x9484
movl $0xd, %edx
movq %rax, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0xa0(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
leaq 0x41a2(%rip), %rsi      # 0x9492
movl $0xa, %edx
movq %rax, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0x70(%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, -0x108(%rbp)
movl -0x8c(%rbp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, -0x130(%rbp)
movl %r12d, %eax
movl %ecx, %r12d
movl $0x1, -0x90(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x360(%rbp), %r15
movb %al, -0x41(%rbp)
movsbl %al, %eax
movl %eax, -0x88(%rbp)
movq %r13, -0xd8(%rbp)
movl $0x7, %edx
movq %r15, %rdi
leaq 0x410c(%rip), %rsi      # 0x949d
callq 0x2230
movq -0x60(%rbp), %rax
leaq 0x1(%rax), %rsi
movq %r15, %rdi
movq %rsi, -0x118(%rbp)
callq 0x2340
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x40e6(%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 -0x88(%rbp), %esi
movl -0x8c(%rbp), %edx
movl -0x90(%rbp), %ecx
movsd -0xa0(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0x251c
movsd -0xd0(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
ucomisd %xmm0, %xmm1
movq -0x8a0(%rbp), %r14
jae 0x5444
incl -0x90(%rbp)
testq %r14, %r14
jne 0x58c4
jmp 0x58cc
movq -0x60(%rbp), %rax
imulq -0x38(%rbp), %rax
leaq (,%rax,8), %rcx
addq %r13, %rcx
movq %rcx, -0xe8(%rbp)
movq -0xc8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0xe0(%rbp)
movq -0xb8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x100(%rbp)
movq -0xb0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x128(%rbp)
movq -0xa8(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x120(%rbp)
movq -0xc0(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0x138(%rbp)
xorl %r13d, %r13d
movsd %xmm0, -0x30(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x54da
movq -0x110(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax,%r13,8)
movl $0x11, %edx
movq %r15, %rdi
leaq 0x3fbe(%rip), %rsi      # 0x94a7
callq 0x2230
movq %r15, %rdi
movsd -0x30(%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 -0x30(%rbp), %xmm0
mulsd -0x130(%rbp), %xmm0
cvttsd2si %xmm0, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq -0x800(%rbp), %rdi
movsd %xmm0, -0x50(%rbp)
movl $0x1, %esi
callq 0x4506
leaq -0x160(%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 0x5563
leaq -0x150(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movq -0x150(%rbp), %rax
movq -0x148(%rbp), %rcx
subq -0x160(%rbp), %rax
subq -0x158(%rbp), %rcx
movq -0xe8(%rbp), %rdx
movq %rax, (%rdx,%r13,8)
movq -0xe0(%rbp), %rax
movq %rcx, (%rax,%r13,8)
leaq -0x800(%rbp), %rdi
movl -0x88(%rbp), %esi
movq -0x40(%rbp), %rdx
movsd -0xa0(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0x672c
movq -0x100(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x5, %edx
movq %r15, %rdi
leaq 0x3ebd(%rip), %rsi      # 0x94b9
movsd %xmm0, -0x68(%rbp)
callq 0x2230
movsd -0x68(%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, -0x74(%rbp)
je 0x57f3
leaq -0x600(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
movl $0x2, %esi
callq 0x4506
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq -0x5e0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x565f
leaq -0x600(%rbp), %rdi
movl -0x88(%rbp), %esi
movq -0x40(%rbp), %rdx
movsd -0xa0(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0x672c
movq -0x128(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0xa, %edx
movq %r15, %rdi
leaq 0x3e07(%rip), %rsi      # 0x94bf
movsd %xmm0, -0x68(%rbp)
callq 0x2230
movsd -0x68(%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 0x4506
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq -0x3e0(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x5711
leaq -0x400(%rbp), %rdi
movl -0x88(%rbp), %esi
movq -0x40(%rbp), %rdx
movsd -0xa0(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0x672c
movq -0x120(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x15, %edx
movq %r15, %rdi
leaq 0x3d60(%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
movq -0x3e0(%rbp), %rdi
callq 0x21f0
movq -0x3f0(%rbp), %rdi
callq 0x21f0
movq -0x3e8(%rbp), %rdi
callq 0x21f0
movq -0x5e0(%rbp), %rdi
callq 0x21f0
movq -0x5f0(%rbp), %rdi
callq 0x21f0
movq -0x5e8(%rbp), %rdi
callq 0x21f0
movq -0x7f0(%rbp), %rdx
movq -0x7e8(%rbp), %rcx
leaq -0x8a0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2738
movq -0x138(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
movl $0x7, %edx
movq %r15, %rdi
leaq 0x3cb3(%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 -0x30(%rbp), %xmm0
mulsd 0x38fd(%rip), %xmm0     # 0x9178
movsd %xmm0, -0x30(%rbp)
incq %r13
movq -0x7e0(%rbp), %rdi
callq 0x21f0
movq -0x7f0(%rbp), %rdi
callq 0x21f0
movq -0x7e8(%rbp), %rdi
callq 0x21f0
movsd -0x80(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jae 0x54c1
incl -0x90(%rbp)
movq -0xd8(%rbp), %r13
movq %r14, %rdi
callq 0x2260
movq -0x118(%rbp), %rcx
movq %rcx, -0x60(%rbp)
cmpq -0x58(%rbp), %rcx
jne 0x5382
leaq -0x360(%rbp), %rdi
callq 0x2280
movq -0x108(%rbp), %r14
movb -0x41(%rbp), %r15b
leaq -0x940(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x64ff
leaq -0x360(%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 0x64ff
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 0x64ff
leaq -0x600(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
xorl %eax, %eax
cmpb $0x45, %r15b
sete %cl
cmpq $0x0, -0x38(%rbp)
movq -0xc8(%rbp), %rdx
je 0x5f5d
movb %cl, %al
movq -0x40(%rbp), %rcx
leal (%rax,%rcx), %r12d
addl $-0x3, %r12d
movl -0xec(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x80(%rbp)
movl %eax, -0xf0(%rbp)
fildl -0xf0(%rbp)
fstpt -0x100(%rbp)
movq -0x38(%rbp), %rax
leaq (,%rax,8), %r15
xorl %ecx, %ecx
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rsi
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %r8
movq %r15, -0x68(%rbp)
movl %r12d, -0x60(%rbp)
movq %r8, -0x50(%rbp)
movq %r13, -0xd8(%rbp)
movq %rdi, -0x30(%rbp)
movq %rsi, -0x70(%rbp)
movq %rax, -0x88(%rbp)
movq %rdx, -0xc8(%rbp)
movq -0x110(%rbp), %rax
movq %rcx, -0xe0(%rbp)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xe8(%rbp)
mulsd 0x372f(%rip), %xmm0     # 0x9180
leaq -0x360(%rbp), %rdi
movsd %xmm0, -0x40(%rbp)
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3a77(%rip), %rsi      # 0x94e8
callq 0x2230
leaq -0x800(%rbp), %rdi
movsd -0x40(%rbp), %xmm0
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3a52(%rip), %rsi      # 0x94e8
callq 0x2230
xorpd %xmm1, %xmm1
movq -0x58(%rbp), %rbx
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
movq -0x68(%rbp), %r12
movl -0x60(%rbp), %r13d
movsd %xmm1, -0x40(%rbp)
movq -0x30(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r13d, %edi
callq 0x407f
movaps %xmm0, -0xa0(%rbp)
movsd (%r15,%r14), %xmm0
movl %r13d, %edi
callq 0x407f
movsd -0x40(%rbp), %xmm1
movapd -0xa0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x36c9(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq %r12, %r14
decq %rbx
jne 0x5ab2
divsd -0x80(%rbp), %xmm1
leaq -0x360(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0xc8(%rbp), %rdx
movq -0xd8(%rbp), %r14
movq -0x58(%rbp), %rax
xorl %ecx, %ecx
fldz
movsd 0x3652(%rip), %xmm2     # 0x9188
movq -0x68(%rbp), %rsi
xorps %xmm0, %xmm0
cvtsi2sdq (%r14,%rcx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%rdx,%rcx), %xmm1
divsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x140(%rbp)
faddl -0x140(%rbp)
addq %rsi, %rcx
decq %rax
jne 0x5b3a
fldt -0x100(%rbp)
fdivrp %st, %st(1)
subq $0x10, %rsp
fstpt (%rsp)
leaq -0x800(%rbp), %rdi
callq 0x2120
addq $0x10, %rsp
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, -0x74(%rbp)
je 0x5cec
xorpd %xmm1, %xmm1
movq -0x58(%rbp), %rbx
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
movq -0x68(%rbp), %r12
movl -0x60(%rbp), %r13d
movsd %xmm1, -0x40(%rbp)
movq -0x70(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r13d, %edi
callq 0x407f
movaps %xmm0, -0xa0(%rbp)
movsd (%r15,%r14), %xmm0
movl %r13d, %edi
callq 0x407f
movsd -0x40(%rbp), %xmm1
movapd -0xa0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x35a7(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq %r12, %r14
decq %rbx
jne 0x5bd4
movsd %xmm1, -0x40(%rbp)
movl $0x1, %edx
leaq -0x360(%rbp), %rdi
leaq 0x38ab(%rip), %rsi      # 0x94e8
callq 0x2230
movsd -0x40(%rbp), %xmm0
divsd -0x80(%rbp), %xmm0
leaq -0x360(%rbp), %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3881(%rip), %rsi      # 0x94e8
callq 0x2230
xorpd %xmm1, %xmm1
movq -0x58(%rbp), %rbx
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
movq -0x68(%rbp), %r12
movl -0x60(%rbp), %r13d
movsd %xmm1, -0x40(%rbp)
movq -0x88(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r13d, %edi
callq 0x407f
movaps %xmm0, -0xa0(%rbp)
movsd (%r15,%r14), %xmm0
movl %r13d, %edi
callq 0x407f
movsd -0x40(%rbp), %xmm1
movapd -0xa0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x34f5(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq %r12, %r14
decq %rbx
jne 0x5c83
divsd -0x80(%rbp), %xmm1
leaq -0x360(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0x360(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x360(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x360(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x11, %edx
leaq -0x600(%rbp), %rdi
leaq 0x3772(%rip), %rsi      # 0x94a7
callq 0x2230
leaq -0x600(%rbp), %rdi
movsd -0xe8(%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 -0x58(%rbp), %r13
xorl %r14d, %r14d
movq -0x68(%rbp), %r15
movl -0x60(%rbp), %r12d
movq -0x50(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r12d, %edi
callq 0x407f
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x7, %edx
movq %rax, %rdi
leaq 0x3733(%rip), %rsi      # 0x94ea
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
movq -0x30(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r12d, %edi
callq 0x407f
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x36df(%rip), %rsi      # 0x94f2
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
cmpl $0x0, -0x74(%rbp)
je 0x5f04
movq -0x70(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r12d, %edi
callq 0x407f
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x367d(%rip), %rsi      # 0x94f6
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
movq -0x88(%rbp), %rax
movsd (%rax,%r14), %xmm0
movl %r12d, %edi
callq 0x407f
leaq -0x600(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3622(%rip), %rsi      # 0x94fa
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
addq %r15, %r14
decq %r13
jne 0x5d87
movq -0xe0(%rbp), %rcx
incq %rcx
movq -0x50(%rbp), %r8
addq $0x8, %r8
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
movq -0xc8(%rbp), %rdx
addq $0x8, %rdx
movq -0xd8(%rbp), %r13
addq $0x8, %r13
movq -0x70(%rbp), %rsi
addq $0x8, %rsi
movq -0x88(%rbp), %rax
addq $0x8, %rax
cmpq -0x38(%rbp), %rcx
jne 0x5a0d
leaq -0x600(%rbp), %rdi
callq 0x2280
leaq -0x360(%rbp), %rdi
callq 0x2280
leaq -0x800(%rbp), %rdi
callq 0x2280
leaq -0x940(%rbp), %r12
movq %r12, %rdi
movq -0x108(%rbp), %rsi
movl $0x2, %edx
callq 0x64ff
leaq -0x360(%rbp), %rdi
movq %r12, %rsi
movl $0x10, %edx
callq 0x2060
cmpl $0x0, -0x38(%rbp)
movq -0xc0(%rbp), %r14
je 0x6025
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %eax, %eax
leaq -0x360(%rbp), %r12
leaq 0x350f(%rip), %r13      # 0x94e8
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %r15
movq %r14, -0xc0(%rbp)
movsd (%r14), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %rbx, %r14
decq %r15
jne 0x5fe8
movq -0x30(%rbp), %rax
incq %rax
movq -0xc0(%rbp), %r14
addq $0x8, %r14
cmpq -0x38(%rbp), %rax
jne 0x5fd9
movq -0x360(%rbp), %rax
leaq -0x360(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x360(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x38(%rbp)
movq -0xb8(%rbp), %r14
je 0x60cd
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %eax, %eax
leaq -0x360(%rbp), %r12
leaq 0x3467(%rip), %r13      # 0x94e8
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %r15
movq %r14, -0xb8(%rbp)
movsd (%r14), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %rbx, %r14
decq %r15
jne 0x6090
movq -0x30(%rbp), %rax
incq %rax
movq -0xb8(%rbp), %r14
addq $0x8, %r14
cmpq -0x38(%rbp), %rax
jne 0x6081
movq -0x360(%rbp), %rax
leaq -0x360(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x360(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x74(%rbp)
je 0x625a
cmpl $0x0, -0x38(%rbp)
movq -0xb0(%rbp), %r14
je 0x617f
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %eax, %eax
leaq -0x360(%rbp), %r12
leaq 0x33b5(%rip), %r13      # 0x94e8
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %r15
movq %r14, -0xb0(%rbp)
movsd (%r14), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %rbx, %r14
decq %r15
jne 0x6142
movq -0x30(%rbp), %rax
incq %rax
movq -0xb0(%rbp), %r14
addq $0x8, %r14
cmpq -0x38(%rbp), %rax
jne 0x6133
movq -0x360(%rbp), %rax
leaq -0x360(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x360(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, -0x38(%rbp)
movq -0xa8(%rbp), %r14
je 0x6227
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %eax, %eax
leaq -0x360(%rbp), %r12
leaq 0x330d(%rip), %r13      # 0x94e8
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %r15
movq %r14, -0xa8(%rbp)
movsd (%r14), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2230
addq %rbx, %r14
decq %r15
jne 0x61ea
movq -0x30(%rbp), %rax
incq %rax
movq -0xa8(%rbp), %r14
addq $0x8, %r14
cmpq -0x38(%rbp), %rax
jne 0x61db
movq -0x360(%rbp), %rax
leaq -0x360(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
leaq -0x360(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x360(%rbp), %r15
movq %r15, %rdi
callq 0x2280
movq 0x6d58(%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 -0x358(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x360(%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 0x6cbe(%rip), %rdi      # 0xcfd0
leaq 0x3008(%rip), %rsi      # 0x9321
jmp 0x6339
movq 0x6cae(%rip), %rdi      # 0xcfd0
leaq 0x306b(%rip), %rsi      # 0x9394
jmp 0x6339
movq 0x6c9e(%rip), %rdi      # 0xcfd0
leaq 0x30b6(%rip), %rsi      # 0x93ef
callq 0x2210
movq %rax, %rdi
callq 0x20f0
jmp 0x636b
movq 0x6c81(%rip), %rdi      # 0xcfd0
leaq 0x30ca(%rip), %rsi      # 0x9420
jmp 0x6366
movq 0x6c71(%rip), %rdi      # 0xcfd0
leaq 0x30e3(%rip), %rsi      # 0x9449
callq 0x2210
movl $0x1, %edi
callq 0x2100
leaq 0x68fc(%rip), %rsi      # 0xcc78
movq %rax, %rdi
xorl %edx, %edx
callq 0x2330
movq 0x6c43(%rip), %rdi      # 0xcfd0
leaq 0x3031(%rip), %rsi      # 0x93c5
jmp 0x6339
jmp 0x641c
jmp 0x639d
movq %rax, %rbx
jmp 0x6455
jmp 0x63b1
jmp 0x63b1
jmp 0x641c
jmp 0x641c
jmp 0x63b1
jmp 0x641c
movq %rax, %rbx
jmp 0x64c1
jmp 0x641c
jmp 0x63f3
jmp 0x648d
jmp 0x63d0
jmp 0x641c
jmp 0x641c
jmp 0x641c
jmp 0x641c
jmp 0x63e2
jmp 0x63f3
movq %rax, %rbx
jmp 0x64b4
jmp 0x648d
jmp 0x648d
movq %rax, %rbx
leaq -0x400(%rbp), %rdi
callq 0x46a4
jmp 0x63f6
movq %rax, %rbx
movq -0x5e0(%rbp), %rdi
callq 0x21f0
movq -0x5f0(%rbp), %rdi
callq 0x21f0
movq -0x5e8(%rbp), %rdi
callq 0x21f0
jmp 0x6490
movq %rax, %rbx
movq 0x6ba2(%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 0x6b6c(%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 0x64c1
movq %rax, %rbx
movq -0x7e0(%rbp), %rdi
callq 0x21f0
movq -0x7f0(%rbp), %rdi
callq 0x21f0
movq -0x7e8(%rbp), %rdi
callq 0x21f0
testq %r14, %r14
je 0x64c1
movq %r14, %rdi
callq 0x2260
movq 0x6b00(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x358(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x360(%rbp,%rcx)
callq 0x21c0
leaq -0x268(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2360