// File: /workspace/github_cpp_makefile_star2_O3/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, -0x90(%rbp)
movq %rsi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
movq 0x20(%rsi), %rsi
subq 0x18(%r14), %rsi
cmpq %rsi, %rdx
movq %r14, -0x38(%rbp)
jne 0x3e56
cmpq %rax, %rcx
je 0x3ef7
movq %rdi, %r15
leaq 0x68(%rdi), %rcx
movq %rcx, -0x60(%rbp)
leaq 0x88(%rdi), %rcx
movq %rcx, -0x88(%rbp)
leaq 0xa0(%rdi), %rcx
movq %rcx, -0x80(%rbp)
leaq 0xb8(%rdi), %rcx
movq %rcx, -0x78(%rbp)
xorl %r13d, %r13d
movl (%rax,%r13,4), %r12d
movq 0x18(%r14), %rax
movq %r13, -0x70(%rbp)
movl (%rax,%r13,4), %r13d
cmpl %r13d, %r12d
jle 0x3c35
movq -0x60(%rbp), %rax
movl (%rax), %eax
incl %eax
movl %eax, 0x68(%r15)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq 0x90(%r15), %rsi
cmpq 0x98(%r15), %rsi
movq -0x70(%rbp), %r13
je 0x3d75
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x90(%r15)
jmp 0x3d85
movslq %r12d, %rax
leal 0x1(%r13), %r14d
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, -0x68(%rbp)
leaq (%rax,%rcx), %rbx
addq $0x18, %rbx
movl %r12d, -0x54(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movss (%rax,%rbx), %xmm0
ucomiss 0x4414(%rip), %xmm0     # 0x8080
jne 0x3c70
jnp 0x3cca
movq %r15, %rdi
movq -0x38(%rbp), %rsi
movq -0x90(%rbp), %rdx
movl %r12d, %r9d
callq 0x4072
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x3cca
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x74c7
movq -0x48(%rbp), %rsi
cmpq %rsi, %rax
jne 0x3cca
cmpq -0x40(%rbp), %rax
je 0x3cbd
movl -0x2c(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x3cca
leaq -0x50(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x618e
incl %r12d
addq $0x1c, %rbx
cmpl %r12d, %r14d
jne 0x3c58
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq %rax, %rcx
je 0x3e12
leaq 0x4(%rax), %rdx
movq %rax, %rsi
cmpq %rcx, %rdx
movq -0x38(%rbp), %r14
je 0x3d13
movl (%rax), %edi
movq %rax, %rsi
movl (%rdx), %r8d
cmpl %edi, %r8d
cmovll %r8d, %edi
cmovlq %rdx, %rsi
addq $0x4, %rdx
cmpq %rcx, %rdx
jne 0x3cfc
movl (%rsi), %r12d
movl -0x54(%rbp), %edx
cmpl %r13d, %edx
jg 0x3d48
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
movq 0x48(%r14), %rcx
subl %edx, %r13d
incl %r13d
movq -0x68(%rbp), %rdx
addq %rdx, %rcx
addq $0x18, %rcx
movss %xmm0, (%rcx)
addq $0x1c, %rcx
decl %r13d
jne 0x3d3b
xorl %ebx, %ebx
movq -0x70(%rbp), %r13
movl (%rax,%rbx,4), %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x4190
incq %rbx
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
ja 0x3d4e
jmp 0x3de5
movq -0x88(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x606c
movq 0xa8(%r15), %rsi
cmpq 0xb0(%r15), %rsi
je 0x3da8
movl 0x68(%r15), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xa8(%r15)
jmp 0x3db5
movq -0x80(%rbp), %rdi
movq -0x60(%rbp), %rdx
callq 0x618e
movq 0xc0(%r15), %rsi
cmpq 0xc8(%r15), %rsi
je 0x3dd8
movl 0x68(%r15), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xc0(%r15)
jmp 0x3de5
movq -0x78(%rbp), %rdi
movq -0x60(%rbp), %rdx
callq 0x618e
movq -0x50(%rbp), %rdi
cmpq %rdi, -0x48(%rbp)
je 0x3df3
movq %rdi, -0x48(%rbp)
incq %r13
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
ja 0x3bdf
jmp 0x3ee6
movq -0x60(%rbp), %rax
movl (%rax), %eax
movl -0x54(%rbp), %edx
cmpl %r13d, %edx
movq -0x38(%rbp), %r14
jg 0x3bfa
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movq 0x48(%r14), %rcx
subl %edx, %r13d
incl %r13d
movq -0x68(%rbp), %rdx
addq %rdx, %rcx
addq $0x18, %rcx
movss %xmm0, (%rcx)
addq $0x1c, %rcx
decl %r13d
jne 0x3e44
jmp 0x3bfa
movq 0x716b(%rip), %rdi      # 0xafc8
leaq 0x4276(%rip), %rsi      # 0x80da
movl $0xd, %edx
callq 0x21c0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x2, %rsi
movq 0x7144(%rip), %rdi      # 0xafc8
callq 0x2110
movq %rax, %r14
leaq 0x4255(%rip), %rsi      # 0x80e8
movl $0x2, %edx
movq %rax, %rdi
callq 0x21c0
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rsi
subq 0x18(%rax), %rsi
sarq $0x2, %rsi
movq %r14, %rdi
callq 0x2110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3ef7
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3f10
jmp 0x3f10
jmp 0x3f10
jmp 0x3f10
jmp 0x3f10
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3f28
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x22a0