// File: tylerwowen[P]movielens/./movielens/neighborsfinder.cpp
// Function: NeighborsLocator::llr(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::llr(Ratings_list &r1, Ratings_list &r2) {
  vector<int> deltaCounter(maxRating, 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) {
      iter1++;
    }
    else if (iter1->first == iter2->first) {
      rating1 = iter1->second;
      rating2 = iter2->second;
      deltaCounter[(int)fabs(rating1 - rating2)]++;
      iter1++;
      iter2++;
    }
    else {
      iter2++;
    }
  }
  double accumulator = 1;
  accumulator *= pow(0.5, deltaCounter[0]) / pow(1.0 / (double)maxRating, deltaCounter[0]);
  
  for (int i = 1; i < maxRating - 1; i++) {
    double pA = pow(2, -i - 1),
    pRand = 2 * (maxRating - i) / (double)(maxRating * maxRating);
    accumulator *= pow(pA, deltaCounter[i]) / pow(pRand, deltaCounter[i]);
  }
  
  double pRand = 2 / (double)(maxRating * maxRating);
  accumulator *= pow(pow(2, -maxRating + 1), deltaCounter[maxRating-1]) / pow(pRand, deltaCounter[maxRating-1]);
  
  return log10(accumulator);
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x150(%rsp)
movq %rsi, 0x148(%rsp)
movq %rdx, 0x140(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x80(%rsp)
movslq 0x14(%rax), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x124(%rsp)
leaq 0x123(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0xc120
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rcx
leaq 0x128(%rsp), %rdi
leaq 0x124(%rsp), %rdx
callq 0xc130
jmp 0xb072
leaq 0x123(%rsp), %rdi
callq 0xc1b0
movq 0x148(%rsp), %rdi
callq 0xc020
movq %rax, 0x108(%rsp)
movq 0x140(%rsp), %rdi
callq 0xc020
movq %rax, 0x100(%rsp)
movq 0x148(%rsp), %rdi
callq 0xc050
movq %rax, 0xf8(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x4f30
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x7f(%rsp)
jne 0xb0e2
jmp 0xb110
movq 0x140(%rsp), %rdi
callq 0xc050
movq %rax, 0xf0(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x4f30
movb %al, 0x7f(%rsp)
movb 0x7f(%rsp), %al
testb $0x1, %al
jne 0xb11d
jmp 0xb28d
xorps %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
movl %eax, 0x78(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xc080
movq %rax, %rcx
movl 0x78(%rsp), %eax
cmpl (%rcx), %eax
jge 0xb1a2
leaq 0x108(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0xd8(%rsp)
jmp 0xb288
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x123(%rsp), %rdi
callq 0xc1b0
jmp 0xb587
leaq 0x108(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
movl %eax, 0x74(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xc080
movq %rax, %rcx
movl 0x74(%rsp), %eax
cmpl (%rcx), %eax
jne 0xb26f
leaq 0x108(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xe8(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd 0xe8(%rsp), %xmm0
subsd 0xe0(%rsp), %xmm0
movaps 0x5e00(%rip), %xmm1     # 0x11020
pand %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movslq %eax, %rsi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x108(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0xd0(%rsp)
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0xc8(%rsp)
jmp 0xb286
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0xc0(%rsp)
jmp 0xb288
jmp 0xb0a9
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xb8(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movl (%rax), %edi
movsd 0x5f4e(%rip), %xmm0     # 0x11208
callq 0x8330
movsd %xmm0, 0x68(%rsp)
jmp 0xb2c7
movq 0x80(%rsp), %rax
cvtsi2sdl 0x14(%rax), %xmm1
movsd 0x5f34(%rip), %xmm0     # 0x11210
divsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movsd 0x58(%rsp), %xmm0
movl (%rax), %edi
callq 0x8330
movsd %xmm0, 0x60(%rsp)
jmp 0xb30c
movsd 0x60(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
divsd %xmm1, %xmm0
mulsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movl $0x1, 0xb4(%rsp)
movq 0x80(%rsp), %rcx
movl 0xb4(%rsp), %eax
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xb480
movl 0xb4(%rsp), %esi
notl %esi
movl $0x2, %edi
callq 0xc1e0
movsd %xmm0, 0x50(%rsp)
jmp 0xb371
movq 0x80(%rsp), %rax
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movl 0x14(%rax), %eax
movl 0xb4(%rsp), %edx
movl %eax, %ecx
subl %edx, %ecx
addl %ecx, %ecx
cvtsi2sd %ecx, %xmm0
imull %eax, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movslq 0xb4(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movsd 0x40(%rsp), %xmm0
movl (%rax), %edi
callq 0x8330
movsd %xmm0, 0x48(%rsp)
jmp 0xb3e9
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0xb4(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movsd 0x30(%rsp), %xmm0
movl (%rax), %edi
callq 0x8330
movsd %xmm0, 0x38(%rsp)
jmp 0xb422
movsd 0x38(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
divsd %xmm1, %xmm0
mulsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0xb339
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xc200
jmp 0xb587
movq 0x80(%rsp), %rax
movl 0x14(%rax), %ecx
imull %ecx, %ecx
cvtsi2sd %ecx, %xmm1
movsd 0x5d7e(%rip), %xmm0     # 0x11218
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movl 0x14(%rax), %eax
movl $0x1, %esi
subl %eax, %esi
movl $0x2, %edi
callq 0xc1e0
movsd %xmm0, 0x28(%rsp)
jmp 0xb4c3
movq 0x80(%rsp), %rax
movl 0x14(%rax), %eax
decl %eax
movslq %eax, %rsi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movsd 0x28(%rsp), %xmm0
movl (%rax), %edi
callq 0x8330
movsd %xmm0, 0x20(%rsp)
jmp 0xb4f5
movq 0x80(%rsp), %rax
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x14(%rax), %eax
decl %eax
movslq %eax, %rsi
leaq 0x128(%rsp), %rdi
callq 0xc1c0
movsd 0x10(%rsp), %xmm0
movl (%rax), %edi
callq 0x8330
movsd %xmm0, 0x18(%rsp)
jmp 0xb536
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm0
divsd %xmm1, %xmm0
mulsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0xb8(%rsp), %xmm0
callq 0x20c0
movsd %xmm0, 0x8(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xc200
movsd 0x8(%rsp), %xmm0
addq $0x158, %rsp            # imm = 0x158
retq
movq 0x118(%rsp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)