// File: ashlall[P]StreamStats/ChiSquareExperiments/VaryMemoryReal.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc < 6)
  {
    cout << "usage: VaryMemoryReal lower-memory upper-memory filename1 filename2 num_bins\n";
    exit(1);
  }

  double lower = atof(argv[1]), upper = atof(argv[2]);
  char *filename1 = argv[3], *filename2 = argv[4];
  int num_buckets = atoi(argv[5]);

  if (lower <=0 || upper <= 0)
  {
    cout << "The memory must be greater than 0.\n";
    exit(1);
  }
  if (num_buckets <= 0)
  {
    cout << "The number of buckets must be greater than 0.\n";
    exit(1);
  }

  // finds the number of times the experiment will run
  double memory_percent;
  int repeats = 0;
  double mem = lower;
  while (mem <= (upper + 0.0000001)) // accounts for rounding error
  {
    repeats++;
    mem *= sqrt(10);
  }

  double actual_values[repeats];
  double GK_values[repeats];
  double QD_values[repeats];
  double RS_values[repeats];
  double percents[repeats];
  std::vector<double> data1, data2;

  // creates and initializes the log file
  ofstream data_file;
  char str[100];
  name_file(str, argv, 0);
  data_file.open(str);
  ifstream input_file;
  char output[100];
  int stream_size1 = 0, stream_size2 = 0;

  std::default_random_engine generator(1);
  std::uniform_real_distribution<double> distribution(0.0, 1.0);

  input_file.open(filename1);
  while (!input_file.eof())
  {
    input_file >> output;
    data1.push_back(atof(output) + (distribution(generator) * 0.000000001));
    stream_size1++;
  }
  input_file.close();

  input_file.open(filename2);
  while (!input_file.eof())
  {
    input_file >> output;
    data2.push_back(atof(output) + (distribution(generator) * 0.000000001));
    stream_size2++;
  }
  input_file.close();

  data_file << filename1 << endl << filename2 << endl;
  data_file << "num_buckets: " << num_buckets << endl;
  data_file << "stream 1 size: " << stream_size1 << endl;
  data_file << "stream 2 size: " << stream_size2 << endl;
  memory_percent = lower;
  int i = 0;
  while (memory_percent <= (upper + 0.00000001)) //accounts for rounding
  {
    data_file << "memory percent: " << memory_percent << endl;
    percents[i] = memory_percent;
    int sample_size1 = memory_percent * stream_size1;
    int sample_size2 = memory_percent * stream_size2;

    // calculates GK statistic
    ChiSquareContinuous GK_sketch1(sample_size1,1);
    for (std::vector<double>::iterator j = data1.begin(); j != data1.end();j++)
      GK_sketch1.insert(*j);
    ChiSquareContinuous GK_sketch2(sample_size2,1);
    for (std::vector<double>::iterator j = data2.begin(); j != data2.end();j++)
      GK_sketch2.insert(*j);
    
    double GK_stat = GK_sketch1.two_sample_statistic(GK_sketch2, num_buckets);
    GK_values[i] = GK_stat;
    data_file << "GK = " << GK_stat << endl;

    // calculates real statistic
    double *upper_intervals = GK_sketch1.get_upper();
    double *lower_intervals = GK_sketch1.get_lower();
    double constant_1 = sqrt((double)stream_size2/stream_size1);
    double constant_2 = sqrt((double)stream_size1/stream_size2);
    double chi_squared = 0;

    for (int i = 0; i < num_buckets; i++)
    {
      double frequency1 = 0, frequency2 = 0;
      for (std::vector<double>::iterator j = data1.begin(); j!=data1.end();j++)
	{
        if (*j <= upper_intervals[i+1] && *j > lower_intervals[i+1])
          frequency1++;
      }
      for (std::vector<double>::iterator j = data2.begin(); j!=data2.end();j++)
      {
        if (*j <= upper_intervals[i+1] && *j > lower_intervals[i+1])
	  frequency2++;
      }

      double lambda = frequency1 * constant_1 - frequency2 * constant_2;
      chi_squared += (lambda * lambda) / (frequency1 + frequency2);
    }

    actual_values[i] = chi_squared;
    data_file << "actual = " << chi_squared << endl;

    memory_percent *= sqrt(10);
    i++;
  }
  data_file.close();

  // creates pvalue file
  name_file(str, argv, 3);
  data_file.open(str);
  
  // creates table file
  ofstream data2_file;
  name_file(str, argv, 1);
  data2_file.open(str);

  // creates extra file
  ofstream data3_file;
  name_file(str, argv, 2);
  data3_file.open(str);

  int deg_freedom = num_buckets;
  if (stream_size1 != stream_size2)
    deg_freedom--;
  for (int i = 0; i < repeats; i++)
  {
    // adds values to the table
    data2_file << percents[i] * 100 << "\t";
    double error = abs(pochisq(GK_values[i], deg_freedom) - pochisq(actual_values[i], deg_freedom));
    data2_file << error << endl;

    // adds values to pvalue file
    data_file << pochisq(actual_values[i], deg_freedom) << " actual" << endl;
    data_file << pochisq(GK_values[i], deg_freedom) << " GK" << endl;

    // adds values to extra file
    data3_file << percents[i] * 100 << "\t";
    error = abs(GK_values[i] - actual_values[i]) / actual_values[i]; 
    data3_file << error << endl;
  }
  data3_file.close();
  data2_file.close();
  data_file.close();
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc20, %rsp            # imm = 0xC20
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x6, -0x8(%rbp)
jge 0x650c
movq 0x13ada(%rip), %rdi     # 0x19fd0
leaq 0xbd63(%rip), %rsi      # 0x12260
callq 0x21e0
movl $0x1, %edi
callq 0x2220
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2230
movsd %xmm0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2230
movsd %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x22a0
movl %eax, -0x34(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jae 0x656c
xorps %xmm0, %xmm0
ucomisd -0x20(%rbp), %xmm0
jb 0x6589
movq 0x13a5d(%rip), %rdi     # 0x19fd0
leaq 0xbd34(%rip), %rsi      # 0x122ae
callq 0x21e0
movl $0x1, %edi
callq 0x2220
cmpl $0x0, -0x34(%rbp)
jg 0x65ac
movq 0x13a3a(%rip), %rdi     # 0x19fd0
leaq 0xbd35(%rip), %rsi      # 0x122d2
callq 0x21e0
movl $0x1, %edi
callq 0x2220
movl $0x0, -0x44(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm1
movsd 0xbb86(%rip), %xmm0     # 0x12150
addsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x65f4
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0xa, %edi
callq 0x8440
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x65bd
movl -0x44(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xaf8(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xaf0(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xae8(%rbp)
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8460
leaq -0xb0(%rbp), %rdi
callq 0x8460
leaq -0x2b0(%rbp), %rdi
callq 0x22f0
jmp 0x66c2
movq -0x10(%rbp), %rsi
leaq -0x320(%rbp), %rdi
xorl %edx, %edx
callq 0x75e0
jmp 0x66d6
leaq -0x2b0(%rbp), %rdi
leaq -0x320(%rbp), %rsi
movl $0x10, %edx
callq 0x2050
jmp 0x66f0
leaq -0x528(%rbp), %rdi
callq 0x2210
jmp 0x66fe
movl $0x0, -0x594(%rbp)
movl $0x0, -0x598(%rbp)
leaq -0x5a0(%rbp), %rdi
movl $0x1, %esi
callq 0x8480
jmp 0x6725
leaq -0x5b0(%rbp), %rdi
xorps %xmm0, %xmm0
movsd 0xb8d1(%rip), %xmm1     # 0x12008
callq 0x84b0
jmp 0x673e
movq -0x28(%rbp), %rsi
leaq -0x528(%rbp), %rdi
movl $0x8, %edx
callq 0x2120
jmp 0x6755
jmp 0x6757
movq -0x528(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x528(%rbp,%rax), %rdi
callq 0x2370
movb %al, -0xaf9(%rbp)
jmp 0x6777
movb -0xaf9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6788
jmp 0x6864
leaq -0x528(%rbp), %rdi
leaq -0x590(%rbp), %rsi
callq 0x84e0
jmp 0x679d
leaq -0x590(%rbp), %rdi
callq 0x2230
movsd %xmm0, -0xb10(%rbp)
leaq -0x5b0(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x8560
movsd %xmm0, -0xb08(%rbp)
jmp 0x67ce
movsd -0xb10(%rbp), %xmm1
movsd -0xb08(%rbp), %xmm0
movsd 0xb982(%rip), %xmm2     # 0x12168
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x5b8(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x5b8(%rbp), %rsi
callq 0x8530
jmp 0x680b
movl -0x594(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x594(%rbp)
jmp 0x6757
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x75b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x75a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x759c
leaq -0x528(%rbp), %rdi
callq 0x2080
jmp 0x6872
movq -0x30(%rbp), %rsi
leaq -0x528(%rbp), %rdi
movl $0x8, %edx
callq 0x2120
jmp 0x6889
jmp 0x688b
movq -0x528(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x528(%rbp,%rax), %rdi
callq 0x2370
movb %al, -0xb11(%rbp)
jmp 0x68ab
movb -0xb11(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x68bc
jmp 0x6953
leaq -0x528(%rbp), %rdi
leaq -0x590(%rbp), %rsi
callq 0x84e0
jmp 0x68d1
leaq -0x590(%rbp), %rdi
callq 0x2230
movsd %xmm0, -0xb28(%rbp)
leaq -0x5b0(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x8560
movsd %xmm0, -0xb20(%rbp)
jmp 0x6902
movsd -0xb28(%rbp), %xmm1
movsd -0xb20(%rbp), %xmm0
movsd 0xb84e(%rip), %xmm2     # 0x12168
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x5c0(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x5c0(%rbp), %rsi
callq 0x8530
jmp 0x693f
movl -0x598(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x598(%rbp)
jmp 0x688b
leaq -0x528(%rbp), %rdi
callq 0x2080
jmp 0x6961
movq -0x28(%rbp), %rsi
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xb30(%rbp)
jmp 0x697a
movq -0xb30(%rbp), %rdi
movq 0x13638(%rip), %rsi     # 0x19fc0
callq 0x2200
movq %rax, -0xb38(%rbp)
jmp 0x6996
movq -0xb38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x21e0
movq %rax, -0xb40(%rbp)
jmp 0x69af
movq -0xb40(%rbp), %rdi
movq 0x13603(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x69c4
leaq 0xb936(%rip), %rsi      # 0x12301
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xb48(%rbp)
jmp 0x69e0
movq -0xb48(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x2320
movq %rax, -0xb50(%rbp)
jmp 0x69f8
movq -0xb50(%rbp), %rdi
movq 0x135ba(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x6a0d
leaq 0xb8fb(%rip), %rsi      # 0x1230f
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xb58(%rbp)
jmp 0x6a29
movq -0xb58(%rbp), %rdi
movl -0x594(%rbp), %esi
callq 0x2320
movq %rax, -0xb60(%rbp)
jmp 0x6a44
movq -0xb60(%rbp), %rdi
movq 0x1356e(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x6a59
leaq 0xb8bf(%rip), %rsi      # 0x1231f
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xb68(%rbp)
jmp 0x6a75
movq -0xb68(%rbp), %rdi
movl -0x598(%rbp), %esi
callq 0x2320
movq %rax, -0xb70(%rbp)
jmp 0x6a90
movq -0xb70(%rbp), %rdi
movq 0x13522(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x6aa5
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x5c4(%rbp)
movsd -0x40(%rbp), %xmm1
movsd 0xb692(%rip), %xmm0     # 0x12158
addsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x70fc
leaq 0xb853(%rip), %rsi      # 0x1232f
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xb78(%rbp)
jmp 0x6af1
movq -0xb78(%rbp), %rdi
movsd -0x40(%rbp), %xmm0
callq 0x2380
movq %rax, -0xb80(%rbp)
jmp 0x6b0b
movq -0xb80(%rbp), %rdi
movq 0x134a7(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x6b20
movq -0xae8(%rbp), %rax
movsd -0x40(%rbp), %xmm0
movslq -0x5c4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x40(%rbp), %xmm0
cvtsi2sdl -0x594(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x5c8(%rbp)
movsd -0x40(%rbp), %xmm0
cvtsi2sdl -0x598(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x5cc(%rbp)
cvtsi2sdl -0x5c8(%rbp), %xmm0
leaq -0x5f8(%rbp), %rdi
movl $0x1, %esi
callq 0x5280
jmp 0x6b89
leaq -0x98(%rbp), %rdi
callq 0x8590
movq %rax, -0x600(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8600
movq %rax, -0x608(%rbp)
leaq -0x600(%rbp), %rdi
leaq -0x608(%rbp), %rsi
callq 0x85c0
testb $0x1, %al
jne 0x6bc8
jmp 0x6c16
leaq -0x600(%rbp), %rdi
callq 0x8630
movsd (%rax), %xmm0
leaq -0x5f8(%rbp), %rdi
callq 0x54a0
jmp 0x6be6
jmp 0x6be8
leaq -0x600(%rbp), %rdi
xorl %esi, %esi
callq 0x8650
movq %rax, -0x610(%rbp)
jmp 0x6b9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x70eb
cvtsi2sdl -0x5cc(%rbp), %xmm0
leaq -0x638(%rbp), %rdi
movl $0x1, %esi
callq 0x5280
jmp 0x6c31
leaq -0xb0(%rbp), %rdi
callq 0x8590
movq %rax, -0x640(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x8600
movq %rax, -0x648(%rbp)
leaq -0x640(%rbp), %rdi
leaq -0x648(%rbp), %rsi
callq 0x85c0
testb $0x1, %al
jne 0x6c70
jmp 0x6cca
leaq -0x640(%rbp), %rdi
callq 0x8630
movsd (%rax), %xmm0
leaq -0x638(%rbp), %rdi
callq 0x54a0
jmp 0x6c8e
jmp 0x6c90
leaq -0x640(%rbp), %rdi
xorl %esi, %esi
callq 0x8650
movq %rax, -0x650(%rbp)
jmp 0x6c44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
leaq -0x638(%rbp), %rdi
callq 0x5430
jmp 0x70eb
movl -0x34(%rbp), %edx
leaq -0x5f8(%rbp), %rdi
leaq -0x638(%rbp), %rsi
callq 0x6060
movsd %xmm0, -0xb88(%rbp)
jmp 0x6cea
movq -0xaf0(%rbp), %rax
movsd -0xb88(%rbp), %xmm0
movsd %xmm0, -0x658(%rbp)
movsd -0x658(%rbp), %xmm0
movslq -0x5c4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0xb624(%rip), %rsi      # 0x12340
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xb90(%rbp)
jmp 0x6d31
movq -0xb90(%rbp), %rdi
movsd -0x658(%rbp), %xmm0
callq 0x2380
movq %rax, -0xb98(%rbp)
jmp 0x6d4e
movq -0xb98(%rbp), %rdi
movq 0x13264(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x6d63
leaq -0x5f8(%rbp), %rdi
callq 0x63e0
movq %rax, -0x660(%rbp)
leaq -0x5f8(%rbp), %rdi
callq 0x63c0
movq %rax, -0x668(%rbp)
cvtsi2sdl -0x598(%rbp), %xmm0
cvtsi2sdl -0x594(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x2160
movsd %xmm0, -0x670(%rbp)
cvtsi2sdl -0x594(%rbp), %xmm0
cvtsi2sdl -0x598(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x2160
movsd %xmm0, -0x678(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x680(%rbp)
movl $0x0, -0x684(%rbp)
movl -0x684(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x7030
xorps %xmm0, %xmm0
movsd %xmm0, -0x690(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x698(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8590
movq %rax, -0x6a0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8600
movq %rax, -0x6a8(%rbp)
leaq -0x6a0(%rbp), %rdi
leaq -0x6a8(%rbp), %rsi
callq 0x85c0
testb $0x1, %al
jne 0x6e47
jmp 0x6ed3
leaq -0x6a0(%rbp), %rdi
callq 0x8630
movsd (%rax), %xmm1
movq -0x660(%rbp), %rax
movl -0x684(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jb 0x6eb7
leaq -0x6a0(%rbp), %rdi
callq 0x8630
movsd (%rax), %xmm0
movq -0x668(%rbp), %rax
movl -0x684(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x6eb7
movsd 0xb161(%rip), %xmm0     # 0x12008
addsd -0x690(%rbp), %xmm0
movsd %xmm0, -0x690(%rbp)
jmp 0x6eb9
leaq -0x6a0(%rbp), %rdi
xorl %esi, %esi
callq 0x8650
movq %rax, -0x6b0(%rbp)
jmp 0x6e18
leaq -0xb0(%rbp), %rdi
callq 0x8590
movq %rax, -0x6b8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x8600
movq %rax, -0x6c0(%rbp)
leaq -0x6b8(%rbp), %rdi
leaq -0x6c0(%rbp), %rsi
callq 0x85c0
testb $0x1, %al
jne 0x6f15
jmp 0x6fa1
leaq -0x6b8(%rbp), %rdi
callq 0x8630
movsd (%rax), %xmm1
movq -0x660(%rbp), %rax
movl -0x684(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jb 0x6f85
leaq -0x6b8(%rbp), %rdi
callq 0x8630
movsd (%rax), %xmm0
movq -0x668(%rbp), %rax
movl -0x684(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x6f85
movsd 0xb093(%rip), %xmm0     # 0x12008
addsd -0x698(%rbp), %xmm0
movsd %xmm0, -0x698(%rbp)
jmp 0x6f87
leaq -0x6b8(%rbp), %rdi
xorl %esi, %esi
callq 0x8650
movq %rax, -0x6c8(%rbp)
jmp 0x6ee6
movsd -0x690(%rbp), %xmm0
movsd -0x670(%rbp), %xmm2
movsd -0x698(%rbp), %xmm1
mulsd -0x678(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x6d0(%rbp)
movsd -0x6d0(%rbp), %xmm0
mulsd -0x6d0(%rbp), %xmm0
movsd -0x690(%rbp), %xmm1
addsd -0x698(%rbp), %xmm1
divsd %xmm1, %xmm0
addsd -0x680(%rbp), %xmm0
movsd %xmm0, -0x680(%rbp)
movl -0x684(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x684(%rbp)
jmp 0x6de0
movq -0xaf8(%rbp), %rax
movsd -0x680(%rbp), %xmm0
movslq -0x5c4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0xb2f4(%rip), %rsi      # 0x12346
leaq -0x2b0(%rbp), %rdi
callq 0x21e0
movq %rax, -0xba0(%rbp)
jmp 0x7067
movq -0xba0(%rbp), %rdi
movsd -0x680(%rbp), %xmm0
callq 0x2380
movq %rax, -0xba8(%rbp)
jmp 0x7084
movq -0xba8(%rbp), %rdi
movq 0x12f2e(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x7099
movl $0xa, %edi
callq 0x8440
movsd %xmm0, -0xbb0(%rbp)
jmp 0x70ad
movsd -0xbb0(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x5c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c4(%rbp)
leaq -0x638(%rbp), %rdi
callq 0x5430
leaq -0x5f8(%rbp), %rdi
callq 0x5430
jmp 0x6ab9
leaq -0x5f8(%rbp), %rdi
callq 0x5430
jmp 0x759c
leaq -0x2b0(%rbp), %rdi
callq 0x2260
jmp 0x710a
movq -0x10(%rbp), %rsi
leaq -0x320(%rbp), %rdi
movl $0x3, %edx
callq 0x75e0
jmp 0x7121
leaq -0x2b0(%rbp), %rdi
leaq -0x320(%rbp), %rsi
movl $0x10, %edx
callq 0x2050
jmp 0x713b
leaq -0x8d0(%rbp), %rdi
callq 0x22f0
jmp 0x7149
movq -0x10(%rbp), %rsi
leaq -0x320(%rbp), %rdi
movl $0x1, %edx
callq 0x75e0
jmp 0x7160
leaq -0x8d0(%rbp), %rdi
leaq -0x320(%rbp), %rsi
movl $0x10, %edx
callq 0x2050
jmp 0x717a
leaq -0xad0(%rbp), %rdi
callq 0x22f0
jmp 0x7188
movq -0x10(%rbp), %rsi
leaq -0x320(%rbp), %rdi
movl $0x2, %edx
callq 0x75e0
jmp 0x719f
leaq -0xad0(%rbp), %rdi
leaq -0x320(%rbp), %rsi
movl $0x10, %edx
callq 0x2050
jmp 0x71b9
movl -0x34(%rbp), %eax
movl %eax, -0xad4(%rbp)
movl -0x594(%rbp), %eax
cmpl -0x598(%rbp), %eax
je 0x721b
movl -0xad4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xad4(%rbp)
jmp 0x721b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x7590
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x2280
jmp 0x7590
movl $0x0, -0xad8(%rbp)
movl -0xad8(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x7508
movq -0xae8(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0xaf11(%rip), %xmm1     # 0x12160
mulsd %xmm1, %xmm0
leaq -0x8d0(%rbp), %rdi
callq 0x2380
movq %rax, -0xbb8(%rbp)
jmp 0x7268
movq -0xbb8(%rbp), %rdi
leaq 0xb0da(%rip), %rsi      # 0x12350
callq 0x21e0
jmp 0x727d
movq -0xaf0(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xad4(%rbp), %edi
callq 0x4c30
movsd %xmm0, -0xbc0(%rbp)
jmp 0x72a5
movq -0xaf8(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xad4(%rbp), %edi
callq 0x4c30
movsd %xmm0, -0xbc8(%rbp)
jmp 0x72cd
movsd -0xbc8(%rbp), %xmm1
movsd -0xbc0(%rbp), %xmm0
subsd %xmm1, %xmm0
callq 0x83b0
movsd %xmm0, -0xbd0(%rbp)
jmp 0x72f0
movsd -0xbd0(%rbp), %xmm0
movsd %xmm0, -0xae0(%rbp)
movsd -0xae0(%rbp), %xmm0
leaq -0x8d0(%rbp), %rdi
callq 0x2380
movq %rax, -0xbd8(%rbp)
jmp 0x731d
movq -0xbd8(%rbp), %rdi
movq 0x12c95(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x7332
movq -0xaf8(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xad4(%rbp), %edi
callq 0x4c30
movsd %xmm0, -0xbe0(%rbp)
jmp 0x735a
movsd -0xbe0(%rbp), %xmm0
leaq -0x2b0(%rbp), %rdi
callq 0x2380
movq %rax, -0xbe8(%rbp)
jmp 0x7377
movq -0xbe8(%rbp), %rdi
leaq 0xafcd(%rip), %rsi      # 0x12352
callq 0x21e0
movq %rax, -0xbf0(%rbp)
jmp 0x7393
movq -0xbf0(%rbp), %rdi
movq 0x12c1f(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x73a8
movq -0xaf0(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xad4(%rbp), %edi
callq 0x4c30
movsd %xmm0, -0xbf8(%rbp)
jmp 0x73d0
movsd -0xbf8(%rbp), %xmm0
leaq -0x2b0(%rbp), %rdi
callq 0x2380
movq %rax, -0xc00(%rbp)
jmp 0x73ed
movq -0xc00(%rbp), %rdi
leaq 0xaf5f(%rip), %rsi      # 0x1235a
callq 0x21e0
movq %rax, -0xc08(%rbp)
jmp 0x7409
movq -0xc08(%rbp), %rdi
movq 0x12ba9(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x741e
movq -0xae8(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0xad27(%rip), %xmm1     # 0x12160
mulsd %xmm1, %xmm0
leaq -0xad0(%rbp), %rdi
callq 0x2380
movq %rax, -0xc10(%rbp)
jmp 0x7452
movq -0xc10(%rbp), %rdi
leaq 0xaef0(%rip), %rsi      # 0x12350
callq 0x21e0
jmp 0x7467
movq -0xaf8(%rbp), %rax
movq -0xaf0(%rbp), %rdx
movslq -0xad8(%rbp), %rcx
movsd (%rdx,%rcx,8), %xmm0
movsd (%rax,%rcx,8), %xmm1
subsd %xmm1, %xmm0
callq 0x83b0
movsd %xmm0, -0xc18(%rbp)
jmp 0x7499
movsd -0xc18(%rbp), %xmm0
movq -0xaf8(%rbp), %rax
movslq -0xad8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xae0(%rbp)
movsd -0xae0(%rbp), %xmm0
leaq -0xad0(%rbp), %rdi
callq 0x2380
movq %rax, -0xc20(%rbp)
jmp 0x74dd
movq -0xc20(%rbp), %rdi
movq 0x12ad5(%rip), %rsi     # 0x19fc0
callq 0x2200
jmp 0x74f2
jmp 0x74f4
movl -0xad8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xad8(%rbp)
jmp 0x7225
leaq -0xad0(%rbp), %rdi
callq 0x2260
jmp 0x7516
leaq -0x8d0(%rbp), %rdi
callq 0x2260
jmp 0x7524
leaq -0x2b0(%rbp), %rdi
callq 0x2260
jmp 0x7532
movl $0x0, -0x4(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x2280
leaq -0x8d0(%rbp), %rdi
callq 0x2280
leaq -0x528(%rbp), %rdi
callq 0x2090
leaq -0x2b0(%rbp), %rdi
callq 0x2280
leaq -0xb0(%rbp), %rdi
callq 0x8690
leaq -0x98(%rbp), %rdi
callq 0x8690
movq -0x58(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
leaq -0x8d0(%rbp), %rdi
callq 0x2280
leaq -0x528(%rbp), %rdi
callq 0x2090
leaq -0x2b0(%rbp), %rdi
callq 0x2280
leaq -0xb0(%rbp), %rdi
callq 0x8690
leaq -0x98(%rbp), %rdi
callq 0x8690
movq -0x2b8(%rbp), %rdi
callq 0x2340
nopl (%rax,%rax)