// File: 4n6ist[P]usn_analytics/lib/usnjrnl.cpp
// Function: UsnJrnl::CheckRecords()
int UsnJrnl::CheckRecords() {
  
  uint64_t i,j;
  uint16_t rec_cnt;
  double time_taken;
  uint64_t progress = usn_set.size() / 20;
  uint64_t rel_ts; // relative timestamp
  vector<uint64_t> skip_set;
  for(i=0; i+1 < usn_set.size(); i++) {
    
    if (i+1 > progress) {
  	  printf(".");
      progress += usn_set.size() / 20;
    }

    // if current record already processed then skip
    if (find(skip_set.begin(), skip_set.end(), i) != skip_set.end()) {
      skip_set.erase(remove(skip_set.begin(), skip_set.end(), i), skip_set.end());
      continue;
    }

    UsnRecord* ur_base = new UsnRecord(fp_in);    
    ur_base->ReadParseRecord(usn_table[usn_set[i]]);
    rec_cnt = 1;
    time_taken = 0;
    
    // DELETE|CLOSE or DELETE|TRANSACT|CLOSE - don't pack
    if (ur_base->usn_record.Reason == (DELETE|CLOSE) || ur_base->usn_record.Reason == (DELETE|TRANSACT|CLOSE)) { 
      UsnMain* um = new UsnMain();
      um->StoreRecord(ur_base, rec_cnt, time_taken);
      usnmain_set.push_back(*um);
      delete um, ur_base;
      continue;
    }

    // if next record already processed then skip
    j=1;
    while(find(skip_set.begin(), skip_set.end(), i+j) != skip_set.end())
      j++;
    
    UsnRecord* ur_next = new UsnRecord(fp_in);    
	  ur_next->ReadParseRecord(usn_table[usn_set[i+j]]);

    // SECURITY -> SECURITY|CLOSE - finish packing
    if ((ur_base->usn_record.Reason == SECURITY) && (ur_next->usn_record.Reason == (SECURITY|CLOSE))) {
      rec_cnt++;
      time_taken += double(ur_next->usn_record.TimeStamp - ur_base->usn_record.TimeStamp) / 10000000; // 1s
      ur_base->usn_record.Reason |= ur_next->usn_record.Reason;
      ur_base->usn_record.FileAttributes |= ur_next->usn_record.FileAttributes;
      UsnMain* um = new UsnMain();
      um->StoreRecord(ur_base, rec_cnt, time_taken);
      usnmain_set.push_back(*um);
      skip_set.push_back(i+j);
      delete um, ur_next, ur_base;
      continue;
    }

    // OLDNAME -> NEWNAME - determine RENAME or MOVE and finish packing
    if ((ur_base->usn_record.Reason & OLDNAME) && (ur_next->usn_record.Reason & NEWNAME)) {
      if (ur_base->file_name == ur_next->file_name) {
        ur_base->usn_record.Reason = MOVE;
        ur_base->file_name += " (" + to_string(ur_base->pid) + " -> " + to_string(ur_next->pid) + ")";
      }
      else {
        ur_base->usn_record.Reason = RENAME;
        ur_base->file_name += " -> " + ur_next->file_name;
      }
      rec_cnt++;
      time_taken += double(ur_next->usn_record.TimeStamp - ur_base->usn_record.TimeStamp) / 10000000;
      ur_base->usn_record.FileAttributes |= ur_next->usn_record.FileAttributes;
      skip_set.push_back(i+j);
      // OLDNAME -> NEWNAME -> NEWNAME|CLOSE - also pack
      rel_ts = ur_next->usn_record.TimeStamp;
      ur_next->ReadParseRecord(usn_table[usn_set[i+j+1]]);
      if (ur_next->usn_record.Reason == (NEWNAME|CLOSE)) {
        ur_base->usn_record.FileAttributes |= ur_next->usn_record.FileAttributes;
        rec_cnt++;
        time_taken += double(ur_next->usn_record.TimeStamp - rel_ts) / 10000000;
        skip_set.push_back(i+j+1);
      }    
      UsnMain* um = new UsnMain();
      um->StoreRecord(ur_base, rec_cnt, time_taken);
      usnmain_set.push_back(*um);
      delete um, ur_next, ur_base;
      continue;
    }
    
    rel_ts = ur_base->usn_record.TimeStamp;
    map<string, uint16_t> filename_vote;
    filename_vote[ur_base->file_name] = 1;
    
    // main pack process
    while(ur_next->usn_record.TimeStamp - rel_ts < 10000000) { // 1s
      if(ur_base->cid == ur_next->cid) { // check if next record is the same id and packable
        // count filename because of garbage exclusion
        if(filename_vote.find(ur_next->file_name) == filename_vote.end())
          filename_vote[ur_next->file_name] = 1;
        else 
          filename_vote[ur_next->file_name]++;
        if (ur_next->usn_record.Reason & (OLDNAME|NEWNAME)) // stop if next operation includes RENAME 
          break;
        rec_cnt++;
        time_taken += double(ur_next->usn_record.TimeStamp - rel_ts) / 10000000;
        ur_base->usn_record.Reason |= ur_next->usn_record.Reason;
        ur_base->usn_record.FileAttributes |= ur_next->usn_record.FileAttributes;
        rel_ts = ur_next->usn_record.TimeStamp;
        skip_set.push_back(i+j);
        if ((ur_next->usn_record.Reason & DELETE) && (ur_next->usn_record.Reason & CLOSE)) // finish if next operation includes DELETE|CLOSE
          break;
      } // skip checking procedure when it doesn't exist relevant record for faster processing
      else if (usnmain_set.size() > 0 && rec_cnt == usnmain_set.back().rec_cnt && ur_base->pid == usnmain_set.back().pid
        && ur_base->usn_record.Reason == usnmain_set.back().reasons_i && ur_base->usn_record.FileAttributes == usnmain_set.back().attrs_i) {
        if (rec_cnt == usnmain_set[usnmain_set.size()-2].rec_cnt && usnmain_set[usnmain_set.size()-2].pid == ur_base->pid
          && ur_base->usn_record.Reason == usnmain_set[usnmain_set.size()-2].reasons_i  && ur_base->usn_record.FileAttributes == usnmain_set[usnmain_set.size()-2].attrs_i) {
          break;
        }
      }
      j++;
      while(find(skip_set.begin(), skip_set.end(), i+j) != skip_set.end())
        j++;
      ur_next->ReadParseRecord(usn_table[usn_set[i+j]]);
    }

    int c=0;
    for(auto x: filename_vote) {
      if(x.second > c) {
        ur_base->file_name = x.first;
        c = x.second;
      }
    }
    // current record is the same pattern as previous record then update last record
    if(usnmain_set.size() > 0 && ur_base->cid == usnmain_set.back().cid && ur_base->pid == usnmain_set.back().pid 
      && ur_base->usn_record.Reason == usnmain_set.back().reasons_i && ur_base->usn_record.FileAttributes == usnmain_set.back().attrs_i) {
      usnmain_set.back().rec_cnt += rec_cnt;
      usnmain_set.back().time_taken = double(ur_base->usn_record.TimeStamp - usnmain_set.back().timestamp_i) / 10000000 + time_taken;
    } else { // not the same then push
      UsnMain* um = new UsnMain();
      um->StoreRecord(ur_base, rec_cnt, time_taken);
      usnmain_set.push_back(*um);
      delete um, ur_next, ur_base;
    }
  }
  // Todo: should process last record even if it's isolated 
  printf("Done\n");
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
addq $0x20, %rdi
callq 0xa620
movl $0x14, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xa2e0
movq $0x0, -0x10(%rbp)
movq -0x2c8(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2d0(%rbp)
addq $0x20, %rdi
callq 0xa620
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x5573
movq -0x10(%rbp), %rax
addq $0x1, %rax
cmpq -0x30(%rbp), %rax
jbe 0x4167
leaq 0x1865e(%rip), %rdi     # 0x1c787
xorl %eax, %eax
callq 0x3060
jmp 0x4132
movq -0x2c8(%rbp), %rdi
addq $0x20, %rdi
callq 0xa620
movl $0x14, %ecx
xorl %edx, %edx
divq %rcx
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x4167
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5597
leaq -0x50(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0xa680
movq -0x2e0(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0xa6b0
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0xa830
movq %rax, -0x2d8(%rbp)
jmp 0x41a5
movq -0x2d8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xa6b0
movq %rax, -0x80(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xa7f0
testb $0x1, %al
jne 0x41d3
jmp 0x429e
leaq -0x50(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0xa680
movq -0x2f0(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0xa6b0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0xa880
movq %rax, -0x2e8(%rbp)
jmp 0x421d
movq -0x2e8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xa7b0
leaq -0x50(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0xa6b0
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xa7b0
movq -0x300(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0xa6e0
movq %rax, -0x2f8(%rbp)
jmp 0x428b
movq -0x2f8(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x5554
movl $0x80, %edi
callq 0x3340
movq %rax, -0x308(%rbp)
jmp 0x42b1
movq -0x308(%rbp), %rdi
movq -0x2c8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x16410
jmp 0x42ca
movq -0x2c8(%rbp), %rdi
movq -0x308(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x320(%rbp)
movq %rdi, %rax
addq $0x68, %rax
movq %rax, -0x318(%rbp)
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
callq 0xa8d0
movq -0x318(%rbp), %rdi
movq %rax, %rsi
callq 0xa540
movq %rax, -0x310(%rbp)
jmp 0x4320
movq -0x320(%rbp), %rdi
movq -0x310(%rbp), %rax
movq (%rax), %rsi
callq 0x167e0
jmp 0x4338
movw $0x1, -0x1a(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0xc0(%rbp), %rax
cmpl $0x80000200, 0x38(%rax) # imm = 0x80000200
je 0x436a
movq -0xc0(%rbp), %rax
cmpl $0x80400200, 0x38(%rax) # imm = 0x80400200
jne 0x444a
movl $0xca, %edi
callq 0x3340
movq %rax, -0x328(%rbp)
jmp 0x437d
movq -0x328(%rbp), %rdi
callq 0x16c30
jmp 0x438b
movq -0x328(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movzwl -0x1a(%rbp), %edx
movsd -0x28(%rbp), %xmm0
callq 0x16d80
jmp 0x43b7
movq -0x2c8(%rbp), %rdi
addq $0x50, %rdi
movq -0xc8(%rbp), %rsi
callq 0xa8f0
jmp 0x43d0
movq -0xc8(%rbp), %rax
movq %rax, -0x330(%rbp)
cmpq $0x0, %rax
je 0x4401
movq -0x330(%rbp), %rdi
callq 0xa960
movq -0x330(%rbp), %rdi
movl $0xca, %esi
callq 0x3350
jmp 0x5554
movq -0x308(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x80, %esi
callq 0x3350
jmp 0x5597
movq -0x328(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0xca, %esi
callq 0x3350
jmp 0x5597
movq $0x1, -0x18(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0xa680
movq -0x340(%rbp), %rdi
movq %rax, -0xd8(%rbp)
callq 0xa6b0
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0xa830
movq %rax, -0x338(%rbp)
jmp 0x44b1
movq -0x338(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xa6b0
movq %rax, -0xf0(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xa7f0
testb $0x1, %al
jne 0x44e8
jmp 0x44f9
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x4452
movl $0x80, %edi
callq 0x3340
movq %rax, -0x348(%rbp)
jmp 0x450c
movq -0x348(%rbp), %rdi
movq -0x2c8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x16410
jmp 0x4525
movq -0x2c8(%rbp), %rdi
movq -0x348(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x360(%rbp)
movq %rdi, %rax
addq $0x68, %rax
movq %rax, -0x358(%rbp)
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
addq %rax, %rsi
callq 0xa8d0
movq -0x358(%rbp), %rdi
movq %rax, %rsi
callq 0xa540
movq %rax, -0x350(%rbp)
jmp 0x4582
movq -0x360(%rbp), %rdi
movq -0x350(%rbp), %rax
movq (%rax), %rsi
callq 0x167e0
jmp 0x459a
movq -0xc0(%rbp), %rax
cmpl $0x800, 0x38(%rax)      # imm = 0x800
jne 0x475d
movq -0xf8(%rbp), %rax
cmpl $0x80000800, 0x38(%rax) # imm = 0x80000800
jne 0x475d
movw -0x1a(%rbp), %ax
incw %ax
movw %ax, -0x1a(%rbp)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0xc0(%rbp), %rcx
movq 0x30(%rcx), %rcx
subq %rcx, %rax
movq %rax, %xmm1
movaps 0x17a1e(%rip), %xmm0    # 0x1c010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x17a22(%rip), %xmm0    # 0x1c020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x17a1b(%rip), %xmm0    # 0x1c030
divsd %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0xf8(%rbp), %rax
movl 0x38(%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x38(%rax), %ecx
orl %edx, %ecx
movl %ecx, 0x38(%rax)
movq -0xf8(%rbp), %rax
movl 0x44(%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %ecx
orl %edx, %ecx
movl %ecx, 0x44(%rax)
movl $0xca, %edi
callq 0x3340
movq %rax, -0x368(%rbp)
jmp 0x466c
movq -0x368(%rbp), %rdi
callq 0x16c30
jmp 0x467a
movq -0x368(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movzwl -0x1a(%rbp), %edx
movsd -0x28(%rbp), %xmm0
callq 0x16d80
jmp 0x46a6
movq -0x2c8(%rbp), %rdi
addq $0x50, %rdi
movq -0x100(%rbp), %rsi
callq 0xa8f0
jmp 0x46bf
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0xa9c0
jmp 0x46e3
movq -0x100(%rbp), %rax
movq %rax, -0x370(%rbp)
cmpq $0x0, %rax
je 0x4714
movq -0x370(%rbp), %rdi
callq 0xa960
movq -0x370(%rbp), %rdi
movl $0xca, %esi
callq 0x3350
jmp 0x5554
movq -0x348(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x80, %esi
callq 0x3350
jmp 0x5597
movq -0x368(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0xca, %esi
callq 0x3350
jmp 0x5597
movq -0xc0(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x4c64
movq -0xf8(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x4c64
movq -0xc0(%rbp), %rdi
addq $0x60, %rdi
movq -0xf8(%rbp), %rsi
addq $0x60, %rsi
callq 0xa9f0
testb $0x1, %al
jne 0x47b1
jmp 0x4967
movq -0xc0(%rbp), %rax
movl $0x2000000, 0x38(%rax)  # imm = 0x2000000
movq -0xc0(%rbp), %rax
movl 0x5a(%rax), %esi
leaq -0x1a8(%rbp), %rdi
callq 0xaba0
jmp 0x47d7
leaq 0x179b8(%rip), %rsi     # 0x1c196
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rdx
callq 0xab50
jmp 0x47f3
leaq 0x1799f(%rip), %rdx     # 0x1c199
leaq -0x168(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0xa360
jmp 0x480f
movq -0xf8(%rbp), %rax
movl 0x5a(%rax), %esi
leaq -0x1c8(%rbp), %rdi
callq 0xaba0
jmp 0x4827
leaq -0x148(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
callq 0xaa80
jmp 0x4843
leaq 0x17954(%rip), %rdx     # 0x1c19e
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0xa360
jmp 0x485f
movq -0xc0(%rbp), %rdi
addq $0x60, %rdi
leaq -0x128(%rbp), %rsi
callq 0x3470
jmp 0x4878
leaq -0x128(%rbp), %rdi
callq 0x31d0
leaq -0x148(%rbp), %rdi
callq 0x31d0
leaq -0x1c8(%rbp), %rdi
callq 0x31d0
leaq -0x168(%rbp), %rdi
callq 0x31d0
leaq -0x188(%rbp), %rdi
callq 0x31d0
leaq -0x1a8(%rbp), %rdi
callq 0x31d0
jmp 0x49d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4956
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x494a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x493e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4932
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x4926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x31d0
leaq -0x148(%rbp), %rdi
callq 0x31d0
leaq -0x1c8(%rbp), %rdi
callq 0x31d0
leaq -0x168(%rbp), %rdi
callq 0x31d0
leaq -0x188(%rbp), %rdi
callq 0x31d0
leaq -0x1a8(%rbp), %rdi
callq 0x31d0
jmp 0x5597
movq -0xc0(%rbp), %rax
movl $0x1000000, 0x38(%rax)  # imm = 0x1000000
movq -0xf8(%rbp), %rdx
addq $0x60, %rdx
leaq 0x17812(%rip), %rsi     # 0x1c199
leaq -0x1e8(%rbp), %rdi
callq 0xac80
jmp 0x4995
movq -0xc0(%rbp), %rdi
addq $0x60, %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3470
jmp 0x49ae
leaq -0x1e8(%rbp), %rdi
callq 0x31d0
jmp 0x49d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x31d0
jmp 0x5597
movw -0x1a(%rbp), %ax
incw %ax
movw %ax, -0x1a(%rbp)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0xc0(%rbp), %rcx
movq 0x30(%rcx), %rcx
subq %rcx, %rax
movq %rax, %xmm1
movaps 0x17607(%rip), %xmm0    # 0x1c010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x1760b(%rip), %xmm0    # 0x1c020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x17604(%rip), %xmm0    # 0x1c030
divsd %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0xf8(%rbp), %rax
movl 0x44(%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %ecx
orl %edx, %ecx
movl %ecx, 0x44(%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x1f0(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0xa9c0
jmp 0x4a7b
movq -0x2c8(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x388(%rbp)
movq %rdi, %rax
addq $0x68, %rax
movq %rax, -0x380(%rbp)
addq $0x20, %rdi
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
leaq 0x1(%rax,%rcx), %rsi
callq 0xa8d0
movq -0x380(%rbp), %rdi
movq %rax, %rsi
callq 0xa540
movq %rax, -0x378(%rbp)
jmp 0x4adb
movq -0x388(%rbp), %rdi
movq -0x378(%rbp), %rax
movq (%rax), %rsi
callq 0x167e0
jmp 0x4af3
movq -0xf8(%rbp), %rax
cmpl $0x80002000, 0x38(%rax) # imm = 0x80002000
jne 0x4ba6
movq -0xf8(%rbp), %rax
movl 0x44(%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %ecx
orl %edx, %ecx
movl %ecx, 0x44(%rax)
movw -0x1a(%rbp), %ax
incw %ax
movw %ax, -0x1a(%rbp)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm1
movaps 0x174c7(%rip), %xmm0    # 0x1c010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x174cb(%rip), %xmm0    # 0x1c020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x174c4(%rip), %xmm0    # 0x1c030
divsd %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
leaq 0x1(%rax,%rcx), %rax
movq %rax, -0x1f8(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0xa9c0
jmp 0x4ba4
jmp 0x4ba6
movl $0xca, %edi
callq 0x3340
movq %rax, -0x390(%rbp)
jmp 0x4bb9
movq -0x390(%rbp), %rdi
callq 0x16c30
jmp 0x4bc7
movq -0x390(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movzwl -0x1a(%rbp), %edx
movsd -0x28(%rbp), %xmm0
callq 0x16d80
jmp 0x4bf3
movq -0x2c8(%rbp), %rdi
addq $0x50, %rdi
movq -0x200(%rbp), %rsi
callq 0xa8f0
jmp 0x4c0c
movq -0x200(%rbp), %rax
movq %rax, -0x398(%rbp)
cmpq $0x0, %rax
je 0x4c3d
movq -0x398(%rbp), %rdi
callq 0xa960
movq -0x398(%rbp), %rdi
movl $0xca, %esi
callq 0x3350
jmp 0x5554
movq -0x390(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0xca, %esi
callq 0x3350
jmp 0x5597
movq -0xc0(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
leaq -0x230(%rbp), %rdi
movq %rdi, -0x3a8(%rbp)
callq 0xad90
movq -0x3a8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
addq $0x60, %rsi
callq 0xadb0
movq %rax, -0x3a0(%rbp)
jmp 0x4ca6
movq -0x3a0(%rbp), %rax
movw $0x1, (%rax)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
subq -0x38(%rbp), %rax
cmpq $0x989680, %rax         # imm = 0x989680
jae 0x51fe
movq -0xc0(%rbp), %rax
movl 0x54(%rax), %eax
movq -0xf8(%rbp), %rcx
cmpl 0x54(%rcx), %eax
jne 0x4ebf
movq -0xf8(%rbp), %rsi
addq $0x60, %rsi
leaq -0x230(%rbp), %rdi
callq 0xaec0
movq %rax, -0x3b0(%rbp)
jmp 0x4d07
movq -0x3b0(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x230(%rbp), %rdi
callq 0xaef0
movq %rax, -0x240(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0xae90
testb $0x1, %al
jne 0x4d41
jmp 0x4d80
movq -0xf8(%rbp), %rsi
addq $0x60, %rsi
leaq -0x230(%rbp), %rdi
callq 0xadb0
movq %rax, -0x3b8(%rbp)
jmp 0x4d61
movq -0x3b8(%rbp), %rax
movw $0x1, (%rax)
jmp 0x4db1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5565
movq -0xf8(%rbp), %rsi
addq $0x60, %rsi
leaq -0x230(%rbp), %rdi
callq 0xadb0
movq %rax, -0x3c0(%rbp)
jmp 0x4da0
movq -0x3c0(%rbp), %rax
movw (%rax), %cx
addw $0x1, %cx
movw %cx, (%rax)
movq -0xf8(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x3000, %eax           # imm = 0x3000
cmpl $0x0, %eax
je 0x4dca
jmp 0x51fe
movw -0x1a(%rbp), %ax
incw %ax
movw %ax, -0x1a(%rbp)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm1
movaps 0x1721d(%rip), %xmm0    # 0x1c010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x17221(%rip), %xmm0    # 0x1c020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x1721a(%rip), %xmm0    # 0x1c030
divsd %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0xf8(%rbp), %rax
movl 0x38(%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x38(%rax), %ecx
orl %edx, %ecx
movl %ecx, 0x38(%rax)
movq -0xf8(%rbp), %rax
movl 0x44(%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %ecx
orl %edx, %ecx
movl %ecx, 0x44(%rax)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x248(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xa9c0
jmp 0x4e8d
movq -0xf8(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x4eba
movq -0xf8(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x4eba
jmp 0x51fe
jmp 0x50df
movq -0x2c8(%rbp), %rdi
addq $0x50, %rdi
callq 0xaf20
cmpq $0x0, %rax
jbe 0x50dd
movq -0x2c8(%rbp), %rdi
movzwl -0x1a(%rbp), %eax
movl %eax, -0x3c4(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x3c4(%rbp), %eax
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jne 0x50dd
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x5a(%rax), %eax
movl %eax, -0x3c8(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x3c8(%rbp), %eax
cmpl 0xa6(%rcx), %eax
jne 0x50dd
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x3cc(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x3cc(%rbp), %eax
cmpl 0x5a(%rcx), %eax
jne 0x50dd
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x3d0(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x3d0(%rbp), %eax
cmpl 0x7e(%rcx), %eax
jne 0x50dd
movq -0x2c8(%rbp), %rdi
movzwl -0x1a(%rbp), %eax
movl %eax, -0x3d4(%rbp)
movq %rdi, %rax
addq $0x50, %rax
movq %rax, -0x3e0(%rbp)
addq $0x50, %rdi
callq 0xaf20
movq -0x3e0(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0xaf90
movq %rax, %rcx
movl -0x3d4(%rbp), %eax
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jne 0x50db
movq -0x2c8(%rbp), %rdi
movq %rdi, %rax
addq $0x50, %rax
movq %rax, -0x3e8(%rbp)
addq $0x50, %rdi
callq 0xaf20
movq -0x3e8(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0xaf90
movl 0xa6(%rax), %eax
movq -0xc0(%rbp), %rcx
cmpl 0x5a(%rcx), %eax
jne 0x50db
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x3ec(%rbp)
movq %rdi, %rax
addq $0x50, %rax
movq %rax, -0x3f8(%rbp)
addq $0x50, %rdi
callq 0xaf20
movq -0x3f8(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0xaf90
movq %rax, %rcx
movl -0x3ec(%rbp), %eax
cmpl 0x5a(%rcx), %eax
jne 0x50db
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x3fc(%rbp)
movq %rdi, %rax
addq $0x50, %rax
movq %rax, -0x408(%rbp)
addq $0x50, %rdi
callq 0xaf20
movq -0x408(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0xaf90
movq %rax, %rcx
movl -0x3fc(%rbp), %eax
cmpl 0x7e(%rcx), %eax
jne 0x50db
jmp 0x51fe
jmp 0x50dd
jmp 0x50df
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0xa680
movq -0x418(%rbp), %rdi
movq %rax, -0x258(%rbp)
callq 0xa6b0
movq %rax, -0x260(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x268(%rbp)
movq -0x258(%rbp), %rdi
movq -0x260(%rbp), %rsi
leaq -0x268(%rbp), %rdx
callq 0xa830
movq %rax, -0x410(%rbp)
jmp 0x514a
movq -0x410(%rbp), %rax
movq %rax, -0x250(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xa6b0
movq %rax, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0xa7f0
testb $0x1, %al
jne 0x5181
jmp 0x5192
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x50eb
movq -0x2c8(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq %rax, -0x430(%rbp)
movq %rdi, %rax
addq $0x68, %rax
movq %rax, -0x428(%rbp)
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
addq %rax, %rsi
callq 0xa8d0
movq -0x428(%rbp), %rdi
movq %rax, %rsi
callq 0xa540
movq %rax, -0x420(%rbp)
jmp 0x51e1
movq -0x430(%rbp), %rdi
movq -0x420(%rbp), %rax
movq (%rax), %rsi
callq 0x167e0
jmp 0x51f9
jmp 0x4cb2
movl $0x0, -0x274(%rbp)
leaq -0x230(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rdi
callq 0xafb0
movq %rax, -0x288(%rbp)
movq -0x280(%rbp), %rdi
callq 0xaef0
movq %rax, -0x290(%rbp)
leaq -0x288(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0xafe0
testb $0x1, %al
jne 0x5258
jmp 0x52e6
leaq -0x288(%rbp), %rdi
callq 0xb010
movq %rax, %rsi
leaq -0x2b8(%rbp), %rdi
callq 0xb030
jmp 0x5275
movzwl -0x298(%rbp), %eax
cmpl -0x274(%rbp), %eax
jle 0x52c9
movq -0xc0(%rbp), %rdi
addq $0x60, %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3050
jmp 0x529d
movzwl -0x298(%rbp), %eax
movl %eax, -0x274(%rbp)
jmp 0x52c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0xb070
jmp 0x5565
leaq -0x2b8(%rbp), %rdi
callq 0xb070
leaq -0x288(%rbp), %rdi
callq 0xb090
jmp 0x523c
movq -0x2c8(%rbp), %rdi
addq $0x50, %rdi
callq 0xaf20
cmpq $0x0, %rax
jbe 0x5490
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x434(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x434(%rbp), %eax
cmpl 0xa2(%rcx), %eax
jne 0x5490
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x5a(%rax), %eax
movl %eax, -0x438(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x438(%rbp), %eax
cmpl 0xa6(%rcx), %eax
jne 0x5490
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x43c(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x43c(%rbp), %eax
cmpl 0x5a(%rcx), %eax
jne 0x5490
movq -0x2c8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x440(%rbp)
addq $0x50, %rdi
callq 0xaf50
movq %rax, %rcx
movl -0x440(%rbp), %eax
cmpl 0x7e(%rcx), %eax
jne 0x5490
movq -0x2c8(%rbp), %rdi
movzwl -0x1a(%rbp), %eax
movl %eax, -0x45c(%rbp)
addq $0x50, %rdi
movq %rdi, -0x458(%rbp)
callq 0xaf50
movl -0x45c(%rbp), %edx
movq -0x458(%rbp), %rdi
movzwl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movq -0xc0(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x450(%rbp)
callq 0xaf50
movq -0x2c8(%rbp), %rdi
movq %rax, %rcx
movq -0x450(%rbp), %rax
movq 0xa(%rcx), %rcx
subq %rcx, %rax
movq %rax, %xmm0
movaps 0x16bcf(%rip), %xmm1    # 0x1c010
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x16bd3(%rip), %xmm1    # 0x1c020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x16bcc(%rip), %xmm1    # 0x1c030
divsd %xmm1, %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x448(%rbp)
addq $0x50, %rdi
callq 0xaf50
movsd -0x448(%rbp), %xmm0
movsd %xmm0, 0x32(%rax)
jmp 0x5548
movl $0xca, %edi
callq 0x3340
movq %rax, -0x468(%rbp)
jmp 0x54a3
movq -0x468(%rbp), %rdi
callq 0x16c30
jmp 0x54b1
movq -0x468(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0x2c0(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movzwl -0x1a(%rbp), %edx
movsd -0x28(%rbp), %xmm0
callq 0x16d80
jmp 0x54dd
movq -0x2c8(%rbp), %rdi
addq $0x50, %rdi
movq -0x2c0(%rbp), %rsi
callq 0xa8f0
jmp 0x54f6
movq -0x2c0(%rbp), %rax
movq %rax, -0x470(%rbp)
cmpq $0x0, %rax
je 0x5527
movq -0x470(%rbp), %rdi
callq 0xa960
movq -0x470(%rbp), %rdi
movl $0xca, %esi
callq 0x3350
jmp 0x5548
movq -0x468(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0xca, %esi
callq 0x3350
jmp 0x5565
leaq -0x230(%rbp), %rdi
callq 0xb0c0
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x40e2
leaq -0x230(%rbp), %rdi
callq 0xb0c0
jmp 0x5597
leaq 0x16e97(%rip), %rdi     # 0x1c411
xorl %eax, %eax
callq 0x3060
jmp 0x5583
leaq -0x50(%rbp), %rdi
callq 0xa280
xorl %eax, %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0xa280
movq -0x58(%rbp), %rdi
callq 0x35c0
nopl (%rax)