// File: ashlall[P]StreamStats/ChiSquareExperiments/VaryMemoryCategorical.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc < 5)
  {
    cout << "usage: VaryMemoryCategorical lower-memory upper-memory filename1 filename2" << endl;
    exit(1);
  }
  
  double lower = atof(argv[1]), upper = atof(argv[2]);
  char *filename1 = argv[3], *filename2 = argv[4];

  double memory_percent, mem = lower;
  int repeats = 0;
  while (mem <= (upper + 0.00000001))
  {
    repeats++;
    mem += 10;
  }

  double actual_values[repeats], estimated_values[repeats], percents[repeats];
  long times[repeats];
  long times2[repeats];
  std::vector<double> data1, data2;
  std::unordered_map<double,int> stream1, stream2;

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

  input_file.open(filename1);
  while (!input_file.eof())
    {
      input_file >> output;
      data1.push_back(atof(output));
      stream_size1++;
      if (stream1.find(atof(output)) == stream1.end())
	stream1.insert(std::make_pair(atof(output),1));
      else
	stream1[atof(output)] += 1;
    }
  input_file.close();

  input_file.open(filename2);
  while (!input_file.eof())
    {
      input_file >> output;
      data2.push_back(atof(output));
      stream_size2++;
      if (stream2.find(atof(output)) == stream2.end())
	stream2.insert(std::make_pair(atof(output),1));
      else
	stream2[atof(output)] += 1;
    }
  input_file.close();

  data_file << filename1 << endl << filename2 << endl;
  data_file << "stream 1 size: " << stream_size1 << endl;
  data_file << "stream 2 size: " << stream_size2 << endl;
  data_file << "number of categories: " << stream1.size() << endl;
  memory_percent = lower;
  int i = 0, num_categories;


  while (memory_percent <= (upper + 0.00000001)) //accounts for rounding
  {
    data_file << "memory percent: " << memory_percent << endl;
    percents[i] = memory_percent;

    // calculates the estimated statistic
    ChiSquareCategorical sketch1(memory_percent);
    ChiSquareCategorical sketch2(memory_percent);

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

    for (std::vector<double>::iterator j = data1.begin(); j != data1.end();j++)
      sketch1.insert(*j);
    for (std::vector<double>::iterator j = data2.begin(); j != data2.end();j++)
      sketch2.insert(*j);

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

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

    double estimated_stat = sketch1.calculate_statistic(sketch2, 0);

    estimated_values[i] = estimated_stat;
    data_file << "estimate = " << estimated_stat << endl;

    // calculates actual statistic
    double constant1 = sqrt(double(stream_size2) / double(stream_size1));
    double constant2 = sqrt(double(stream_size1) / double(stream_size2));
    double actual_stat = 0;

    for (std::unordered_map<double,int>::const_iterator j = stream1.begin(); j!= stream1.end(); j++)
    {
      double frequency1 = j->second;
      double frequency2 = 0;
      num_categories++;
      if (stream2.find(j->first) != stream2.end())
	frequency2 = stream2[j->first];
      double value = frequency1 * constant1 - frequency2 * constant2;
      actual_stat += (value * value) / (frequency1 + frequency2);
    }
    // have to loop through other stream to find when first one is 0
    for (std::unordered_map<double,int>::const_iterator j = stream2.begin(); j!= stream2.end(); j++)
    {
      if (stream1.find(j->first) == stream1.end())
      {
	num_categories++;
	int frequency1 = 0;
	int frequency2 = j->second;
	double value = frequency1 * constant1 - frequency2 * constant2;
	actual_stat += (value * value) / (frequency1 + frequency2);
      }
    }
    actual_values[i] = actual_stat;
    data_file << "actual = " << actual_stat << endl;
    i++;
    memory_percent += 10;
  }
  data_file.close();

  // creates pvalues 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 time table file
  ofstream time_file;
  char str2[150];
  name_file(str2, argv, 5);
  time_file.open(str2);

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

  int deg_freedom = num_categories - 1;
  for (int i = 0; i < repeats; i++)
    {
      // adds values to the table
      data2_file << percents[i] << "\t";
      double error = abs(pochisq(estimated_values[i], deg_freedom) - pochisq(actual_values[i], deg_freedom));
      data2_file << error << endl;

	  // adds values to the time table
	  time_file << percents[i] << "\t";
      long double avg_time = times[i] + times2[i]/1000000.0;
      time_file << avg_time << endl;
	  
      // adds values to pvalue file
      data_file << pochisq(actual_values[i], deg_freedom) << " actual" << endl;
      data_file << pochisq(estimated_values[i], deg_freedom) << " estimated" << endl;

      // adds values to extra file
      data3_file << percents[i] << "\t";
      error = abs(estimated_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 $0x1140, %rsp           # imm = 0x1140
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x8(%rbp)
jge 0x364b
movq 0xb9b2(%rip), %rdi      # 0xefd8
leaq 0x6ba2(%rip), %rsi      # 0xa1cf
callq 0x21a0
movq %rax, %rdi
movq 0xb98c(%rip), %rsi      # 0xefc8
callq 0x21c0
movl $0x1, %edi
callq 0x21f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2200
movsd %xmm0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2200
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)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movsd -0x40(%rbp), %xmm1
movsd 0x6a7b(%rip), %xmm0     # 0xa120
addsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x36cd
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movsd 0x6a6f(%rip), %xmm0     # 0xa130
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x3698
movl -0x44(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x50(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xfa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xf98(%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, -0xf90(%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, -0xf88(%rbp)
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, -0xf80(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x50c0
leaq -0xa8(%rbp), %rdi
callq 0x50c0
leaq -0xe0(%rbp), %rdi
callq 0x50e0
leaq -0x118(%rbp), %rdi
callq 0x50e0
leaq -0x318(%rbp), %rdi
callq 0x22a0
jmp 0x37c1
movq -0x10(%rbp), %rsi
leaq -0x390(%rbp), %rdi
xorl %edx, %edx
callq 0x4b00
jmp 0x37d5
leaq -0x318(%rbp), %rdi
leaq -0x390(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x37ef
leaq -0x598(%rbp), %rdi
callq 0x21d0
jmp 0x37fd
movl $0x0, -0x604(%rbp)
movl $0x0, -0x608(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x598(%rbp), %rdi
movl $0x8, %edx
callq 0x20e0
jmp 0x3828
jmp 0x382a
movq -0x598(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x598(%rbp,%rax), %rdi
callq 0x2310
movb %al, -0xfa1(%rbp)
jmp 0x384a
movb -0xfa1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x385b
jmp 0x3a54
leaq -0x598(%rbp), %rdi
leaq -0x600(%rbp), %rsi
callq 0x5100
jmp 0x3870
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x610(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x610(%rbp), %rsi
callq 0x5150
jmp 0x3899
movl -0x604(%rbp), %eax
incl %eax
movl %eax, -0x604(%rbp)
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x620(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x620(%rbp), %rsi
callq 0x51b0
movq %rax, -0xfb0(%rbp)
jmp 0x38d7
movq -0xfb0(%rbp), %rax
movq %rax, -0x618(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x51e0
movq %rax, -0x628(%rbp)
leaq -0x618(%rbp), %rdi
leaq -0x628(%rbp), %rsi
callq 0x5180
testb $0x1, %al
jne 0x3914
jmp 0x3a11
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x640(%rbp)
movl $0x1, -0x644(%rbp)
leaq -0x640(%rbp), %rdi
leaq -0x644(%rbp), %rsi
callq 0x5250
movl %eax, -0xfbc(%rbp)
movsd %xmm0, -0xfb8(%rbp)
jmp 0x3955
movl -0xfbc(%rbp), %eax
movsd -0xfb8(%rbp), %xmm0
movsd %xmm0, -0x658(%rbp)
movl %eax, -0x650(%rbp)
movl -0x650(%rbp), %eax
movl %eax, -0x630(%rbp)
movq -0x658(%rbp), %rax
movq %rax, -0x638(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x638(%rbp), %rsi
callq 0x5210
movb %dl, -0xfc9(%rbp)
movq %rax, -0xfc8(%rbp)
jmp 0x39ad
movb -0xfc9(%rbp), %al
movq -0xfc8(%rbp), %rcx
movq %rcx, -0x668(%rbp)
movb %al, -0x660(%rbp)
jmp 0x3a4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
jmp 0x4ac2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
jmp 0x4ab6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
jmp 0x4aaa
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x670(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x670(%rbp), %rsi
callq 0x5280
movq %rax, -0xfd8(%rbp)
jmp 0x3a41
movq -0xfd8(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x382a
leaq -0x598(%rbp), %rdi
callq 0x2060
jmp 0x3a62
movq -0x30(%rbp), %rsi
leaq -0x598(%rbp), %rdi
movl $0x8, %edx
callq 0x20e0
jmp 0x3a79
jmp 0x3a7b
movq -0x598(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x598(%rbp,%rax), %rdi
callq 0x2310
movb %al, -0xfd9(%rbp)
jmp 0x3a9b
movb -0xfd9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3aac
jmp 0x3c5d
leaq -0x598(%rbp), %rdi
leaq -0x600(%rbp), %rsi
callq 0x5100
jmp 0x3ac1
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x678(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x678(%rbp), %rsi
callq 0x5150
jmp 0x3aea
movl -0x608(%rbp), %eax
incl %eax
movl %eax, -0x608(%rbp)
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x688(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x688(%rbp), %rsi
callq 0x51b0
movq %rax, -0xfe8(%rbp)
jmp 0x3b28
movq -0xfe8(%rbp), %rax
movq %rax, -0x680(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x51e0
movq %rax, -0x690(%rbp)
leaq -0x680(%rbp), %rdi
leaq -0x690(%rbp), %rsi
callq 0x5180
testb $0x1, %al
jne 0x3b65
jmp 0x3c1a
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x6a8(%rbp)
movl $0x1, -0x6ac(%rbp)
leaq -0x6a8(%rbp), %rdi
leaq -0x6ac(%rbp), %rsi
callq 0x5250
movl %eax, -0xff4(%rbp)
movsd %xmm0, -0xff0(%rbp)
jmp 0x3ba6
movl -0xff4(%rbp), %eax
movsd -0xff0(%rbp), %xmm0
movsd %xmm0, -0x6c0(%rbp)
movl %eax, -0x6b8(%rbp)
movl -0x6b8(%rbp), %eax
movl %eax, -0x698(%rbp)
movq -0x6c0(%rbp), %rax
movq %rax, -0x6a0(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x6a0(%rbp), %rsi
callq 0x5210
movb %dl, -0x1001(%rbp)
movq %rax, -0x1000(%rbp)
jmp 0x3bfe
movb -0x1001(%rbp), %al
movq -0x1000(%rbp), %rcx
movq %rcx, -0x6d0(%rbp)
movb %al, -0x6c8(%rbp)
jmp 0x3c58
leaq -0x600(%rbp), %rdi
callq 0x2200
movsd %xmm0, -0x6d8(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x6d8(%rbp), %rsi
callq 0x5280
movq %rax, -0x1010(%rbp)
jmp 0x3c4a
movq -0x1010(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3a7b
leaq -0x598(%rbp), %rdi
callq 0x2060
jmp 0x3c6b
movq -0x28(%rbp), %rsi
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x1018(%rbp)
jmp 0x3c84
movq -0x1018(%rbp), %rdi
movq 0xb336(%rip), %rsi      # 0xefc8
callq 0x21c0
movq %rax, -0x1020(%rbp)
jmp 0x3ca0
movq -0x1020(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x21a0
movq %rax, -0x1028(%rbp)
jmp 0x3cb9
movq -0x1028(%rbp), %rdi
movq 0xb301(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x3cce
leaq 0x6545(%rip), %rsi      # 0xa21a
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x1030(%rbp)
jmp 0x3cea
movq -0x1030(%rbp), %rdi
movl -0x604(%rbp), %esi
callq 0x22c0
movq %rax, -0x1038(%rbp)
jmp 0x3d05
movq -0x1038(%rbp), %rdi
movq 0xb2b5(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x3d1a
leaq 0x6509(%rip), %rsi      # 0xa22a
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x1040(%rbp)
jmp 0x3d36
movq -0x1040(%rbp), %rdi
movl -0x608(%rbp), %esi
callq 0x22c0
movq %rax, -0x1048(%rbp)
jmp 0x3d51
movq -0x1048(%rbp), %rdi
movq 0xb269(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x3d66
leaq 0x64cd(%rip), %rsi      # 0xa23a
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x1050(%rbp)
jmp 0x3d82
leaq -0xe0(%rbp), %rdi
callq 0x52b0
movq -0x1050(%rbp), %rdi
movq %rax, %rsi
callq 0x2070
movq %rax, -0x1058(%rbp)
jmp 0x3da6
movq -0x1058(%rbp), %rdi
movq 0xb214(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x3dbb
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x6dc(%rbp)
movsd -0x38(%rbp), %xmm1
movsd 0x6344(%rip), %xmm0     # 0xa120
addsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x44f6
leaq 0x645f(%rip), %rsi      # 0xa251
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x1060(%rbp)
jmp 0x3e07
movq -0x1060(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
callq 0x2320
movq %rax, -0x1068(%rbp)
jmp 0x3e21
movq -0x1068(%rbp), %rdi
movq 0xb199(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x3e36
movq -0xf90(%rbp), %rax
movsd -0x38(%rbp), %xmm0
movslq -0x6dc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x38(%rbp), %xmm0
leaq -0x748(%rbp), %rdi
callq 0x24d0
jmp 0x3e61
movsd -0x38(%rbp), %xmm0
leaq -0x7b0(%rbp), %rdi
callq 0x24d0
jmp 0x3e74
leaq -0x7c0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2270
leaq -0x90(%rbp), %rdi
callq 0x52d0
movq %rax, -0x7e8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5340
movq %rax, -0x7f0(%rbp)
leaq -0x7e8(%rbp), %rdi
leaq -0x7f0(%rbp), %rsi
callq 0x5300
testb $0x1, %al
jne 0x3ec3
jmp 0x3f34
leaq -0x7e8(%rbp), %rdi
callq 0x5370
movsd (%rax), %xmm0
leaq -0x748(%rbp), %rdi
callq 0x2570
jmp 0x3ee1
jmp 0x3ee3
leaq -0x7e8(%rbp), %rdi
xorl %esi, %esi
callq 0x5390
movq %rax, -0x7f8(%rbp)
jmp 0x3e97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
jmp 0x44e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
leaq -0x7b0(%rbp), %rdi
callq 0x54f0
jmp 0x44e5
leaq -0xa8(%rbp), %rdi
callq 0x52d0
movq %rax, -0x800(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5340
movq %rax, -0x808(%rbp)
leaq -0x800(%rbp), %rdi
leaq -0x808(%rbp), %rsi
callq 0x5300
testb $0x1, %al
jne 0x3f73
jmp 0x3faa
leaq -0x800(%rbp), %rdi
callq 0x5370
movsd (%rax), %xmm0
leaq -0x7b0(%rbp), %rdi
callq 0x2570
jmp 0x3f91
jmp 0x3f93
leaq -0x800(%rbp), %rdi
xorl %esi, %esi
callq 0x5390
movq %rax, -0x810(%rbp)
jmp 0x3f47
xorl %eax, %eax
movl %eax, -0x1074(%rbp)
movl %eax, %esi
leaq -0x7d0(%rbp), %rdi
callq 0x2270
movq -0xf88(%rbp), %rcx
movl -0x1074(%rbp), %edx
movq -0xf80(%rbp), %rax
movq -0x7d0(%rbp), %rsi
movq -0x7c0(%rbp), %rdi
subq %rdi, %rsi
movq %rsi, -0x7d8(%rbp)
movq -0x7c8(%rbp), %rsi
movq -0x7b8(%rbp), %rdi
subq %rdi, %rsi
movq %rsi, -0x7e0(%rbp)
movq -0x7d8(%rbp), %rdi
movslq -0x6dc(%rbp), %rsi
movq %rdi, (%rcx,%rsi,8)
movq -0x7e0(%rbp), %rsi
movslq -0x6dc(%rbp), %rcx
movq %rsi, (%rax,%rcx,8)
leaq -0x748(%rbp), %rdi
leaq -0x7b0(%rbp), %rsi
callq 0x2680
movsd %xmm0, -0x1070(%rbp)
jmp 0x4045
movq -0xf98(%rbp), %rax
movsd -0x1070(%rbp), %xmm0
movsd %xmm0, -0x818(%rbp)
movsd -0x818(%rbp), %xmm0
movslq -0x6dc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0x61eb(%rip), %rsi      # 0xa262
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x1080(%rbp)
jmp 0x408c
movq -0x1080(%rbp), %rdi
movsd -0x818(%rbp), %xmm0
callq 0x2320
movq %rax, -0x1088(%rbp)
jmp 0x40a9
movq -0x1088(%rbp), %rdi
movq 0xaf11(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x40be
cvtsi2sdl -0x608(%rbp), %xmm0
cvtsi2sdl -0x604(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x2110
movsd %xmm0, -0x820(%rbp)
cvtsi2sdl -0x604(%rbp), %xmm0
cvtsi2sdl -0x608(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x2110
movsd %xmm0, -0x828(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x830(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x53d0
movq %rax, -0x840(%rbp)
leaq -0x838(%rbp), %rdi
leaq -0x840(%rbp), %rsi
callq 0x5400
leaq -0xe0(%rbp), %rdi
callq 0x51e0
movq %rax, -0x848(%rbp)
leaq -0x838(%rbp), %rdi
leaq -0x848(%rbp), %rsi
callq 0x5430
testb $0x1, %al
jne 0x4160
jmp 0x42c3
leaq -0x838(%rbp), %rdi
movq %rdi, -0x1098(%rbp)
callq 0x5460
movq -0x1098(%rbp), %rdi
cvtsi2sdl 0x8(%rax), %xmm0
movsd %xmm0, -0x850(%rbp)
movq $0x0, -0x858(%rbp)
movl -0x6e0(%rbp), %eax
incl %eax
movl %eax, -0x6e0(%rbp)
callq 0x5460
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x51b0
movq %rax, -0x1090(%rbp)
jmp 0x41bd
movq -0x1090(%rbp), %rax
movq %rax, -0x860(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x51e0
movq %rax, -0x868(%rbp)
leaq -0x860(%rbp), %rdi
leaq -0x868(%rbp), %rsi
callq 0x5430
testb $0x1, %al
jne 0x41f7
jmp 0x422e
leaq -0x838(%rbp), %rdi
callq 0x5460
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x5490
movq %rax, -0x10a0(%rbp)
jmp 0x421b
movq -0x10a0(%rbp), %rax
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0x858(%rbp)
movsd -0x850(%rbp), %xmm0
movsd -0x820(%rbp), %xmm2
movsd -0x858(%rbp), %xmm1
mulsd -0x828(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x870(%rbp)
movsd -0x870(%rbp), %xmm0
mulsd -0x870(%rbp), %xmm0
movsd -0x850(%rbp), %xmm1
addsd -0x858(%rbp), %xmm1
divsd %xmm1, %xmm0
addsd -0x830(%rbp), %xmm0
movsd %xmm0, -0x830(%rbp)
leaq -0x838(%rbp), %rdi
xorl %esi, %esi
callq 0x54c0
movq %rax, -0x878(%rbp)
jmp 0x4131
leaq -0x118(%rbp), %rdi
callq 0x53d0
movq %rax, -0x888(%rbp)
leaq -0x880(%rbp), %rdi
leaq -0x888(%rbp), %rsi
callq 0x5400
leaq -0x118(%rbp), %rdi
callq 0x51e0
movq %rax, -0x890(%rbp)
leaq -0x880(%rbp), %rdi
leaq -0x890(%rbp), %rsi
callq 0x5430
testb $0x1, %al
jne 0x4318
jmp 0x443e
leaq -0x880(%rbp), %rdi
callq 0x5460
movq %rax, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x51b0
movq %rax, -0x10a8(%rbp)
jmp 0x433c
movq -0x10a8(%rbp), %rax
movq %rax, -0x898(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x51e0
movq %rax, -0x8a0(%rbp)
leaq -0x898(%rbp), %rdi
leaq -0x8a0(%rbp), %rsi
callq 0x5180
testb $0x1, %al
jne 0x4379
jmp 0x4422
movl -0x6e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6e0(%rbp)
movl $0x0, -0x8a4(%rbp)
leaq -0x880(%rbp), %rdi
callq 0x5460
movl 0x8(%rax), %eax
movl %eax, -0x8a8(%rbp)
cvtsi2sdl -0x8a4(%rbp), %xmm0
movsd -0x820(%rbp), %xmm2
cvtsi2sdl -0x8a8(%rbp), %xmm1
mulsd -0x828(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x8b0(%rbp)
movsd -0x8b0(%rbp), %xmm0
mulsd -0x8b0(%rbp), %xmm0
movl -0x8a4(%rbp), %eax
addl -0x8a8(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
addsd -0x830(%rbp), %xmm0
movsd %xmm0, -0x830(%rbp)
jmp 0x4424
leaq -0x880(%rbp), %rdi
xorl %esi, %esi
callq 0x54c0
movq %rax, -0x8b8(%rbp)
jmp 0x42e9
movq -0xfa0(%rbp), %rax
movsd -0x830(%rbp), %xmm0
movslq -0x6dc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0x5e0e(%rip), %rsi      # 0xa26e
leaq -0x318(%rbp), %rdi
callq 0x21a0
movq %rax, -0x10b0(%rbp)
jmp 0x4475
movq -0x10b0(%rbp), %rdi
movsd -0x830(%rbp), %xmm0
callq 0x2320
movq %rax, -0x10b8(%rbp)
jmp 0x4492
movq -0x10b8(%rbp), %rdi
movq 0xab28(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x44a7
movl -0x6dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6dc(%rbp)
movsd 0x5c72(%rip), %xmm0     # 0xa130
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x7b0(%rbp), %rdi
callq 0x54f0
leaq -0x748(%rbp), %rdi
callq 0x54f0
jmp 0x3dcf
leaq -0x748(%rbp), %rdi
callq 0x54f0
jmp 0x4aaa
leaq -0x318(%rbp), %rdi
callq 0x2220
jmp 0x4504
movq -0x10(%rbp), %rsi
leaq -0x390(%rbp), %rdi
movl $0x3, %edx
callq 0x4b00
jmp 0x451b
leaq -0x318(%rbp), %rdi
leaq -0x390(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x4535
leaq -0xab8(%rbp), %rdi
callq 0x22a0
jmp 0x4543
movq -0x10(%rbp), %rsi
leaq -0x390(%rbp), %rdi
movl $0x1, %edx
callq 0x4b00
jmp 0x455a
leaq -0xab8(%rbp), %rdi
leaq -0x390(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x4574
leaq -0xcb8(%rbp), %rdi
callq 0x22a0
jmp 0x4582
movq -0x10(%rbp), %rsi
leaq -0xd50(%rbp), %rdi
movl $0x5, %edx
callq 0x4b00
jmp 0x4599
leaq -0xcb8(%rbp), %rdi
leaq -0xd50(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x45b3
leaq -0xf50(%rbp), %rdi
callq 0x22a0
jmp 0x45c1
movq -0x10(%rbp), %rsi
leaq -0x390(%rbp), %rdi
movl $0x2, %edx
callq 0x4b00
jmp 0x45d8
leaq -0xf50(%rbp), %rdi
leaq -0x390(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x45f2
movl -0x6e0(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xf54(%rbp)
movl $0x0, -0xf58(%rbp)
movl -0xf58(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x49e6
movq -0xf90(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0xab8(%rbp), %rdi
callq 0x2320
movq %rax, -0x10c0(%rbp)
jmp 0x4642
movq -0x10c0(%rbp), %rdi
leaq 0x5c28(%rip), %rsi      # 0xa278
callq 0x21a0
jmp 0x4657
movq -0xf98(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xf54(%rbp), %edi
callq 0x2fb0
movsd %xmm0, -0x10c8(%rbp)
jmp 0x467f
movq -0xfa0(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xf54(%rbp), %edi
callq 0x2fb0
movsd %xmm0, -0x10d0(%rbp)
jmp 0x46a7
movsd -0x10d0(%rbp), %xmm1
movsd -0x10c8(%rbp), %xmm0
subsd %xmm1, %xmm0
callq 0x50a0
movsd %xmm0, -0x10d8(%rbp)
jmp 0x46ca
movsd -0x10d8(%rbp), %xmm0
movsd %xmm0, -0xf60(%rbp)
movsd -0xf60(%rbp), %xmm0
leaq -0xab8(%rbp), %rdi
callq 0x2320
movq %rax, -0x10e0(%rbp)
jmp 0x46f7
movq -0x10e0(%rbp), %rdi
movq 0xa8c3(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x470c
movq -0xf90(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0xcb8(%rbp), %rdi
callq 0x2320
movq %rax, -0x10e8(%rbp)
jmp 0x4734
movq -0x10e8(%rbp), %rdi
leaq 0x5b36(%rip), %rsi      # 0xa278
callq 0x21a0
jmp 0x4749
movq -0xf80(%rbp), %rax
movq -0xf88(%rbp), %rdx
movslq -0xf58(%rbp), %rcx
cvtsi2sdq (%rdx,%rcx,8), %xmm0
cvtsi2sdq (%rax,%rcx,8), %xmm1
movsd 0x59b6(%rip), %xmm2     # 0xa128
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0xf78(%rbp)
fldl -0xf78(%rbp)
fstpt -0xf70(%rbp)
fldt -0xf70(%rbp)
subq $0x10, %rsp
movq %rsp, %rax
fstpt (%rax)
leaq -0xcb8(%rbp), %rdi
callq 0x21e0
addq $0x10, %rsp
movq %rax, -0x10f0(%rbp)
jmp 0x47b6
movq -0x10f0(%rbp), %rdi
movq 0xa804(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x47cb
movq -0xfa0(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xf54(%rbp), %edi
callq 0x2fb0
movsd %xmm0, -0x10f8(%rbp)
jmp 0x47f3
movsd -0x10f8(%rbp), %xmm0
leaq -0x318(%rbp), %rdi
callq 0x2320
movq %rax, -0x1100(%rbp)
jmp 0x4810
movq -0x1100(%rbp), %rdi
leaq 0x5a5c(%rip), %rsi      # 0xa27a
callq 0x21a0
movq %rax, -0x1108(%rbp)
jmp 0x482c
movq -0x1108(%rbp), %rdi
movq 0xa78e(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x4841
movq -0xf98(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl -0xf54(%rbp), %edi
callq 0x2fb0
movsd %xmm0, -0x1110(%rbp)
jmp 0x4869
movsd -0x1110(%rbp), %xmm0
leaq -0x318(%rbp), %rdi
callq 0x2320
movq %rax, -0x1118(%rbp)
jmp 0x4886
movq -0x1118(%rbp), %rdi
leaq 0x59ee(%rip), %rsi      # 0xa282
callq 0x21a0
movq %rax, -0x1120(%rbp)
jmp 0x48a2
movq -0x1120(%rbp), %rdi
movq 0xa718(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x48b7
movq -0xf90(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0xf50(%rbp), %rdi
callq 0x2320
movq %rax, -0x1128(%rbp)
jmp 0x48df
movq -0x1128(%rbp), %rdi
leaq 0x598b(%rip), %rsi      # 0xa278
callq 0x21a0
jmp 0x48f4
movq -0xfa0(%rbp), %rax
movq -0xf98(%rbp), %rdx
movslq -0xf58(%rbp), %rcx
movsd (%rdx,%rcx,8), %xmm0
movsd (%rax,%rcx,8), %xmm1
subsd %xmm1, %xmm0
callq 0x50a0
movsd %xmm0, -0x1130(%rbp)
jmp 0x4926
movsd -0x1130(%rbp), %xmm0
movq -0xfa0(%rbp), %rax
movslq -0xf58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xf60(%rbp)
movsd -0xf60(%rbp), %xmm0
leaq -0xf50(%rbp), %rdi
callq 0x2320
movq %rax, -0x1138(%rbp)
jmp 0x496a
movq -0x1138(%rbp), %rdi
movq 0xa650(%rip), %rsi      # 0xefc8
callq 0x21c0
jmp 0x497f
jmp 0x4981
movl -0xf58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf58(%rbp)
jmp 0x460b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
jmp 0x4a9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
jmp 0x4a92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x320(%rbp)
movl %eax, -0x324(%rbp)
leaq -0xf50(%rbp), %rdi
callq 0x2250
jmp 0x4a92
leaq -0xf50(%rbp), %rdi
callq 0x2220
jmp 0x49f4
leaq -0xab8(%rbp), %rdi
callq 0x2220
jmp 0x4a02
leaq -0x318(%rbp), %rdi
callq 0x2220
jmp 0x4a10
movl $0x0, -0x4(%rbp)
leaq -0xf50(%rbp), %rdi
callq 0x2250
leaq -0xcb8(%rbp), %rdi
callq 0x2250
leaq -0xab8(%rbp), %rdi
callq 0x2250
leaq -0x598(%rbp), %rdi
callq 0x2080
leaq -0x318(%rbp), %rdi
callq 0x2250
leaq -0x118(%rbp), %rdi
callq 0x5510
leaq -0xe0(%rbp), %rdi
callq 0x5510
leaq -0xa8(%rbp), %rdi
callq 0x5530
leaq -0x90(%rbp), %rdi
callq 0x5530
movq -0x50(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
leaq -0xcb8(%rbp), %rdi
callq 0x2250
leaq -0xab8(%rbp), %rdi
callq 0x2250
leaq -0x598(%rbp), %rdi
callq 0x2080
leaq -0x318(%rbp), %rdi
callq 0x2250
leaq -0x118(%rbp), %rdi
callq 0x5510
leaq -0xe0(%rbp), %rdi
callq 0x5510
leaq -0xa8(%rbp), %rdi
callq 0x5530
leaq -0x90(%rbp), %rdi
callq 0x5530
movq -0x320(%rbp), %rdi
callq 0x22e0
nop