// File: tylerwowen[P]movielens/./movielens/neighborsfinder.cpp
// Function: NeighborsLocator::pcc(std::__cxx11::list<std::pair<int, double>, std::allocator<std::pair<int, double>>>&, std::__cxx11::list<std::pair<int, double>, std::allocator<std::pair<int, double>>>&)
double NeighborsLocator::pcc(Ratings_list &r1, Ratings_list &r2) {
  double sum1 = 0, sum1SQ = 0,
  sum2 = 0, sum2SQ = 0, sum12 = 0;
  
  Ratings_list::const_iterator iter1 = r1.cbegin(), iter2 = r2.cbegin();
  while (iter1 != r1.cend() && iter2 != r2.cend()) {
    double rating1 = 0, rating2 = 0;
    
    if (iter1->first < iter2->first) {
      rating1 = iter1->second;
      rating2 = defaultRatingForItem(iter1->first);
      iter1++;
    }
    else if (iter1->first == iter2->first) {
      rating1 = iter1->second;
      rating2 = iter2->second;
      iter1++;
      iter2++;
    }
    else {
      rating1 = defaultRatingForItem(iter2->first);
      rating2 = iter2->second;
      iter2++;
    }
    sum12 += rating1 * rating2;
    sum1 += rating1;
    sum1SQ += rating1 * rating1;
    sum2 += rating2;
    sum2SQ += rating2 * rating2;
  }
  
  Rating r1Last = r1.back();
  while (iter2 != r2.cend()) {
    double rating1 = 0, rating2 = iter2->second;
    if (iter2->first != r1Last.first) {
      rating1 = defaultRatingForItem(iter2->first);
    }
    else {
      rating1 = r1Last.second;
    }
    iter2++;
    
    sum12 += rating1 * rating2;
    sum1 += rating1;
    sum1SQ += rating1 * rating1;
    sum2 += rating2;
    sum2SQ += rating2 * rating2;
  }
  Rating r2Last = r2.back();
  while (iter1 != r1.cend()) {
    double rating1 = iter1->second, rating2 = 0;
    if (iter2->first != r1Last.first) {
      rating2 = defaultRatingForItem(iter1->first);
    }
    else {
      rating2 = r2Last.second;
    }
    iter1++;
    
    sum12 += rating1 * rating2;
    sum1 += rating1;
    sum1SQ += rating1 * rating1;
    sum2 += rating2;
    sum2SQ += rating2 * rating2;
  }

  double mean1 = sum1 / numOfItems;
  double mean2 = sum2 / numOfItems;

  return (sum12 - numOfItems * mean1 * mean2) / (sqrt(sum1SQ - numOfItems * mean1 * mean1) * sqrt(sum2SQ - numOfItems * mean2 * mean2));
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movq %rdx, 0x100(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
movq 0x108(%rsp), %rdi
callq 0xc020
movq %rax, 0xd0(%rsp)
movq 0x100(%rsp), %rdi
callq 0xc020
movq %rax, 0xc8(%rsp)
movq 0x108(%rsp), %rdi
callq 0xc050
movq %rax, 0xc0(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x4f30
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xf(%rsp)
jne 0xaa3b
jmp 0xaa69
movq 0x100(%rsp), %rdi
callq 0xc050
movq %rax, 0xb8(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x4f30
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0xaa76
jmp 0xac9e
xorps %xmm0, %xmm0
movsd %xmm0, 0xb0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
movl %eax, 0x8(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movq %rax, %rcx
movl 0x8(%rsp), %eax
cmpl (%rcx), %eax
jge 0xab11
leaq 0xd0(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xb0(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0xa0(%rsp)
jmp 0xabf7
leaq 0xd0(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
movl %eax, 0x4(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movq %rax, %rcx
movl 0x4(%rsp), %eax
cmpl (%rcx), %eax
jne 0xaba2
leaq 0xd0(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xb0(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x98(%rsp)
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x90(%rsp)
jmp 0xabf5
leaq 0xc8(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0xb0(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x88(%rsp)
jmp 0xabf7
movsd 0xb0(%rsp), %xmm0
mulsd 0xa8(%rsp), %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0xb0(%rsp), %xmm0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd 0xb0(%rsp), %xmm0
mulsd 0xb0(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0xa8(%rsp), %xmm0
addsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0xa8(%rsp), %xmm0
mulsd 0xa8(%rsp), %xmm0
addsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
jmp 0xaa02
movq 0x108(%rsp), %rdi
callq 0xc0e0
movq (%rax), %rcx
movq %rcx, 0x78(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x100(%rsp), %rdi
callq 0xc050
movq %rax, 0x70(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4f30
testb $0x1, %al
jne 0xacec
jmp 0xadf4
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
cmpl 0x78(%rsp), %eax
je 0xad42
leaq 0xc8(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0xad51
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x58(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0x68(%rsp), %xmm0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd 0x68(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x60(%rsp), %xmm0
addsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x60(%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
addsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
jmp 0xacbf
movq 0x100(%rsp), %rdi
callq 0xc0e0
movq (%rax), %rcx
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x108(%rsp), %rdi
callq 0xc050
movq %rax, 0x40(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4f30
testb $0x1, %al
jne 0xae3f
jmp 0xaf44
leaq 0xd0(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
cmpl 0x78(%rsp), %eax
je 0xae95
leaq 0xd0(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
jmp 0xaea1
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x28(%rsp)
movsd 0x38(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0x38(%rsp), %xmm0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd 0x38(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x30(%rsp), %xmm0
addsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x30(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
addsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
jmp 0xae12
movq 0x10(%rsp), %rax
movsd 0xf8(%rsp), %xmm0
cvtsi2sdl 0x8(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0xe8(%rsp), %xmm0
cvtsi2sdl 0x8(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0xd8(%rsp), %xmm0
cvtsi2sdl 0x8(%rax), %xmm1
mulsd 0x20(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0xf0(%rsp), %xmm1
cvtsi2sdl 0x8(%rax), %xmm2
mulsd 0x20(%rsp), %xmm2
mulsd 0x20(%rsp), %xmm2
subsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
movsd 0xe0(%rsp), %xmm2
cvtsi2sdl 0x8(%rax), %xmm3
mulsd 0x18(%rsp), %xmm3
mulsd 0x18(%rsp), %xmm3
subsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
addq $0x118, %rsp            # imm = 0x118
retq
nopl (%rax,%rax)