// File: tylerwowen[P]movielens/./movielens/neighborsfinder.cpp
// Function: NeighborsLocator::cityBlockDistance(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::cityBlockDistance(Ratings_list &r1, Ratings_list &r2) {
  double distance = 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++;
    }
    distance += fabs(rating1 - rating2);
  }
  
  Rating last = iter1 == r1.cend() ? r1.back() : r2.back();
  Ratings_list::const_iterator activeIter = iter1 == r1.cend() ? iter2 : iter1,
  activeIterCend = iter1 == r1.cend() ? r2.cend() : r1.cend();
  
  while (activeIter != activeIterCend) {
    double rating1 = activeIter->second, rating2 = 0;
    if (activeIter->first != last.first) {
      rating2 = defaultRatingForItem(activeIter->first);
    }
    else {
      rating2 = last.second;
    }
    activeIter++;
    distance += fabs(rating1 - rating2);
  }
  
  return distance;
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xc8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0xc020
movq %rax, 0xc0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0xc020
movq %rax, 0xb8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0xc050
movq %rax, 0xb0(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4f30
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x27(%rsp)
jne 0xa15e
jmp 0xa18c
movq 0xd0(%rsp), %rdi
callq 0xc050
movq %rax, 0xa8(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x4f30
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0xa199
jmp 0xa34b
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
movl %eax, 0x20(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xc080
movq %rax, %rcx
movl 0x20(%rsp), %eax
cmpl (%rcx), %eax
jge 0xa234
leaq 0xc0(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x98(%rsp)
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x90(%rsp)
jmp 0xa317
leaq 0xc0(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xc080
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl (%rcx), %eax
jne 0xa2c5
leaq 0xc0(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x98(%rsp)
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x88(%rsp)
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x80(%rsp)
jmp 0xa315
leaq 0xb8(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0xa0(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x98(%rsp)
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x78(%rsp)
jmp 0xa317
movsd 0xa0(%rsp), %xmm0
subsd 0x98(%rsp), %xmm0
movaps 0x6cf0(%rip), %xmm1     # 0x11020
pand %xmm1, %xmm0
addsd 0xc8(%rsp), %xmm0
movsd %xmm0, 0xc8(%rsp)
jmp 0xa125
movq 0xd8(%rsp), %rdi
callq 0xc050
movq %rax, 0x60(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x4940
testb $0x1, %al
jne 0xa375
jmp 0xa389
movq 0xd8(%rsp), %rdi
callq 0xc0e0
movq %rax, 0x10(%rsp)
jmp 0xa39b
movq 0xd0(%rsp), %rdi
callq 0xc0e0
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x68(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0xd8(%rsp), %rdi
callq 0xc050
movq %rax, 0x50(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x4940
testb $0x1, %al
jne 0xa3db
jmp 0xa3ea
leaq 0xb8(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0xa3f9
leaq 0xc0(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0xa3f9
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq 0xd8(%rsp), %rdi
callq 0xc050
movq %rax, 0x40(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4940
testb $0x1, %al
jne 0xa430
jmp 0xa444
movq 0xd0(%rsp), %rdi
callq 0xc050
movq %rax, 0x48(%rsp)
jmp 0xa456
movq 0xd8(%rsp), %rdi
callq 0xc050
movq %rax, 0x48(%rsp)
jmp 0xa458
leaq 0x58(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x4f30
testb $0x1, %al
jne 0xa470
jmp 0xa508
leaq 0x58(%rsp), %rdi
callq 0xc080
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xc080
movl (%rax), %eax
cmpl 0x68(%rsp), %eax
je 0xa4bd
leaq 0x58(%rsp), %rdi
callq 0xc080
movl (%rax), %edi
callq 0xbbb0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
jmp 0xa4c9
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0xc0b0
movq %rax, 0x28(%rsp)
movsd 0x38(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
movaps 0x6b33(%rip), %xmm1     # 0x11020
pand %xmm1, %xmm0
addsd 0xc8(%rsp), %xmm0
movsd %xmm0, 0xc8(%rsp)
jmp 0xa458
movsd 0xc8(%rsp), %xmm0
addq $0xe8, %rsp
retq
nopl (%rax)