// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xcd8, %rsp            # imm = 0xCD8
cmpl $0x4, %edi
jle 0x4048
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x2250
movsd %xmm0, -0x38(%rbp)
movq 0x10(%r14), %rdi
callq 0x2250
addsd 0x2083(%rip), %xmm0     # 0x5130
xorl %eax, %eax
ucomisd -0x38(%rbp), %xmm0
jb 0x30d1
xorl %eax, %eax
movsd 0x2078(%rip), %xmm2     # 0x5138
movsd -0x38(%rbp), %xmm1
incl %eax
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jae 0x30c5
movsd %xmm0, -0xa8(%rbp)
movq 0x18(%r14), %r12
movq 0x20(%r14), %r15
movl %eax, -0x54(%rbp)
movl %eax, %eax
movq %rsp, %rcx
movq %rax, -0x100(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xd8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xe0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xd0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc8(%rbp)
movq %rcx, %rsp
xorl %eax, %eax
movq %rax, -0x80(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movq %rax, -0x60(%rbp)
movapd %xmm0, -0x70(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, -0x10(%rax)
movupd %xmm0, -0x8(%rax)
leaq -0x148(%rbp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movupd %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movupd %xmm0, -0x8(%rax)
leaq -0x780(%rbp), %rdi
callq 0x2310
leaq -0x9f0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x415b
leaq -0x780(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0x580(%rbp), %rdi
callq 0x2220
movq %r14, -0xe8(%rbp)
leaq -0x580(%rbp), %rdi
movq %r12, -0x50(%rbp)
movq %r12, %rsi
movl $0x8, %edx
callq 0x2120
movq %r15, -0x40(%rbp)
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
movl $0x0, -0x30(%rbp)
testb $0x2, -0x560(%rbp,%rax)
jne 0x3387
movl $0x0, -0x30(%rbp)
leaq -0xb00(%rbp), %r14
leaq -0x378(%rbp), %r13
leaq -0x140(%rbp), %r12
movq -0x570(%rbp,%rax), %rbx
movl $0x64, %edx
leaq -0x580(%rbp), %rdi
movq %r14, %rsi
callq 0x2320
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x560(%rbp,%rax)
jne 0x3296
addq $-0x65, %rbx
cmpq $-0x65, %rbx
ja 0x3296
movq -0x498(%rbp,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x3352
movq %r14, %rdi
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movq -0x88(%rbp), %rsi
cmpq -0x80(%rbp), %rsi
je 0x32c4
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x88(%rbp)
jmp 0x32d3
leaq -0x90(%rbp), %rdi
movq %r13, %rdx
callq 0x47be
movq %r14, %rdi
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x48fa
movq %r14, %rdi
testq %rax, %rax
je 0x3312
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4d0c
incl (%rax)
jmp 0x3334
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movl $0x1, -0x370(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x49f6
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
incl -0x30(%rbp)
testb $0x2, -0x560(%rbp,%rax)
je 0x3245
jmp 0x3387
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x3296
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x580, %rdi           # imm = 0xFA80
movl 0x20(%rdi), %esi
orl $0x2, %esi
callq 0x2300
jmp 0x3296
leaq -0x580(%rbp), %rdi
callq 0x2070
movq -0x40(%rbp), %rsi
leaq -0x580(%rbp), %rdi
movl $0x8, %edx
callq 0x2120
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x2, -0x560(%rbp,%rax)
jne 0x3512
xorl %ebx, %ebx
leaq -0xb00(%rbp), %r12
leaq -0x378(%rbp), %r13
leaq -0x178(%rbp), %r15
movq -0x570(%rbp,%rax), %r14
movl $0x64, %edx
leaq -0x580(%rbp), %rdi
movq %r12, %rsi
callq 0x2320
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x560(%rbp,%rax)
jne 0x342b
addq $-0x65, %r14
cmpq $-0x65, %r14
ja 0x342b
movq -0x498(%rbp,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x34dd
movq %r12, %rdi
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movq -0x68(%rbp), %rsi
cmpq -0x60(%rbp), %rsi
je 0x3453
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x68(%rbp)
jmp 0x345f
leaq -0x70(%rbp), %rdi
movq %r13, %rdx
callq 0x47be
movq %r12, %rdi
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x48fa
movq %r12, %rdi
testq %rax, %rax
je 0x349e
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x4d0c
incl (%rax)
jmp 0x34c0
callq 0x2250
movsd %xmm0, -0x378(%rbp)
movl $0x1, -0x370(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x49f6
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
incl %ebx
testb $0x2, -0x560(%rbp,%rax)
je 0x33da
jmp 0x3512
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x342b
movq -0x580(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x580, %rdi           # imm = 0xFA80
movl 0x20(%rdi), %esi
orl $0x2, %esi
callq 0x2300
jmp 0x342b
leaq -0x580(%rbp), %rdi
callq 0x2070
movq -0x40(%rbp), %r12
movq -0x50(%rbp), %r14
testq %r14, %r14
je 0x3547
movq %r14, %rdi
callq 0x20d0
leaq -0x780(%rbp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2230
jmp 0x3568
movq -0x780(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x780, %rdi           # imm = 0xF880
movl 0x20(%rdi), %esi
orl $0x1, %esi
callq 0x2300
movq -0x780(%rbp), %rax
leaq -0x780(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x780(%rbp), %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq %rax, %r14
testq %r12, %r12
je 0x35bb
movq %r12, %rdi
callq 0x20d0
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2230
jmp 0x35d5
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2300
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
leaq 0x1c93(%rip), %rsi      # 0x5296
leaq -0x780(%rbp), %rdi
movl $0xf, %edx
callq 0x2230
leaq -0x780(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x2330
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
leaq 0x1c52(%rip), %rsi      # 0x52a6
leaq -0x780(%rbp), %rdi
movl $0xf, %edx
callq 0x2230
leaq -0x780(%rbp), %rdi
movl %ebx, %esi
callq 0x2330
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
leaq 0x1c12(%rip), %rsi      # 0x52b6
leaq -0x780(%rbp), %rdi
movl $0x16, %edx
callq 0x2230
movq -0x128(%rbp), %rsi
leaq -0x780(%rbp), %rdi
callq 0x2130
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movsd -0xa8(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jb 0x3b9c
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
divsd %xmm0, %xmm1
leaq -0x780(%rbp), %r12
movsd %xmm2, -0xb0(%rbp)
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd %xmm1, -0xb8(%rbp)
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
leaq -0x178(%rbp), %r15
xorl %ebx, %ebx
movl $0x10, %edx
movq %r12, %rdi
leaq 0x1b63(%rip), %rsi      # 0x52cd
callq 0x2230
movq %r12, %rdi
movsd -0x38(%rbp), %xmm0
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 0x2030
movq %rax, %rdi
callq 0x2140
movq -0xe0(%rbp), %rax
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
xorl %edx, %edx
movq %rdx, -0x350(%rbp)
leaq -0x318(%rbp), %rax
movq %rax, -0x348(%rbp)
movl $0x1, %esi
movq %rsi, -0x340(%rbp)
leaq -0x348(%rbp), %rax
xorpd %xmm1, %xmm1
movupd %xmm1, 0x10(%rax)
movl $0x3f800000, %edi       # imm = 0x3F800000
movl %edi, -0x328(%rbp)
movupd %xmm1, 0x28(%rax)
movq %rdx, -0x378(%rbp)
movq %rdx, -0x358(%rbp)
movsd %xmm0, -0x368(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rcx, -0x350(%rbp)
movq %rdx, -0x958(%rbp)
leaq -0x920(%rbp), %rax
movq %rax, -0x950(%rbp)
movq %rsi, -0x948(%rbp)
leaq -0x950(%rbp), %rax
movupd %xmm1, 0x10(%rax)
movl %edi, -0x930(%rbp)
movupd %xmm1, 0x28(%rax)
movq %rdx, -0x980(%rbp)
movq %rdx, -0x960(%rbp)
movsd %xmm0, -0x970(%rbp)
movq %rcx, -0x958(%rbp)
leaq -0xd00(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movq -0x90(%rbp), %r12
cmpq -0x88(%rbp), %r12
je 0x38a7
movsd (%r12), %xmm0
leaq -0x378(%rbp), %rdi
callq 0x2532
addq $0x8, %r12
jmp 0x3886
movq -0x70(%rbp), %r12
cmpq -0x68(%rbp), %r12
je 0x38c9
movsd (%r12), %xmm0
leaq -0x980(%rbp), %rdi
callq 0x2532
addq $0x8, %r12
jmp 0x38ab
leaq -0xa90(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movq -0xa90(%rbp), %rax
movq -0xa88(%rbp), %rcx
subq -0xd00(%rbp), %rax
subq -0xcf8(%rbp), %rcx
movq -0xd0(%rbp), %rdx
movq %rax, (%rdx,%rbx,8)
movq -0xc8(%rbp), %rax
movq %rcx, (%rax,%rbx,8)
leaq -0x378(%rbp), %rdi
leaq -0x980(%rbp), %rsi
xorl %edx, %edx
callq 0x2612
leaq -0x780(%rbp), %r12
movq -0xd8(%rbp), %rax
movsd %xmm0, (%rax,%rbx,8)
movl $0xb, %edx
movq %r12, %rdi
leaq 0x199e(%rip), %rsi      # 0x52de
movsd %xmm0, -0x30(%rbp)
callq 0x2230
movsd -0x30(%rbp), %xmm0
movq %r12, %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 0x2030
movq %rax, %rdi
callq 0x2140
movsd -0xb0(%rbp), %xmm0
ucomisd 0x17b7(%rip), %xmm0     # 0x5148
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
jae 0x39b8
movsd -0xb0(%rbp), %xmm0
callq 0x2170
movsd %xmm0, -0xa0(%rbp)
movsd -0xb8(%rbp), %xmm0
ucomisd 0x1780(%rip), %xmm0     # 0x5148
movsd -0xf0(%rbp), %xmm0
movapd %xmm0, -0x50(%rbp)
jae 0x39e9
movsd -0xb8(%rbp), %xmm0
callq 0x2170
movapd %xmm0, -0x50(%rbp)
movq -0x130(%rbp), %r12
xorpd %xmm0, %xmm0
testq %r12, %r12
je 0x3a72
movsd %xmm0, -0x30(%rbp)
leaq 0x8(%r12), %r13
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x48fa
testq %rax, %rax
je 0x3a36
movq %r15, %rdi
movq %r13, %rsi
callq 0x4dbe
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
jmp 0x3a3a
xorpd %xmm0, %xmm0
movapd -0x50(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm2
addsd %xmm2, %xmm0
mulsd -0xa0(%rbp), %xmm2
subsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
divsd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
addsd %xmm2, %xmm0
movq (%r12), %r12
incl %r14d
jmp 0x39f4
movq -0x168(%rbp), %r12
testq %r12, %r12
je 0x3af6
movapd -0x50(%rbp), %xmm1
xorpd 0x16c5(%rip), %xmm1     # 0x5150
movapd %xmm1, -0x50(%rbp)
movsd %xmm0, -0x30(%rbp)
leaq 0x8(%r12), %rsi
leaq -0x140(%rbp), %rdi
callq 0x48fa
testq %rax, %rax
je 0x3ab2
movsd -0x30(%rbp), %xmm0
jmp 0x3aed
incl %r14d
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%r12), %xmm0
movapd -0x50(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0xa0(%rbp), %xmm2
mulsd 0x1670(%rip), %xmm2     # 0x5148
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
divsd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
addsd %xmm2, %xmm0
movq (%r12), %r12
testq %r12, %r12
jne 0x3a90
movsd %xmm0, -0x30(%rbp)
movq -0xc0(%rbp), %rax
movsd %xmm0, (%rax,%rbx,8)
movl $0x9, %edx
leaq -0x780(%rbp), %r12
movq %r12, %rdi
leaq 0x17cd(%rip), %rsi      # 0x52ea
callq 0x2230
movq %r12, %rdi
movsd -0x30(%rbp), %xmm0
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 0x2030
movq %rax, %rdi
callq 0x2140
incq %rbx
movsd -0x38(%rbp), %xmm0
addsd 0x15cf(%rip), %xmm0     # 0x5138
movsd %xmm0, -0x38(%rbp)
leaq -0x950(%rbp), %rdi
callq 0x42d8
leaq -0x348(%rbp), %rdi
callq 0x42d8
movsd -0xa8(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jae 0x375b
decl %r14d
leaq -0x780(%rbp), %rdi
callq 0x2270
movq -0xe8(%rbp), %r15
leaq -0x9f0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq 0x415b
leaq -0x780(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0x378(%rbp), %rdi
callq 0x2310
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x415b
leaq -0x378(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0x980(%rbp), %rdi
callq 0x2310
leaq -0xa90(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x5, %edx
callq 0x415b
leaq -0x980(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0xd00(%rbp), %rdi
callq 0x2310
leaq -0x9f0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x415b
leaq -0xd00(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
cmpl $0x0, -0x54(%rbp)
je 0x3f0a
xorl %ebx, %ebx
leaq 0x1669(%rip), %r12      # 0x52f4
leaq -0xd00(%rbp), %r15
movq -0xe0(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
leaq -0x378(%rbp), %rdi
movsd %xmm0, -0x30(%rbp)
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2230
movq -0xd8(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
movaps %xmm0, -0x50(%rbp)
movl %r14d, %edi
callq 0x2be8
movaps %xmm0, -0xa0(%rbp)
movq -0xc0(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, -0x40(%rbp)
movl %r14d, %edi
callq 0x2be8
movapd -0xa0(%rbp), %xmm1
subsd %xmm0, %xmm1
andpd 0x1455(%rip), %xmm1     # 0x5160
movapd %xmm1, %xmm0
leaq -0x378(%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 0x2030
movq %rax, %rdi
callq 0x2140
leaq -0x980(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2230
movq -0xd0(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sdq (%rax,%rbx,8), %xmm0
movq -0xc8(%rbp), %rax
xorps %xmm1, %xmm1
cvtsi2sdq (%rax,%rbx,8), %xmm1
divsd 0x13b2(%rip), %xmm1     # 0x5140
addsd %xmm0, %xmm1
movsd %xmm1, -0x108(%rbp)
fldl -0x108(%rbp)
subq $0x10, %rsp
fstpt (%rsp)
leaq -0x980(%rbp), %rdi
callq 0x20f0
addq $0x10, %rsp
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 0x2030
movq %rax, %rdi
callq 0x2140
movsd -0x40(%rbp), %xmm0
movl %r14d, %edi
callq 0x2be8
leaq -0x780(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x14ea(%rip), %rsi      # 0x52f6
callq 0x2230
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movapd -0x50(%rbp), %xmm0
movl %r14d, %edi
callq 0x2be8
leaq -0x780(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movl $0xa, %edx
movq %rax, %rdi
leaq 0x149a(%rip), %rsi      # 0x52fe
callq 0x2230
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq %r15, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2230
movapd -0x50(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
subsd %xmm1, %xmm0
andpd 0x129c(%rip), %xmm0     # 0x5160
divsd %xmm1, %xmm0
movq %r15, %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 0x2030
movq %rax, %rdi
callq 0x2140
incq %rbx
cmpq %rbx, -0x100(%rbp)
jne 0x3c92
leaq -0xd00(%rbp), %r15
movq %r15, %rdi
callq 0x2270
leaq -0x378(%rbp), %r14
movq %r14, %rdi
callq 0x2270
leaq -0x780(%rbp), %rbx
movq %rbx, %rdi
callq 0x2270
movq 0x4092(%rip), %rax      # 0x7fd0
movq (%rax), %r12
movq 0x18(%rax), %r13
leaq -0xcf8(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0xd00(%rbp,%rax)
callq 0x21a0
movl $0xf8, %eax
addq %rax, %r15
movq %r15, %rdi
callq 0x20a0
leaq -0x978(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0x980(%rbp,%rax)
callq 0x21a0
leaq -0x980(%rbp), %rdi
movl $0xf8, %r15d
addq %r15, %rdi
callq 0x20a0
leaq -0x370(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0x378(%rbp,%rax)
callq 0x21a0
addq %r15, %r14
movq %r14, %rdi
callq 0x20a0
leaq -0x580(%rbp), %rdi
callq 0x2080
leaq -0x778(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0x780(%rbp,%rax)
callq 0x21a0
addq %r15, %rbx
movq %rbx, %rdi
callq 0x20a0
leaq -0x178(%rbp), %rdi
callq 0x435c
leaq -0x140(%rbp), %rdi
callq 0x435c
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4026
callq 0x21d0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x4037
callq 0x21d0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f89(%rip), %rdi      # 0x7fd8
leaq 0x11f5(%rip), %rsi      # 0x524b
callq 0x2200
movq %rax, %rdi
callq 0x20e0
movl $0x1, %edi
callq 0x2240
jmp 0x40dd
jmp 0x4071
movq %rax, %rbx
jmp 0x40ec
jmp 0x4078
movq %rax, %rbx
jmp 0x40f8
jmp 0x40af
jmp 0x4081
movq %rax, %rbx
jmp 0x4110
movq %rax, %rbx
jmp 0x411c
jmp 0x40af
jmp 0x40dd
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40af
jmp 0x40dd
jmp 0x40c0
movq %rax, %rbx
jmp 0x4104
jmp 0x40c0
jmp 0x40dd
jmp 0x40c0
jmp 0x40c0
jmp 0x40c0
jmp 0x40c0
movq %rax, %rbx
leaq -0x950(%rbp), %rdi
callq 0x42d8
leaq -0x348(%rbp), %rdi
callq 0x42d8
jmp 0x4104
movq %rax, %rbx
leaq -0xd00(%rbp), %rdi
callq 0x22a0
leaq -0x980(%rbp), %rdi
callq 0x22a0
leaq -0x378(%rbp), %rdi
callq 0x22a0
leaq -0x580(%rbp), %rdi
callq 0x2080
leaq -0x780(%rbp), %rdi
callq 0x22a0
leaq -0x178(%rbp), %rdi
callq 0x435c
leaq -0x140(%rbp), %rdi
callq 0x435c
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4142
callq 0x21d0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x4153
callq 0x21d0
movq %rbx, %rdi
callq 0x2340