// File: /workspace/github_cpp_makefile_star2_O2/mitchellsayer[P]FastPointCloudSegmentation/src/./point_cloud_segmenter.cc
// Function: PointCloudSegmenter::UpdateLabels(Scanline&, Scanline&)
void PointCloudSegmenter::UpdateLabels(Scanline &scan_current, Scanline &scan_above) {
  std::vector<int> labels_to_merge;
  std::vector<int>::iterator i_it;
  int start_index;
  int end_index;

  if (scan_current.s_queue.size() != scan_current.e_queue.size()) {
    std:: cout << "Start & End: " << scan_current.s_queue.size() << "  " << scan_current.e_queue.size() << std::endl;
    return;
  }

  for (int i = 0; i < scan_current.s_queue.size(); i++) {
    start_index = scan_current.s_queue[i];
    end_index = scan_current.e_queue[i];

    for (int k = start_index; k <= end_index; k++) {
      if (scan_current.points[k].label != -3) {
        int nearest_label = FindNearestNeighbor(scan_current, scan_above, start_index, end_index, k);

        if (nearest_label != -1 && std::find(labels_to_merge.begin(), labels_to_merge.end(), nearest_label) == labels_to_merge.end()) {
          labels_to_merge.push_back( nearest_label );
        }
      }
    }

    if (labels_to_merge.size() == 0) {
      SetRunLabel(scan_current, start_index, end_index, this->new_label);
      this->new_label += 1;
      this->next.push_back(-1);
      this->tail.push_back(this->new_label);
      this->rtable.push_back(this->new_label);
    }

    else {
      int min_label = *std::min_element(labels_to_merge.begin(), labels_to_merge.end());;

      SetRunLabel(scan_current, start_index, end_index, min_label);
      MergeLabels(labels_to_merge, min_label);
    }

    labels_to_merge.clear();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, -0x88(%rbp)
movq %rsi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
movq 0x20(%rsi), %rsi
subq 0x18(%rbx), %rsi
cmpq %rsi, %rdx
jne 0x3475
movq %rdi, %r15
leaq 0x68(%rdi), %r14
leaq 0x88(%rdi), %rdx
movq %rdx, -0x78(%rbp)
leaq 0xa0(%rdi), %rdx
movq %rdx, -0x70(%rbp)
leaq 0xb8(%rdi), %rdx
movq %rdx, -0x68(%rbp)
xorl %r12d, %r12d
movq %r14, -0x80(%rbp)
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
jbe 0x34c6
movslq (%rax,%r12,4), %r13
movq 0x18(%rbx), %rax
movq %r12, -0x58(%rbp)
movslq (%rax,%r12,4), %r12
imulq $0x1c, %r13, %r14
addq $0x18, %r14
movq %r13, -0x60(%rbp)
cmpq %r12, %r13
jg 0x33d6
movq 0x48(%rbx), %rax
movss (%rax,%r14), %xmm0
ucomiss 0x3d00(%rip), %xmm0     # 0x7088
jne 0x338c
jnp 0x33cd
movq %r15, %rdi
movq %rbx, %rsi
movq -0x88(%rbp), %rdx
movl %r13d, %r9d
callq 0x35fe
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x33cd
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x68cc
cmpq -0x48(%rbp), %rax
jne 0x33cd
leaq -0x50(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x3dd6
incq %r13
addq $0x1c, %r14
jmp 0x3372
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
cmpq %rdi, %rsi
je 0x3412
callq 0x4719
movl (%rax), %r13d
movq %rbx, %rsi
movq -0x60(%rbp), %rdx
movl %r12d, %ecx
movl %r13d, %r8d
callq 0x32a0
movq %r15, %rdi
leaq -0x50(%rbp), %rsi
movl %r13d, %edx
callq 0x36b6
movq -0x58(%rbp), %r12
jmp 0x3458
movq -0x80(%rbp), %r14
movl (%r14), %r8d
movq %rbx, %rsi
movq -0x60(%rbp), %rdx
movl %r12d, %ecx
callq 0x32a0
incl (%r14)
orl $-0x1, -0x2c(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x5474
movq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0x3dd6
movq -0x58(%rbp), %r12
movq -0x68(%rbp), %rdi
movq %r14, %rsi
callq 0x3dd6
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x3466
movq %rax, -0x48(%rbp)
incq %r12
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
jmp 0x3346
movq 0x7b4c(%rip), %rdi      # 0xafc8
leaq 0x3c5f(%rip), %rsi      # 0x70e2
callq 0x2190
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x2120
leaq 0x3c4e(%rip), %rsi      # 0x70f0
movq %rax, %rdi
callq 0x2190
movq 0x20(%rbx), %rsi
subq 0x18(%rbx), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20b0
leaq -0x50(%rbp), %rdi
callq 0x48c2
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x34ea
jmp 0x34ea
jmp 0x34ea
jmp 0x34ea
jmp 0x34ea
jmp 0x34ea
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x48c2
movq %rbx, %rdi
callq 0x2290