// File: /workspace/github_cpp_makefile_star2_O1/ashlall[P]StreamStats/ChiSquareExperiments/VaryMemoryTwoSample.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc < 12)
  {
    cout << "usage: VaryMemoryTwoSample lower-memory upper-memory num-stream(>0) [N|U|P|E] location1 scale1 location2 scale2 [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 location1 = atof (argv[5]);
  double scale1 = atof (argv[6]);
  double location2 = atof (argv[7]);
  double scale2 = atof (argv[8]);
  int all_quantiles = atoi (argv[9]);
  int stream_size = atoi (argv[10]);
  int num_buckets = atoi (argv[11]);
  int seed1 = 1;
  int seed2 = 2;

  // ensures that the parameters will not create error
  if (data_repeats <= 0)
  {
    cout << "The number of streams must be greater than zero.\n";
    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.\n";
    throw ParameterError();
  }
  if (lower <= 0)
  {
    cout << "The lower percent of memory must be greater than 0.\n";
    throw ParameterError();
  }
  if (num_buckets <= 0)
  {
    cout << "The number of buckets must be greater than 0.\n";
    throw ParameterError();
  }
  if (stream_size <= 0)
  {
    cout << "The stream size must be greater than 0.\n";
    throw ParameterError();
  }

  // finds the number of different bins the experiment will run on
  double memory_percent;
  int num_mems = 0;
  double mem = lower;
  while (mem <= (upper + 0.0000001))
  {
    num_mems++;
    mem *= sqrt(10);
  }

  // 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];

  // creates and intializes the log file
  ofstream data_file;
  char str[150];
  name_file(str, argv, 0);
  data_file.open(str);
  data_file << "Distribution: " << distribution_type << endl;
  data_file << "location_1 = " << location1 << " scale_1 = " << scale1 << endl;
  data_file << "location_2 = " << location2 << " scale_2 = " << scale2 << endl;
  data_file << "stream_size = " << stream_size << endl;
  data_file << "num_buckets = " << num_buckets << endl;

  for (int i = 0; i < data_repeats; i++) // runs all test data_repeats times
  {
    memory_percent = lower;
    int j = 0;
    data_file << "Pass " << i+1 << ":" << endl;

    // generates the data based on parameters                                                
    DataGenerator data1(distribution_type, stream_size, seed1, location1, scale1);
    double *stream1 = data1.get_stream();
    DataGenerator data2(distribution_type, stream_size, seed2, location2, scale2);
    double *stream2 = data2.get_stream();

    while (memory_percent <= (upper + 0.00000001))  // runs tests for every memory percent
    { 
      int sample_size = memory_percent * stream_size;
      if (!i)
	percents[j] = memory_percent;

      // computes GK estimate
      ChiSquareContinuous *GK_sketch1 = new ChiSquareContinuous(sample_size, 1);
      for (int k = 0; k < stream_size; k++)
        GK_sketch1->insert(stream1[k]);
      ChiSquareContinuous *GK_sketch2 = new ChiSquareContinuous(sample_size, 1);
      for (int k = 0; k < stream_size; k++)
        GK_sketch2->insert(stream2[k]);
      double GK_stat = GK_sketch1->two_sample_statistic(*GK_sketch2, num_buckets);
      GK_values[i][j] = GK_stat;
      data_file << "GK = " << GK_stat << endl;

      if (all_quantiles)
      {
        // computes QDigest estimate
        ChiSquareContinuous QD_sketch1(sample_size, 2);
        for (int k = 0; k < stream_size; k++)
          QD_sketch1.insert(stream1[k]);
        ChiSquareContinuous QD_sketch2(sample_size, 2);
        for (int k = 0; k < stream_size; k++)
          QD_sketch2.insert(stream2[k]);
        double QD_stat = QD_sketch1.two_sample_statistic(QD_sketch2, num_buckets);
        QD_values[i][j] = QD_stat;
        data_file << "QD = " << QD_stat << endl;

        // computes Reservoir Sampling estimate
        ChiSquareContinuous RS_sketch1(sample_size, 3);
        for (int k = 0; k < stream_size; k++)
          RS_sketch1.insert(stream1[k]);
        ChiSquareContinuous RS_sketch2(sample_size, 3);
        for (int k = 0; k < stream_size; k++)
          RS_sketch2.insert(stream2[k]);
        double RS_stat = RS_sketch1.two_sample_statistic(RS_sketch2, num_buckets);
        RS_values[i][j]= RS_stat;
        data_file << "RS = " << RS_stat<< endl;
      }
       
      // computes actual statistic
      double *upper_interval = GK_sketch1->get_upper();
      double *lower_interval = GK_sketch1->get_lower();
      double actual = data2.get_stat_two_sample(data1, num_buckets, upper_interval, lower_interval);
      actual_values[i][j] = actual;
      data_file << "Real = " << actual << endl;

      memory_percent *= sqrt(10);
      j++;
    }     
    seed1++;
    seed2++;
  }
  data_file.close();

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

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

  int deg_freedom = num_buckets;
  for (int i = 0; i < num_mems; i++)
  {
    data_file << percents[i] * 100 << "\t";
    double error = 0;

    // adds pvalue error from the GK sketch to the table file
    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;

    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();

  // 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 statistics 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 << endl;
  data_file.close();
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6a8, %rsp            # imm = 0x6A8
cmpl $0xb, %edi
jle 0x6551
movq %rsi, %r12
movq 0x8(%rsi), %rdi
callq 0x2240
movsd %xmm0, -0x98(%rbp)
movq 0x10(%r12), %rdi
callq 0x2240
movsd %xmm0, -0x60(%rbp)
movq 0x18(%r12), %rdi
callq 0x22b0
movl %eax, %ebx
movq 0x20(%r12), %rax
movq 0x28(%r12), %rdi
movb (%rax), %r14b
callq 0x2240
movsd %xmm0, -0x108(%rbp)
movq 0x30(%r12), %rdi
callq 0x2240
movsd %xmm0, -0x100(%rbp)
movq 0x38(%r12), %rdi
callq 0x2240
movsd %xmm0, -0xf8(%rbp)
movq 0x40(%r12), %rdi
callq 0x2240
movsd %xmm0, -0xf0(%rbp)
movq 0x48(%r12), %rdi
callq 0x22b0
movl %eax, -0x68(%rbp)
movq 0x50(%r12), %rdi
callq 0x22b0
movl %eax, -0x64(%rbp)
movq 0x58(%r12), %rdi
callq 0x22b0
movl %ebx, -0x54(%rbp)
testl %ebx, %ebx
jle 0x656e
movzbl %r14b, %edx
addl $-0x45, %edx
cmpl $0x10, %edx
ja 0x65ae
movl $0x10a01, %ecx          # imm = 0x10A01
btl %edx, %ecx
jae 0x65ae
xorpd %xmm0, %xmm0
ucomisd -0x98(%rbp), %xmm0
jae 0x657e
testl %eax, %eax
jle 0x658e
cmpl $0x0, -0x64(%rbp)
jle 0x659e
movb %r14b, -0x29(%rbp)
movl %eax, -0x40(%rbp)
movsd 0x3dfe(%rip), %xmm0     # 0x9170
addsd -0x60(%rbp), %xmm0
xorl %eax, %eax
ucomisd -0x98(%rbp), %xmm0
jb 0x53a1
xorl %eax, %eax
movsd 0x3deb(%rip), %xmm1     # 0x9178
movsd -0x98(%rbp), %xmm2
incl %eax
mulsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jae 0x5395
movl -0x54(%rbp), %ecx
movl %eax, %edx
imulq %rdx, %rcx
leaq 0xf(,%rcx,8), %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %rcx
movq %rdx, -0x50(%rbp)
leaq 0xf(,%rdx,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x110(%rbp)
movq %rcx, %rsp
leaq -0x398(%rbp), %rbx
movq %rbx, %rdi
callq 0x2310
leaq -0x6d0(%rbp), %r14
movq %r14, %rdi
movq %r12, -0xe8(%rbp)
movq %r12, %rsi
xorl %edx, %edx
callq 0x66f1
movq %rbx, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2060
movb -0x29(%rbp), %r14b
leaq 0x4035(%rip), %rsi      # 0x9489
leaq -0x398(%rbp), %rdi
movl $0xe, %edx
callq 0x2220
leaq -0x630(%rbp), %rsi
movb %r14b, (%rsi)
leaq -0x398(%rbp), %rdi
movl $0x1, %edx
callq 0x2220
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x3fe7(%rip), %rsi      # 0x9498
leaq -0x398(%rbp), %rdi
movl $0xd, %edx
callq 0x2220
leaq -0x398(%rbp), %rdi
movsd -0x108(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
leaq 0x3fc6(%rip), %rsi      # 0x94a6
movl $0xb, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
movsd -0x100(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x3f84(%rip), %rsi      # 0x94b2
leaq -0x398(%rbp), %rdi
movl $0xd, %edx
callq 0x2220
leaq -0x398(%rbp), %rdi
movsd -0xf8(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
leaq 0x3f63(%rip), %rsi      # 0x94c0
movl $0xb, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
movsd -0xf0(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x3f21(%rip), %rsi      # 0x94cc
leaq -0x398(%rbp), %rdi
movl $0xe, %edx
callq 0x2220
leaq -0x398(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x2330
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x3edf(%rip), %rsi      # 0x94db
leaq -0x398(%rbp), %rdi
movl $0xe, %edx
callq 0x2220
leaq -0x398(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x2330
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movsd -0x60(%rbp), %xmm0
addsd 0x3b2d(%rip), %xmm0     # 0x9180
movsd %xmm0, -0x60(%rbp)
movl -0x64(%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0xd8(%rbp)
cmpl $0x2, %eax
movl $0x1, %ecx
movl %eax, %r12d
movl $0x1, -0xc0(%rbp)
cmovll %ecx, %r12d
movl -0x54(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0xb0(%rbp)
movl $0x2, -0xbc(%rbp)
movq $0x0, -0x70(%rbp)
movq %r15, -0x88(%rbp)
movl $0x5, %edx
leaq -0x398(%rbp), %rdi
leaq 0x3e26(%rip), %rsi      # 0x94ea
callq 0x2220
movq -0x70(%rbp), %rax
leaq 0x1(%rax), %rsi
leaq -0x398(%rbp), %rdi
movq %rsi, -0x118(%rbp)
callq 0x2330
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3dfa(%rip), %rsi      # 0x94f0
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movsbl %r14b, %ebx
leaq -0x148(%rbp), %rdi
movl %ebx, %esi
movl -0x64(%rbp), %r14d
movl %r14d, %edx
movl -0xc0(%rbp), %ecx
movsd -0x108(%rbp), %xmm0
movsd -0x100(%rbp), %xmm1
callq 0x250c
movq -0x148(%rbp), %r15
leaq -0x138(%rbp), %rdi
movl %ebx, %esi
movl %r14d, %edx
movl -0xbc(%rbp), %ecx
movsd -0xf8(%rbp), %xmm0
movsd -0xf0(%rbp), %xmm1
callq 0x250c
movsd -0x60(%rbp), %xmm0
ucomisd -0x98(%rbp), %xmm0
movq -0x138(%rbp), %r14
jb 0x5bee
movq -0x70(%rbp), %rax
imulq -0x50(%rbp), %rax
movq -0xa0(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0xb8(%rbp)
movq -0x90(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x128(%rbp)
movq -0x88(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, -0x120(%rbp)
movq -0xa8(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, -0xe0(%rbp)
movq $0x0, -0x38(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x5821
movq -0x110(%rbp), %rax
movq -0x38(%rbp), %rcx
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x28, %edi
callq 0x2210
movq %rax, %rbx
movsd -0xd0(%rbp), %xmm0
mulsd -0xd8(%rbp), %xmm0
cvttsd2si %xmm0, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq %rbx, %rdi
movsd %xmm0, -0x48(%rbp)
movl $0x1, %esi
callq 0x46a4
xorl %r13d, %r13d
movsd (%r15,%r13,8), %xmm0
movq 0x20(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %r13
cmpq %r13, %r12
jne 0x585e
movl $0x28, %edi
callq 0x2210
movq %rax, %r13
movq %rax, %rdi
movsd -0x48(%rbp), %xmm0
movl $0x1, %esi
callq 0x46a4
movq %rbx, -0x80(%rbp)
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq 0x20(%r13), %rdi
movq (%rdi), %rax
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x589a
movq -0x80(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movl -0x40(%rbp), %edx
callq 0x4f80
movq -0xb8(%rbp), %rax
movq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x5, %edx
leaq -0x398(%rbp), %rdi
leaq 0x3c0c(%rip), %rsi      # 0x94f2
movsd %xmm0, -0x78(%rbp)
callq 0x2220
movsd -0x78(%rbp), %xmm0
leaq -0x398(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
cmpl $0x0, -0x68(%rbp)
je 0x5b3d
leaq -0x630(%rbp), %rdi
movsd -0x48(%rbp), %xmm0
movl $0x2, %esi
callq 0x46a4
movq -0x610(%rbp), %r13
xorl %ebx, %ebx
movsd (%r15,%rbx,8), %xmm0
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x5954
leaq -0x430(%rbp), %rdi
movsd -0x48(%rbp), %xmm0
movl $0x2, %esi
callq 0x46a4
movq -0x410(%rbp), %r13
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x598a
leaq -0x630(%rbp), %rdi
leaq -0x430(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x4f80
movq -0x128(%rbp), %rax
movq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x5, %edx
leaq -0x398(%rbp), %rdi
leaq 0x3b1e(%rip), %rsi      # 0x94f8
movsd %xmm0, -0x78(%rbp)
callq 0x2220
movsd -0x78(%rbp), %xmm0
leaq -0x398(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq -0x198(%rbp), %rdi
movsd -0x48(%rbp), %xmm0
movl $0x3, %esi
callq 0x46a4
movq -0x178(%rbp), %r13
xorl %ebx, %ebx
movsd (%r15,%rbx,8), %xmm0
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x5a3e
leaq -0x170(%rbp), %rdi
movsd -0x48(%rbp), %xmm0
movl $0x3, %esi
callq 0x46a4
movq -0x150(%rbp), %r13
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movq (%r13), %rax
movq %r13, %rdi
callq *(%rax)
incq %rbx
cmpq %rbx, %r12
jne 0x5a74
leaq -0x198(%rbp), %rdi
leaq -0x170(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x4f80
movq -0x120(%rbp), %rax
movq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x5, %edx
leaq -0x398(%rbp), %rdi
leaq 0x3a3a(%rip), %rsi      # 0x94fe
movsd %xmm0, -0x48(%rbp)
callq 0x2220
movsd -0x48(%rbp), %xmm0
leaq -0x398(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq -0x170(%rbp), %rdi
callq 0x4844
leaq -0x198(%rbp), %rdi
callq 0x4844
leaq -0x430(%rbp), %rdi
callq 0x4844
leaq -0x630(%rbp), %rdi
callq 0x4844
movq -0x80(%rbp), %rbx
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %r8
leaq -0x138(%rbp), %rdi
leaq -0x148(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x27e6
movq -0xe0(%rbp), %rax
movq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x7, %edx
leaq -0x398(%rbp), %rdi
leaq 0x3986(%rip), %rsi      # 0x9504
movsd %xmm0, -0x48(%rbp)
callq 0x2220
movsd -0x48(%rbp), %xmm0
leaq -0x398(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movsd -0xd0(%rbp), %xmm1
mulsd 0x35a5(%rip), %xmm1     # 0x9178
incq -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm1, -0xd0(%rbp)
ucomisd %xmm1, %xmm0
jae 0x5802
testq %r14, %r14
je 0x5bfb
movq %r14, %rdi
callq 0x2250
testq %r15, %r15
je 0x5c08
movq %r15, %rdi
callq 0x2250
incl -0xc0(%rbp)
incl -0xbc(%rbp)
movq -0x118(%rbp), %rcx
movq %rcx, -0x70(%rbp)
cmpq -0xb0(%rbp), %rcx
movb -0x29(%rbp), %r14b
jne 0x56b1
leaq -0x398(%rbp), %rdi
callq 0x2270
leaq -0x630(%rbp), %rdi
callq 0x2310
movq -0xe8(%rbp), %r14
leaq -0x430(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq 0x66f1
leaq -0x630(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
leaq -0x6d0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x66f1
leaq -0x398(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2060
cmpq $0x0, -0x50(%rbp)
je 0x6151
xorps %xmm0, %xmm0
cvtsi2sdl -0x54(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x50(%rbp), %rax
leaq (,%rax,8), %r12
xorl %ecx, %ecx
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %r14
movq %r12, -0x38(%rbp)
movq %rsi, -0x78(%rbp)
movq %r14, -0x60(%rbp)
movq %rdx, -0x80(%rbp)
movq %rax, -0x70(%rbp)
movq -0x110(%rbp), %rax
movq %rcx, -0xd8(%rbp)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xe0(%rbp)
mulsd 0x3467(%rip), %xmm0     # 0x9188
leaq -0x398(%rbp), %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x37d0(%rip), %rsi      # 0x950c
callq 0x2220
xorpd %xmm1, %xmm1
movq -0xb0(%rbp), %rbx
xorl %r15d, %r15d
movl -0x40(%rbp), %r13d
movq -0x80(%rbp), %r14
movq -0x60(%rbp), %r12
movsd %xmm1, -0x48(%rbp)
movsd (%r14,%r15), %xmm0
movl %r13d, %edi
callq 0x421e
movaps %xmm0, -0xd0(%rbp)
movsd (%r12,%r15), %xmm0
movl %r13d, %edi
callq 0x421e
movsd -0x48(%rbp), %xmm1
movapd -0xd0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x3424(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq -0x38(%rbp), %r15
decq %rbx
jne 0x5d5b
divsd -0xb8(%rbp), %xmm1
leaq -0x398(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0x38(%rbp), %r12
cmpl $0x0, -0x68(%rbp)
je 0x5f05
xorpd %xmm1, %xmm1
movq -0xb0(%rbp), %rbx
xorl %r15d, %r15d
movl -0x40(%rbp), %r13d
movq -0x60(%rbp), %r14
movq -0x78(%rbp), %r12
movsd %xmm1, -0x48(%rbp)
movsd (%r12,%r15), %xmm0
movl %r13d, %edi
callq 0x421e
movaps %xmm0, -0xd0(%rbp)
movsd (%r14,%r15), %xmm0
movl %r13d, %edi
callq 0x421e
movsd -0x48(%rbp), %xmm1
movapd -0xd0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x3396(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq -0x38(%rbp), %r15
decq %rbx
jne 0x5de9
movsd %xmm1, -0x48(%rbp)
movl $0x1, %edx
leaq -0x398(%rbp), %rdi
leaq 0x36bd(%rip), %rsi      # 0x950c
callq 0x2220
movsd -0x48(%rbp), %xmm0
divsd -0xb8(%rbp), %xmm0
leaq -0x398(%rbp), %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3690(%rip), %rsi      # 0x950c
callq 0x2220
xorpd %xmm1, %xmm1
movq -0xb0(%rbp), %rbx
xorl %r15d, %r15d
movl -0x40(%rbp), %r13d
movq -0x70(%rbp), %r12
movq -0x60(%rbp), %r14
movsd %xmm1, -0x48(%rbp)
movsd (%r12,%r15), %xmm0
movl %r13d, %edi
callq 0x421e
movaps %xmm0, -0xd0(%rbp)
movsd (%r14,%r15), %xmm0
movl %r13d, %edi
callq 0x421e
movsd -0x48(%rbp), %xmm1
movapd -0xd0(%rbp), %xmm2
subsd %xmm0, %xmm2
andpd 0x32e4(%rip), %xmm2     # 0x91c0
addsd %xmm2, %xmm1
addq -0x38(%rbp), %r15
decq %rbx
jne 0x5e9b
divsd -0xb8(%rbp), %xmm1
leaq -0x398(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x22c0
movq -0x38(%rbp), %r12
movq -0x398(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x398(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x398(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movl $0x11, %edx
leaq -0x630(%rbp), %rdi
leaq 0x35c0(%rip), %rsi      # 0x950e
callq 0x2220
leaq -0x630(%rbp), %rdi
movsd -0xe0(%rbp), %xmm0
callq 0x22c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0xb0(%rbp), %r13
xorl %r15d, %r15d
movq -0x60(%rbp), %r14
movsd (%r14,%r15), %xmm0
movl -0x40(%rbp), %edi
callq 0x421e
leaq -0x630(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x7, %edx
movq %rax, %rdi
leaq 0x3555(%rip), %rsi      # 0x9520
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0x80(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl -0x40(%rbp), %edi
callq 0x421e
leaq -0x630(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3501(%rip), %rsi      # 0x9528
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
cmpl $0x0, -0x68(%rbp)
je 0x6115
movq -0x78(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl -0x40(%rbp), %edi
callq 0x421e
leaq -0x630(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x349f(%rip), %rsi      # 0x952c
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0x70(%rbp), %rax
movsd (%rax,%r15), %xmm0
movl -0x40(%rbp), %edi
callq 0x421e
leaq -0x630(%rbp), %rdi
callq 0x22c0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x3447(%rip), %rsi      # 0x9530
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
addq %r12, %r15
decq %r13
jne 0x5f9f
movq -0xd8(%rbp), %rcx
incq %rcx
addq $0x8, %r14
movq -0x80(%rbp), %rdx
addq $0x8, %rdx
movq -0x78(%rbp), %rsi
addq $0x8, %rsi
movq -0x70(%rbp), %rax
addq $0x8, %rax
cmpq -0x50(%rbp), %rcx
jne 0x5cee
leaq -0x630(%rbp), %rdi
callq 0x2270
leaq -0x398(%rbp), %rdi
callq 0x2270
leaq -0x6d0(%rbp), %r15
movq %r15, %rdi
movq -0xe8(%rbp), %rsi
movl $0x2, %edx
callq 0x66f1
leaq -0x398(%rbp), %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x2060
cmpq $0x0, -0x50(%rbp)
movq -0xa8(%rbp), %r14
je 0x6220
movl -0x54(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x50(%rbp), %rax
leaq (,%rax,8), %r13
xorl %eax, %eax
leaq -0x398(%rbp), %r15
leaq 0x3338(%rip), %r12      # 0x950c
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r14, -0xa8(%rbp)
movsd (%r14), %xmm0
movq %r15, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2220
addq %r13, %r14
decq %rbx
jne 0x61e3
movq -0x40(%rbp), %rax
incq %rax
movq -0xa8(%rbp), %r14
addq $0x8, %r14
cmpq -0x50(%rbp), %rax
jne 0x61d4
movq -0x398(%rbp), %rax
leaq -0x398(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x398(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
cmpq $0x0, -0x50(%rbp)
movq -0xa0(%rbp), %r14
je 0x62db
movl -0x54(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x50(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %eax, %eax
leaq -0x398(%rbp), %r15
leaq 0x327d(%rip), %r12      # 0x950c
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %r13
movq %r14, -0xa0(%rbp)
movsd (%r14), %xmm0
movq %r15, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2220
addq %rbx, %r14
decq %r13
jne 0x629e
movq -0x40(%rbp), %rax
incq %rax
movq -0xa0(%rbp), %r14
addq $0x8, %r14
cmpq -0x50(%rbp), %rax
jne 0x628f
movq -0x398(%rbp), %rax
leaq -0x398(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x398(%rbp), %rbx
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
cmpl $0x0, -0x68(%rbp)
je 0x649c
cmpq $0x0, -0x50(%rbp)
movq -0x90(%rbp), %r13
je 0x63a4
movl -0x54(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x50(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x398(%rbp), %r15
leaq 0x31b5(%rip), %r12      # 0x950c
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r13, -0x90(%rbp)
movsd (%r13), %xmm0
movq %r15, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2220
addq %r14, %r13
decq %rbx
jne 0x6366
movq -0x40(%rbp), %rax
incq %rax
movq -0x90(%rbp), %r13
addq $0x8, %r13
cmpq -0x50(%rbp), %rax
jne 0x6357
movq -0x398(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x398(%rbp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x398(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
cmpq $0x0, -0x50(%rbp)
movq -0x88(%rbp), %r15
je 0x6462
movl -0x54(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x50(%rbp), %rax
leaq (,%rax,8), %r14
xorl %eax, %eax
leaq -0x398(%rbp), %r12
leaq 0x30f6(%rip), %r13      # 0x950c
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %r15, -0x88(%rbp)
movsd (%r15), %xmm0
movq %r12, %rdi
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2220
addq %r14, %r15
decq %rbx
jne 0x6425
movq -0x40(%rbp), %rax
incq %rax
movq -0x88(%rbp), %r15
addq $0x8, %r15
cmpq -0x50(%rbp), %rax
jne 0x6416
movq -0x398(%rbp), %rax
leaq -0x398(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x21f0
leaq -0x398(%rbp), %rbx
movsbl %al, %esi
leaq -0x398(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0x398(%rbp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x398(%rbp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq -0x398(%rbp), %r14
movq %r14, %rdi
callq 0x2270
movq 0x6ae7(%rip), %rax      # 0xcfc8
movq (%rax), %rbx
movq 0x18(%rax), %r15
leaq -0x628(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r15, -0x630(%rbp,%rax)
callq 0x21b0
movl $0xf8, %r12d
leaq -0x630(%rbp), %rdi
addq %r12, %rdi
callq 0x20b0
leaq -0x390(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r15, -0x398(%rbp,%rax)
callq 0x21b0
addq %r12, %r14
movq %r14, %rdi
callq 0x20b0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6a78(%rip), %rdi      # 0xcfd0
leaq 0x2db2(%rip), %rsi      # 0x9311
callq 0x2200
movq %rax, %rdi
callq 0x20f0
jmp 0x65c1
movq 0x6a5b(%rip), %rdi      # 0xcfd0
leaq 0x2e23(%rip), %rsi      # 0x939f
jmp 0x65bc
movq 0x6a4b(%rip), %rdi      # 0xcfd0
leaq 0x2e70(%rip), %rsi      # 0x93fc
jmp 0x65bc
movq 0x6a3b(%rip), %rdi      # 0xcfd0
leaq 0x2e95(%rip), %rsi      # 0x9431
jmp 0x65bc
movq 0x6a2b(%rip), %rdi      # 0xcfd0
leaq 0x2eb4(%rip), %rsi      # 0x9460
jmp 0x65bc
movq 0x6a1b(%rip), %rdi      # 0xcfd0
leaq 0x2e15(%rip), %rsi      # 0x93d1
callq 0x2200
movl $0x1, %edi
callq 0x2100
leaq 0x66a6(%rip), %rsi      # 0xcc78
movq %rax, %rdi
xorl %edx, %edx
callq 0x2320
jmp 0x65f9
jmp 0x667b
jmp 0x667b
jmp 0x65f9
movq %rax, %r14
jmp 0x66a2
jmp 0x65f9
jmp 0x667b
movq %rax, %r14
jmp 0x66b3
jmp 0x667b
jmp 0x6659
jmp 0x6648
jmp 0x666a
jmp 0x668e
jmp 0x668e
movq %rax, %r14
movq %r13, %rdi
jmp 0x661e
movq %rax, %r14
movq %rbx, %rdi
callq 0x21e0
jmp 0x6691
jmp 0x668e
jmp 0x667b
jmp 0x667b
jmp 0x667b
jmp 0x667b
jmp 0x6637
jmp 0x6659
jmp 0x668e
jmp 0x668e
movq %rax, %r14
leaq -0x170(%rbp), %rdi
callq 0x4844
jmp 0x664b
movq %rax, %r14
leaq -0x198(%rbp), %rdi
callq 0x4844
jmp 0x665c
movq %rax, %r14
leaq -0x430(%rbp), %rdi
callq 0x4844
jmp 0x666d
movq %rax, %r14
leaq -0x630(%rbp), %rdi
callq 0x4844
jmp 0x6691
movq %rax, %r14
leaq -0x630(%rbp), %rdi
callq 0x2290
jmp 0x66b3
jmp 0x668e
movq %rax, %r14
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x66a2
callq 0x2250
movq -0x148(%rbp), %rdi
testq %rdi, %rdi
je 0x66b3
callq 0x2250
movq 0x690e(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x390(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x398(%rbp,%rcx)
callq 0x21b0
leaq -0x2a0(%rbp), %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x2350