// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rsi, %r15
movq %rdi, %r14
movslq 0x14(%rdi), %rsi
leaq 0x3c(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x40(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x4d5c
movq (%r15), %rax
movq (%rbx), %rcx
cmpq %r15, %rax
setne %dl
cmpq %rbx, %rcx
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x465d
movq 0x40(%rsp), %rdx
movapd 0x1a4a(%rip), %xmm0     # 0x6070
movl 0x10(%rcx), %esi
cmpl %esi, 0x10(%rax)
jge 0x4633
movq (%rax), %rax
jmp 0x4653
jne 0x4650
movsd 0x18(%rax), %xmm1
subsd 0x18(%rcx), %xmm1
andpd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
incl (%rdx,%rsi,4)
movq (%rax), %rax
movq (%rcx), %rcx
cmpq %r15, %rax
je 0x465d
cmpq %rbx, %rcx
jne 0x4626
movq 0x40(%rsp), %rbx
movl (%rbx), %ebp
movsd 0x1c24(%rip), %xmm0     # 0x6290
movl %ebp, %edi
callq 0x22f0
movsd %xmm0, 0x8(%rsp)
movl 0x14(%r14), %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x19f3(%rip), %xmm0     # 0x6080
movsd %xmm0, 0x18(%rsp)
divsd %xmm1, %xmm0
negl %ebp
movl %ebp, %edi
callq 0x22f0
mulsd 0x8(%rsp), %xmm0
leal -0x1(%r14), %ecx
cmpl $0x3, %r14d
movq %r14, 0x30(%rsp)
movl %ecx, 0x2c(%rsp)
movsd %xmm0, 0x8(%rsp)
jl 0x475d
movl %r14d, %eax
imull %r14d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl %ecx, %r13d
movsd 0x18(%rsp), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x18(%rsp)
leal -0x2(,%r14,2), %r12d
movl $0x1, %r15d
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movsd 0x1b99(%rip), %xmm0     # 0x6298
movl %ebp, %edi
callq 0x22f0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd 0x18(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movl (%rbx,%r15,4), %r14d
movl %r14d, %edi
callq 0x22f0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
negl %r14d
movsd 0x20(%rsp), %xmm0
movl %r14d, %edi
callq 0x22f0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
incq %r15
addl $-0x2, %r12d
decl %ebp
cmpq %r15, %r13
jne 0x46f7
movq 0x30(%rsp), %rcx
movl %ecx, %eax
imull %ecx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x1b22(%rip), %xmm0     # 0x6298
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
movl $0x1, %edi
subl %ecx, %edi
callq 0x22f0
movslq 0x2c(%rsp), %rax
movl (%rbx,%rax,4), %ebp
movl %ebp, %edi
callq 0x22f0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
negl %ebp
movsd 0x20(%rsp), %xmm0
movl %ebp, %edi
callq 0x22f0
mulsd 0x8(%rsp), %xmm0
callq 0x20e0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x21b0
movsd 0x8(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq