// File: 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
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x14(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x57d0
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movslq -0x14(%rbp), %rsi
callq 0x69e0
movss 0x18(%rax), %xmm0
movss 0xde03(%rip), %xmm1     # 0x1200c
ucomiss %xmm1, %xmm0
jne 0x421b
jp 0x421b
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x41eb
movslq -0x14(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x5780
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jae 0x428f
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x5eb0
movslq -0x14(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x5780
movq %rax, %rcx
movq -0x70(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x4284
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x14(%rbp), %rsi
callq 0x5eb0
jmp 0x449e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4294
jmp 0x449e
jmp 0x4296
movslq -0x14(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x5780
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x449e
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movslq -0x14(%rbp), %rsi
callq 0x69e0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x69e0
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movss 0x18(%rax), %xmm0
movss 0xdd11(%rip), %xmm1     # 0x1200c
ucomiss %xmm1, %xmm0
jne 0x4307
jp 0x4307
jmp 0x4458
movq -0x30(%rbp), %rax
movss 0x18(%rax), %xmm0
movss 0xdcf4(%rip), %xmm1     # 0x1200c
ucomiss %xmm1, %xmm0
jne 0x4367
jp 0x4367
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x5eb0
movslq -0x14(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x5780
movq %rax, %rcx
movq -0x80(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x4362
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x14(%rbp), %rsi
callq 0x5eb0
jmp 0x4456
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movslq -0x14(%rbp), %rsi
callq 0x69e0
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x69e0
movq -0x88(%rbp), %rdi
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x40(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
leaq -0x50(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movl 0x18(%rax), %eax
movl %eax, 0x18(%rsp)
callq 0x6a00
movq -0x60(%rbp), %rax
cvtss2sd %xmm0, %xmm0
ucomisd 0x70(%rax), %xmm0
jbe 0x4418
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
leaq -0x54(%rbp), %rsi
callq 0x5e80
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x5eb0
movslq -0x14(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x5780
movq %rax, %rcx
movq -0x90(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x4454
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x14(%rbp), %rsi
callq 0x5eb0
jmp 0x4456
jmp 0x448e
movq -0x30(%rbp), %rax
movss 0x18(%rax), %xmm0
movss 0xdba3(%rip), %xmm1     # 0x1200c
ucomiss %xmm1, %xmm0
jne 0x4472
jp 0x4472
jmp 0x448c
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x5e80
jmp 0x448e
jmp 0x4490
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4296
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)