// File: /workspace/github_cpp_makefile_star2_O3/knei-knurow[P]lidar-visualizations/src/cloud-grabbers.cpp
// Function: CloudFileGrabber::read(Cloud&)
bool CloudFileGrabber::read(Cloud& cloud) {
  if (!status_)
    return false;

  if (cloud_.size == 0) {
    std::ifstream file(filename_);
    while (file) {
      std::string line;
      std::getline(file, line);
      if (line.empty() || line[0] == '#')
        continue;
      PointCyl pt_cyl;
      std::stringstream sline(line);
      sline >> pt_cyl.angle >> pt_cyl.dist;

      if (pt_cyl.dist > cloud_.max) {
        cloud_.max = pt_cyl.dist;
        cloud_.max_idx = cloud_.size;
      }
      if (pt_cyl.dist < cloud_.min && pt_cyl.dist > 0) {
        cloud_.min = pt_cyl.dist;
        cloud_.min_idx = cloud_.size;
      }

      cloud_.size++;
      cloud_.pts_cyl.push_back(pt_cyl);
      cloud_.pts_cart.push_back(pt_cyl.to_cart());
    }

    if (cloud_.size == 0) {
      std::cerr << "Error: File does not contain a valid cloud." << std::endl;
      status_ = false;
    }
    cloud = cloud_;
  } else if (rot_angle_ != 0.0f) {
    for (int i = 0; i < cloud.size; i++) {
      cloud.pts_cyl[i].angle += rot_angle_;
      if (cloud.pts_cyl[i].angle >= 360.0f) {
        cloud.pts_cyl[i].angle -= 360.0f;
      } else if (cloud.pts_cyl[i].angle < 0.0f) {
        cloud.pts_cyl[i].angle += 360.0f;
      }
      cloud.pts_cart[i] = cloud.pts_cyl[i].to_cart();
    }
  }

  return status_;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
cmpb $0x1, 0x8(%rdi)
jne 0x602e
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x80(%rdi)
je 0x6035
movss 0x30(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x5fbd
jnp 0x625b
cmpq $0x0, 0x48(%r14)
je 0x625b
xorl %r15d, %r15d
xorl %r12d, %r12d
movss 0x30(%rbx), %xmm0
movq (%r14), %rax
leaq (%rax,%r15), %rdi
addss (%rax,%r15), %xmm0
movss %xmm0, (%rax,%r15)
ucomiss 0x3437(%rip), %xmm0     # 0x9424
movss 0x342b(%rip), %xmm1     # 0x9420
jae 0x6007
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
movss 0x341f(%rip), %xmm1     # 0x9424
jbe 0x600f
addss %xmm1, %xmm0
movss %xmm0, (%rdi)
callq 0x5d00
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r15)
incq %r12
addq $0x8, %r15
cmpq %r12, 0x48(%r14)
ja 0x5fce
jmp 0x625b
xorl %eax, %eax
jmp 0x625e
leaq 0x38(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x10(%rbx), %rsi
leaq -0x3f8(%rbp), %r13
movq %r13, %rdi
movl $0x8, %edx
callq 0x33c0
movq (%r13), %rax
movq -0x18(%rax), %rcx
testb $0x5, -0x3d8(%rbp,%rcx)
jne 0x61d0
addq $-0x18, %rax
leaq 0x50(%rbx), %rcx
movq %rcx, -0x60(%rbp)
leaq -0x30(%rbp), %r12
leaq -0x40(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
movq (%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %r13, %rdi
leaq -0x50(%rbp), %rsi
callq 0x3450
cmpq $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rdi
je 0x619e
cmpb $0x23, (%rdi)
je 0x619e
movq $0x0, -0x30(%rbp)
leaq -0x1f0(%rbp), %r15
movq %r15, %rdi
leaq -0x50(%rbp), %rsi
movl $0x18, %edx
callq 0x33a0
movq %r15, %rdi
movq %r12, %rsi
callq 0x34b0
movq %rax, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x34b0
movss -0x2c(%rbp), %xmm0
ucomiss 0x6c(%rbx), %xmm0
movq 0x80(%rbx), %rax
jbe 0x6118
movss %xmm0, 0x6c(%rbx)
movq %rax, 0x70(%rbx)
ucomiss 0x3309(%rip), %xmm0     # 0x9428
jbe 0x6134
movss 0x68(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x6134
movss %xmm0, 0x68(%rbx)
movq %rax, 0x78(%rbx)
incq %rax
movq %rax, 0x80(%rbx)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x6156
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x40(%rbx)
jmp 0x6162
movq -0x58(%rbp), %rdi
movq %r12, %rdx
callq 0x6c4a
movq %r12, %rdi
callq 0x5d00
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6d70
leaq -0x1f0(%rbp), %rdi
movq 0x6e1f(%rip), %rsi      # 0xcfa8
callq 0x3190
leaq -0x170(%rbp), %rdi
callq 0x30c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x61b3
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
movq -0x3f8(%rbp), %rax
movq -0x18(%rax), %rcx
addq $-0x18, %rax
testb $0x5, -0x3d8(%rbp,%rcx)
je 0x607b
cmpq $0x0, 0x80(%rbx)
jne 0x6224
movq 0x6e0f(%rip), %r15      # 0xcff0
leaq 0x3244(%rip), %rsi      # 0x942c
movl $0x2b, %edx
movq %r15, %rdi
callq 0x32a0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x6ddd(%rip), %rdi      # 0xcff0
callq 0x3030
movq %rax, %rdi
callq 0x3170
movb $0x0, 0x8(%rbx)
movq %r14, %rdi
movq -0x58(%rbp), %rsi
callq 0x6a1e
leaq 0x18(%r14), %rdi
leaq 0x50(%rbx), %rsi
callq 0x6b16
movups 0x68(%rbx), %xmm0
movups 0x78(%rbx), %xmm1
movups %xmm1, 0x40(%r14)
movups %xmm0, 0x30(%r14)
leaq -0x3f8(%rbp), %rdi
callq 0x3070
movb 0x8(%rbx), %al
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x62b9
jmp 0x629d
jmp 0x6279
movq %rax, %rbx
movq 0x6d25(%rip), %rsi      # 0xcfa8
leaq -0x1f0(%rbp), %rdi
callq 0x3190
leaq -0x170(%rbp), %rdi
callq 0x30c0
jmp 0x62a0
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x62b9
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
leaq -0x3f8(%rbp), %rdi
callq 0x3070
movq %rbx, %rdi
callq 0x3430
nop