// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq 0x8(%rsi), %rax
subq (%rsi), %rax
movq 0x20(%rsi), %rcx
subq 0x18(%rsi), %rcx
cmpq %rcx, %rax
jne 0x3f4e
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x3fd3
leaq 0x68(%rdi), %rcx
movq %rcx, -0x58(%rbp)
leaq 0x88(%rdi), %rcx
movq %rcx, -0x80(%rbp)
leaq 0xa0(%rdi), %rcx
movq %rcx, -0x78(%rbp)
leaq 0xb8(%rdi), %rcx
movq %rcx, -0x70(%rbp)
xorl %edx, %edx
movq %rdi, -0x68(%rbp)
movl (%rax,%rdx,4), %eax
movl %eax, -0x30(%rbp)
movslq %eax, %rcx
movq %r13, %r15
movq 0x18(%r13), %rax
movq %rdx, -0x88(%rbp)
movl (%rax,%rdx,4), %r13d
movq %rcx, -0x60(%rbp)
cmpl %r13d, %ecx
jg 0x3d83
leal 0x1(%r13), %r14d
movq -0x60(%rbp), %rcx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rbx
addq $0x18, %rbx
movl -0x30(%rbp), %r12d
movq 0x48(%r15), %rax
movss (%rax,%rbx), %xmm0
ucomiss 0x4367(%rip), %xmm0     # 0x8080
jne 0x3d1d
jnp 0x3d77
movq -0x68(%rbp), %rdi
movq %r15, %rsi
movq -0x90(%rbp), %rdx
movl %r12d, %r9d
callq 0x415a
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x3d77
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x76f3
movq -0x48(%rbp), %rsi
cmpq %rsi, %rax
jne 0x3d77
cmpq -0x40(%rbp), %rsi
je 0x3d6a
movl -0x2c(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x3d77
leaq -0x50(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x62d2
incl %r12d
addq $0x1c, %rbx
cmpl %r12d, %r14d
jne 0x3d09
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq %rax, %rcx
je 0x3e30
leaq 0x4(%rax), %rdx
movq %rax, %rsi
cmpq %rcx, %rdx
movq -0x68(%rbp), %r14
je 0x3dc1
movq %rax, %rdi
movl (%rdx), %r8d
movq %rdx, %rsi
cmpl (%rdi), %r8d
jl 0x3db5
movq %rdi, %rsi
addq $0x4, %rdx
movq %rsi, %rdi
cmpq %rcx, %rdx
jne 0x3da7
movl (%rsi), %r12d
movl -0x30(%rbp), %edx
cmpl %r13d, %edx
jg 0x3e01
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
movq 0x48(%r15), %rcx
subl %edx, %r13d
incl %r13d
movq -0x60(%rbp), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
addq %rdx, %rcx
addq $0x18, %rcx
movss %xmm0, (%rcx)
addq $0x1c, %rcx
decl %r13d
jne 0x3df4
xorl %ebx, %ebx
movq %r15, %r13
movl (%rax,%rbx,4), %esi
movq %r14, %rdi
movl %r12d, %edx
callq 0x427e
incq %rbx
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
ja 0x3e06
jmp 0x3f19
movq -0x58(%rbp), %rax
movl (%rax), %eax
movl -0x30(%rbp), %edx
cmpl %r13d, %edx
movq -0x68(%rbp), %r14
jg 0x3e76
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movq 0x48(%r15), %rcx
subl %edx, %r13d
incl %r13d
movq -0x60(%rbp), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
addq %rdx, %rcx
addq $0x18, %rcx
movss %xmm0, (%rcx)
addq $0x1c, %rcx
decl %r13d
jne 0x3e69
incl %eax
movl %eax, 0x68(%r14)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq 0x90(%r14), %rsi
cmpq 0x98(%r14), %rsi
je 0x3ea9
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x90(%r14)
movq %r15, %r13
jmp 0x3eb9
movq -0x80(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x61b0
movq %r15, %r13
movq 0xa8(%r14), %rsi
cmpq 0xb0(%r14), %rsi
je 0x3edc
movl 0x68(%r14), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xa8(%r14)
jmp 0x3ee9
movq -0x78(%rbp), %rdi
movq -0x58(%rbp), %rdx
callq 0x62d2
movq 0xc0(%r14), %rsi
cmpq 0xc8(%r14), %rsi
je 0x3f0c
movl 0x68(%r14), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xc0(%r14)
jmp 0x3f19
movq -0x70(%rbp), %rdi
movq -0x58(%rbp), %rdx
callq 0x62d2
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x3f27
movq %rax, -0x48(%rbp)
movq -0x88(%rbp), %rdx
incq %rdx
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
ja 0x3cc5
jmp 0x3fd3
movq 0x7073(%rip), %rdi      # 0xafc8
leaq 0x417e(%rip), %rsi      # 0x80da
movl $0xd, %edx
callq 0x21d0
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x2, %rsi
movq 0x704f(%rip), %rdi      # 0xafc8
callq 0x2110
movq %rax, %r14
leaq 0x4160(%rip), %rsi      # 0x80e8
movl $0x2, %edx
movq %rax, %rdi
callq 0x21d0
movq 0x20(%r13), %rsi
subq 0x18(%r13), %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 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3fe8
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x21c0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4001
jmp 0x4001
jmp 0x4001
jmp 0x4001
jmp 0x4001
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x4019
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22b0
nop