// File: /workspace/github_cpp_makefile_star2_O3/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 0x3f77
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x2250
movsd %xmm0, -0x38(%rbp)
movq 0x10(%r14), %rdi
callq 0x2250
addsd 0x20d5(%rip), %xmm0     # 0x5130
xorl %eax, %eax
ucomisd -0x38(%rbp), %xmm0
jb 0x307f
xorl %eax, %eax
movsd 0x20ca(%rip), %xmm2     # 0x5138
movsd -0x38(%rbp), %xmm1
incl %eax
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jae 0x3073
movsd %xmm0, -0x98(%rbp)
movq 0x18(%r14), %r12
movq 0x20(%r14), %r15
movl %eax, %eax
movq %rsp, %rcx
movq %rax, -0xa0(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xc8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xb8(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xb0(%rbp)
movq %rcx, %rsp
xorl %eax, %eax
movq %rax, -0x70(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x80(%rbp)
movq %rax, -0x50(%rbp)
movapd %xmm0, -0x60(%rbp)
leaq -0x118(%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 -0x150(%rbp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movupd %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movupd %xmm0, -0x8(%rax)
leaq -0x788(%rbp), %rdi
callq 0x2310
leaq -0x9f0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4087
leaq -0x788(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0x588(%rbp), %rdi
callq 0x2220
movq %r14, -0xe8(%rbp)
leaq -0x588(%rbp), %rdi
movq %r12, -0x90(%rbp)
movq %r12, %rsi
movl $0x8, %edx
callq 0x2120
movq %r15, -0x40(%rbp)
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
movl $0x0, -0x30(%rbp)
testb $0x2, -0x568(%rbp,%rax)
jne 0x3329
movl $0x0, -0x30(%rbp)
leaq -0xb00(%rbp), %r14
leaq -0x380(%rbp), %r13
leaq -0x148(%rbp), %r12
movq -0x578(%rbp,%rax), %rbx
movl $0x64, %edx
leaq -0x588(%rbp), %rdi
movq %r14, %rsi
callq 0x2320
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x568(%rbp,%rax)
jne 0x3241
addq $-0x65, %rbx
cmpq $-0x65, %rbx
ja 0x3241
movq -0x4a0(%rbp,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x32f4
movq %r14, %rdi
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movq -0x78(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x3269
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x78(%rbp)
jmp 0x3275
leaq -0x80(%rbp), %rdi
movq %r13, %rdx
callq 0x467e
movq %r14, %rdi
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x47ba
movq %r14, %rdi
testq %rax, %rax
je 0x32b4
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4bba
incl (%rax)
jmp 0x32d6
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movl $0x1, -0x378(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x48b6
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
incl -0x30(%rbp)
testb $0x2, -0x568(%rbp,%rax)
je 0x31f0
jmp 0x3329
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x3241
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x588, %rdi           # imm = 0xFA78
movl 0x20(%rdi), %esi
orl $0x2, %esi
callq 0x2300
jmp 0x3241
leaq -0x588(%rbp), %rdi
callq 0x2070
movq -0x40(%rbp), %rsi
leaq -0x588(%rbp), %rdi
movl $0x8, %edx
callq 0x2120
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x2, -0x568(%rbp,%rax)
jne 0x34b4
xorl %ebx, %ebx
leaq -0xb00(%rbp), %r12
leaq -0x380(%rbp), %r13
leaq -0x180(%rbp), %r15
movq -0x578(%rbp,%rax), %r14
movl $0x64, %edx
leaq -0x588(%rbp), %rdi
movq %r12, %rsi
callq 0x2320
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x568(%rbp,%rax)
jne 0x33cd
addq $-0x65, %r14
cmpq $-0x65, %r14
ja 0x33cd
movq -0x4a0(%rbp,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x347f
movq %r12, %rdi
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movq -0x58(%rbp), %rsi
cmpq -0x50(%rbp), %rsi
je 0x33f5
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x58(%rbp)
jmp 0x3401
leaq -0x60(%rbp), %rdi
movq %r13, %rdx
callq 0x467e
movq %r12, %rdi
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x47ba
movq %r12, %rdi
testq %rax, %rax
je 0x3440
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x4bba
incl (%rax)
jmp 0x3462
callq 0x2250
movsd %xmm0, -0x380(%rbp)
movl $0x1, -0x378(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x48b6
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
incl %ebx
testb $0x2, -0x568(%rbp,%rax)
je 0x337c
jmp 0x34b4
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x33cd
movq -0x588(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x588, %rdi           # imm = 0xFA78
movl 0x20(%rdi), %esi
orl $0x2, %esi
callq 0x2300
jmp 0x33cd
leaq -0x588(%rbp), %rdi
callq 0x2070
movq -0x40(%rbp), %r12
movq -0x90(%rbp), %r14
testq %r14, %r14
je 0x34ec
movq %r14, %rdi
callq 0x20d0
leaq -0x788(%rbp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2230
jmp 0x350d
movq -0x788(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x788, %rdi           # imm = 0xF878
movl 0x20(%rdi), %esi
orl $0x1, %esi
callq 0x2300
movq -0x788(%rbp), %rax
leaq -0x788(%rbp), %rdi
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
leaq -0x788(%rbp), %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq %rax, %r14
testq %r12, %r12
je 0x3560
movq %r12, %rdi
callq 0x20d0
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2230
jmp 0x357a
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 0x1cee(%rip), %rsi      # 0x5296
leaq -0x788(%rbp), %rdi
movl $0xf, %edx
callq 0x2230
leaq -0x788(%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 0x1cad(%rip), %rsi      # 0x52a6
leaq -0x788(%rbp), %rdi
movl $0xf, %edx
callq 0x2230
leaq -0x788(%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 0x1c6d(%rip), %rsi      # 0x52b6
leaq -0x788(%rbp), %rdi
movl $0x16, %edx
callq 0x2230
movq -0x130(%rbp), %rsi
leaq -0x788(%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 -0x98(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jb 0x3ac1
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
sqrtsd %xmm2, %xmm2
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
movapd 0x1a7b(%rip), %xmm1     # 0x5150
movapd %xmm0, -0xe0(%rbp)
xorpd %xmm0, %xmm1
movapd %xmm1, -0x110(%rbp)
leaq -0x788(%rbp), %r12
xorpd %xmm0, %xmm0
movsd %xmm2, -0x90(%rbp)
mulsd %xmm2, %xmm0
movsd %xmm0, -0xf0(%rbp)
leaq -0x180(%rbp), %r15
xorl %ebx, %ebx
movl $0x10, %edx
movq %r12, %rdi
leaq 0x1bad(%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 -0xc8(%rbp), %rax
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
leaq -0x320(%rbp), %rax
movq %rax, -0x350(%rbp)
movl $0x1, %esi
movq %rsi, -0x348(%rbp)
leaq -0x350(%rbp), %rax
xorpd %xmm1, %xmm1
movupd %xmm1, 0x10(%rax)
movl $0x3f800000, %edi       # imm = 0x3F800000
movl %edi, -0x330(%rbp)
movupd %xmm1, 0x28(%rax)
movl $0x0, %edx
movq %rdx, -0x380(%rbp)
movq %rdx, -0x360(%rbp)
movsd %xmm0, -0x370(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rcx, -0x358(%rbp)
leaq -0x928(%rbp), %rax
movq %rax, -0x958(%rbp)
movq %rsi, -0x950(%rbp)
leaq -0x958(%rbp), %rax
movupd %xmm1, 0x10(%rax)
movl %edi, -0x938(%rbp)
movupd %xmm1, 0x28(%rax)
movq %rdx, -0x988(%rbp)
movq %rdx, -0x968(%rbp)
movsd %xmm0, -0x978(%rbp)
movq %rcx, -0x960(%rbp)
leaq -0xd00(%rbp), %rdi
xorl %esi, %esi
callq 0x22d0
movq -0x80(%rbp), %r12
cmpq -0x78(%rbp), %r12
je 0x384c
movsd (%r12), %xmm0
leaq -0x380(%rbp), %rdi
callq 0x2530
addq $0x8, %r12
jmp 0x382e
movq -0x60(%rbp), %r12
cmpq -0x58(%rbp), %r12
je 0x386e
movsd (%r12), %xmm0
leaq -0x988(%rbp), %rdi
callq 0x2530
addq $0x8, %r12
jmp 0x3850
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 -0xb8(%rbp), %rdx
movq %rax, (%rdx,%rbx,8)
movq -0xb0(%rbp), %rax
movq %rcx, (%rax,%rbx,8)
leaq -0x380(%rbp), %rdi
leaq -0x988(%rbp), %rsi
xorl %edx, %edx
callq 0x261e
leaq -0x788(%rbp), %r12
movq -0xc0(%rbp), %rax
movsd %xmm0, (%rax,%rbx,8)
movl $0xb, %edx
movq %r12, %rdi
leaq 0x19f9(%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
movq -0x138(%rbp), %r12
xorpd %xmm0, %xmm0
testq %r12, %r12
je 0x39b5
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 0x47ba
testq %rax, %rax
je 0x3973
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c64
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
jmp 0x3977
xorpd %xmm0, %xmm0
movapd -0xe0(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm2
addsd %xmm2, %xmm0
mulsd -0x90(%rbp), %xmm2
subsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
divsd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
addsd %xmm2, %xmm0
movq (%r12), %r12
incl %r14d
jmp 0x3931
movq -0x170(%rbp), %r12
testq %r12, %r12
je 0x3a1b
movsd %xmm0, -0x30(%rbp)
leaq 0x8(%r12), %rsi
leaq -0x148(%rbp), %rdi
callq 0x47ba
testq %rax, %rax
je 0x39e3
movsd -0x30(%rbp), %xmm0
jmp 0x3a15
incl %r14d
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%r12), %xmm0
movapd -0x110(%rbp), %xmm1
mulsd %xmm0, %xmm1
addsd -0xf0(%rbp), %xmm1
mulsd %xmm1, %xmm1
divsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movq (%r12), %r12
jmp 0x39bc
movsd %xmm0, -0x30(%rbp)
movq -0xa8(%rbp), %rax
movsd %xmm0, (%rax,%rbx,8)
movl $0x9, %edx
leaq -0x788(%rbp), %r12
movq %r12, %rdi
leaq 0x18a8(%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 0x16aa(%rip), %xmm0     # 0x5138
movsd %xmm0, -0x38(%rbp)
leaq -0x958(%rbp), %rdi
callq 0x4204
leaq -0x350(%rbp), %rdi
callq 0x4204
movsd -0x98(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jae 0x3711
decl %r14d
leaq -0x788(%rbp), %rdi
callq 0x2270
movq -0xe8(%rbp), %r15
leaq -0x9f0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq 0x4087
leaq -0x788(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0x380(%rbp), %rdi
callq 0x2310
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x4087
leaq -0x380(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
leaq -0x988(%rbp), %rdi
callq 0x2310
leaq -0xa90(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x5, %edx
callq 0x4087
leaq -0x988(%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 0x4087
leaq -0xd00(%rbp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2050
cmpq $0x0, -0xa0(%rbp)
je 0x3e3c
xorl %ebx, %ebx
leaq 0x1740(%rip), %r12      # 0x52f4
leaq -0xd00(%rbp), %r15
movq -0xc8(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
leaq -0x380(%rbp), %rdi
movsd %xmm0, -0x30(%rbp)
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2230
movq -0xc0(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
movaps %xmm0, -0x90(%rbp)
movl %r14d, %edi
callq 0x2b96
movaps %xmm0, -0xe0(%rbp)
movq -0xa8(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, -0x40(%rbp)
movl %r14d, %edi
callq 0x2b96
movapd -0xe0(%rbp), %xmm1
subsd %xmm0, %xmm1
andpd 0x1529(%rip), %xmm1     # 0x5160
movapd %xmm1, %xmm0
leaq -0x380(%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 -0x988(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
callq 0x22c0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2230
movq -0xb8(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sdq (%rax,%rbx,8), %xmm0
movq -0xb0(%rbp), %rax
xorps %xmm1, %xmm1
cvtsi2sdq (%rax,%rbx,8), %xmm1
divsd 0x1486(%rip), %xmm1     # 0x5140
addsd %xmm0, %xmm1
movsd %xmm1, -0xf8(%rbp)
fldl -0xf8(%rbp)
subq $0x10, %rsp
fstpt (%rsp)
leaq -0x988(%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 0x2b96
leaq -0x788(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x15be(%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 -0x90(%rbp), %xmm0
movl %r14d, %edi
callq 0x2b96
leaq -0x788(%rbp), %rdi
callq 0x22c0
movq %rax, %r13
movl $0xa, %edx
movq %rax, %rdi
leaq 0x156b(%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 -0x90(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
subsd %xmm1, %xmm0
andpd 0x136a(%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, -0xa0(%rbp)
jne 0x3bbb
leaq -0xd00(%rbp), %r15
movq %r15, %rdi
callq 0x2270
leaq -0x380(%rbp), %r14
movq %r14, %rdi
callq 0x2270
leaq -0x788(%rbp), %rbx
movq %rbx, %rdi
callq 0x2270
movq 0x3160(%rip), %rax      # 0x6fd0
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 -0x980(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0x988(%rbp,%rax)
callq 0x21a0
leaq -0x988(%rbp), %rdi
movl $0xf8, %r15d
addq %r15, %rdi
callq 0x20a0
leaq -0x378(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0x380(%rbp,%rax)
callq 0x21a0
addq %r15, %r14
movq %r14, %rdi
callq 0x20a0
leaq -0x588(%rbp), %rdi
callq 0x2080
leaq -0x780(%rbp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, -0x788(%rbp,%rax)
callq 0x21a0
addq %r15, %rbx
movq %rbx, %rdi
callq 0x20a0
leaq -0x180(%rbp), %rdi
callq 0x4288
leaq -0x148(%rbp), %rdi
callq 0x4288
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3f58
callq 0x21d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x3f66
callq 0x21d0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x305a(%rip), %rdi      # 0x6fd8
leaq 0x12c6(%rip), %rsi      # 0x524b
callq 0x2200
movq %rax, %rdi
callq 0x20e0
movl $0x1, %edi
callq 0x2240
jmp 0x400c
jmp 0x3fa0
movq %rax, %rbx
jmp 0x401b
jmp 0x3fa7
movq %rax, %rbx
jmp 0x4027
jmp 0x3fde
jmp 0x3fb0
movq %rax, %rbx
jmp 0x403f
movq %rax, %rbx
jmp 0x404b
jmp 0x3fde
jmp 0x400c
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x3fde
jmp 0x400c
jmp 0x3fef
movq %rax, %rbx
jmp 0x4033
jmp 0x3fef
jmp 0x400c
jmp 0x3fef
jmp 0x3fef
jmp 0x3fef
jmp 0x3fef
movq %rax, %rbx
leaq -0x958(%rbp), %rdi
callq 0x4204
leaq -0x350(%rbp), %rdi
callq 0x4204
jmp 0x4033
movq %rax, %rbx
leaq -0xd00(%rbp), %rdi
callq 0x22a0
leaq -0x988(%rbp), %rdi
callq 0x22a0
leaq -0x380(%rbp), %rdi
callq 0x22a0
leaq -0x588(%rbp), %rdi
callq 0x2080
leaq -0x788(%rbp), %rdi
callq 0x22a0
leaq -0x180(%rbp), %rdi
callq 0x4288
leaq -0x148(%rbp), %rdi
callq 0x4288
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x4071
callq 0x21d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x407f
callq 0x21d0
movq %rbx, %rdi
callq 0x2340