// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movslq 0x14(%rdi), %rsi
leaq 0x3c(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x40(%rsp), %rbx
leaq 0xf(%rsp), %rcx
movq %rbx, %rdi
callq 0x4c84
movq (%r12), %rax
movq (%r15), %rcx
cmpq %r12, %rax
setne %dl
cmpq %r15, %rcx
setne %sil
andb %dl, %sil
movq (%rbx), %rbx
cmpb $0x1, %sil
jne 0x45ad
movapd 0x1afa(%rip), %xmm0     # 0x6070
movl 0x10(%rcx), %edx
cmpl %edx, 0x10(%rax)
jge 0x4583
movq (%rax), %rax
jmp 0x45a3
jne 0x45a0
movsd 0x18(%rax), %xmm1
subsd 0x18(%rcx), %xmm1
andpd %xmm0, %xmm1
cvttsd2si %xmm1, %edx
movslq %edx, %rdx
incl (%rbx,%rdx,4)
movq (%rax), %rax
movq (%rcx), %rcx
cmpq %r12, %rax
je 0x45ad
cmpq %r15, %rcx
jne 0x4576
movl (%rbx), %ebp
movsd 0x1cd9(%rip), %xmm0     # 0x6290
movl %ebp, %edi
callq 0x22f0
movsd %xmm0, (%rsp)
movl 0x14(%r14), %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x1aa9(%rip), %xmm0     # 0x6080
movsd %xmm0, 0x10(%rsp)
divsd %xmm1, %xmm0
negl %ebp
movl %ebp, %edi
callq 0x22f0
mulsd (%rsp), %xmm0
leal -0x1(%r14), %ecx
movl %r14d, %eax
imull %r14d, %eax
cvtsi2sd %eax, %xmm2
cmpl $0x3, %r14d
movq %r14, 0x30(%rsp)
movl %ecx, 0x24(%rsp)
movsd %xmm2, 0x28(%rsp)
movsd %xmm0, (%rsp)
jl 0x46a4
movl %ecx, %r13d
movsd 0x10(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, 0x10(%rsp)
leal -0x2(,%r14,2), %r12d
movl $0x1, %r15d
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movsd 0x1c4e(%rip), %xmm0     # 0x6298
movl %ebp, %edi
callq 0x22f0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
movl (%rbx,%r15,4), %r14d
movl %r14d, %edi
callq 0x22f0
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
negl %r14d
movsd 0x18(%rsp), %xmm0
movl %r14d, %edi
callq 0x22f0
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
incq %r15
addl $-0x2, %r12d
decl %ebp
cmpq %r15, %r13
jne 0x4642
movsd 0x1bec(%rip), %xmm0     # 0x6298
movapd %xmm0, %xmm1
divsd 0x28(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
movl $0x1, %edi
subl 0x30(%rsp), %edi
callq 0x22f0
movslq 0x24(%rsp), %rax
movl (%rbx,%rax,4), %ebp
movl %ebp, %edi
callq 0x22f0
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
negl %ebp
movsd 0x18(%rsp), %xmm0
movl %ebp, %edi
callq 0x22f0
mulsd (%rsp), %xmm0
callq 0x20e0
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x21b0
movsd (%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop