// File: /workspace/github_cpp_makefile_star2_O3/mitchellsayer[P]FastPointCloudSegmentation/src/./point_cloud_segmenter.cc
// Function: PointCloudSegmenter::FindRuns(Scanline&)
void PointCloudSegmenter::FindRuns(Scanline& cur_scanline) {
  int i = 0;

  std::vector<Vec3>::iterator it;

  while (cur_scanline.points[i].label == -3) {
    i++;
  }

  if (i < cur_scanline.points.size() ) {
    cur_scanline.s_queue.push_back(i);

    if (i == cur_scanline.points.size() - 1){
      cur_scanline.e_queue.push_back(i);
      return;
    }

    i += 1;
  } else {
    return;
  }

  for (; i < cur_scanline.points.size(); i++) {
    Vec3* cur_p = &cur_scanline.points[i];
    Vec3* prev_p = &cur_scanline.points[i-1];

    if (cur_p->label != -3) {

      if (prev_p->label == -3) {
        //Start new run if immediately after gnd pt
        cur_scanline.s_queue.push_back(i);
        if (i == cur_scanline.points.size() - 1) {
          cur_scanline.e_queue.push_back(i);
        }
      } else {
        //check distance to prev point
        if ( (cur_scanline.points[i]).distance(cur_scanline.points[i-1]) > this->th_run ) {
          cur_scanline.e_queue.push_back(i - 1);
          cur_scanline.s_queue.push_back(i);
        }

        if (i == cur_scanline.points.size() - 1) {
            cur_scanline.e_queue.push_back(i);
        }
      }
    } else {
      //Current point is ground & previous point is not
      //then end that run
      if (prev_p->label != -3) {
        cur_scanline.e_queue.push_back(i-1);
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rsi), %rax
leaq 0x18(%rax), %rdx
movq $-0x1, %rcx
movss 0x4824(%rip), %xmm3     # 0x8080
movss (%rdx), %xmm0
incq %rcx
addq $0x1c, %rdx
ucomiss %xmm3, %xmm0
jne 0x386e
jnp 0x385c
movl %ecx, -0x2c(%rbp)
movq 0x50(%rbx), %rdx
movq %rdx, %r8
subq %rax, %r8
sarq $0x2, %r8
movabsq $0x6db6db6db6db6db7, %r13 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r13, %r8
cmpq %rcx, %r8
jbe 0x3b11
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x38ac
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x38d6
leaq -0x2c(%rbp), %rdx
movq %rbx, %rdi
callq 0x618e
movss 0x47c0(%rip), %xmm3     # 0x8080
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
movq %rdx, %r8
subq %rax, %r8
sarq $0x2, %r8
imulq %r13, %r8
movl -0x2c(%rbp), %edi
movslq %edi, %rcx
leaq -0x1(%r8), %rsi
cmpq %rcx, %rsi
jne 0x3902
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x3b01
movl %edi, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x3b11
incq %rcx
movl %ecx, -0x2c(%rbp)
cmpq %rcx, %r8
jbe 0x3b11
leaq 0x18(%rbx), %r15
leaq -0x2c(%rbp), %r12
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
movslq %edi, %r9
leaq (%r9,%r9,8), %r8
leaq (%r8,%r8,2), %r8
addq %r9, %r8
movss 0x18(%rax,%rsi), %xmm0
ucomiss %xmm3, %xmm0
movss 0x18(%rax,%r8), %xmm0
jne 0x3946
jnp 0x396a
ucomiss %xmm3, %xmm0
jne 0x398d
jp 0x398d
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x39f6
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3a11
ucomiss %xmm3, %xmm0
jne 0x3975
jnp 0x3ad3
movl %edi, -0x30(%rbp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x3a3e
movl %edi, (%rsi)
jmp 0x3ab6
addq %rax, %rsi
addq %rax, %r8
movss (%rsi), %xmm0
subss (%r8), %xmm0
movss 0x4(%rsi), %xmm1
subss 0x4(%r8), %xmm1
movss 0x8(%rsi), %xmm2
subss 0x8(%r8), %xmm2
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
mulss %xmm2, %xmm2
addss %xmm0, %xmm2
xorps %xmm0, %xmm0
sqrtss %xmm2, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x70(%r14), %xmm0
jbe 0x3a8f
movl %edi, -0x34(%rbp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x3a4c
movl %edi, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x3a60
movq %rbx, %rdi
movq %r12, %rdx
callq 0x618e
movss 0x4677(%rip), %xmm3     # 0x8080
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
movslq -0x2c(%rbp), %rax
sarq $0x2, %rdx
imulq %r13, %rdx
decq %rdx
cmpq %rax, %rdx
jne 0x3ad3
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x3ac0
movl %eax, (%rsi)
jmp 0x3ab6
movq %r15, %rdi
leaq -0x30(%rbp), %rdx
callq 0x606c
jmp 0x3acb
movq %r15, %rdi
leaq -0x34(%rbp), %rdx
callq 0x606c
movss 0x4620(%rip), %xmm3     # 0x8080
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3a79
movl -0x2c(%rbp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3a8f
movq %rbx, %rdi
movq %r12, %rdx
callq 0x618e
movss 0x45f4(%rip), %xmm3     # 0x8080
movl -0x2c(%rbp), %ecx
movslq %ecx, %rax
movq 0x50(%rbx), %rdx
subq 0x48(%rbx), %rdx
sarq $0x2, %rdx
imulq %r13, %rdx
decq %rdx
cmpq %rax, %rdx
jne 0x3ad3
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x3ac0
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x3ad3
movq %r15, %rdi
movq %r12, %rdx
callq 0x618e
movss 0x45ad(%rip), %xmm3     # 0x8080
movslq -0x2c(%rbp), %rdi
movq %rdi, %rcx
incq %rcx
movl %ecx, -0x2c(%rbp)
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
movq %rdx, %rsi
subq %rax, %rsi
sarq $0x2, %rsi
imulq %r13, %rsi
cmpq %rcx, %rsi
ja 0x3919
jmp 0x3b11
addq $0x18, %rbx
leaq -0x2c(%rbp), %rdx
movq %rbx, %rdi
callq 0x618e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq