// File: /workspace/github_cpp_makefile_star2_O1/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 0x5fb2
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x80(%rdi)
je 0x5fb9
movss 0x30(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x5f41
jnp 0x61e3
cmpq $0x0, 0x48(%r14)
je 0x61e3
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 0x34b3(%rip), %xmm0     # 0x9424
movss 0x34a7(%rip), %xmm1     # 0x9420
jae 0x5f8b
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
movss 0x349b(%rip), %xmm1     # 0x9424
jbe 0x5f93
addss %xmm1, %xmm0
movss %xmm0, (%rdi)
callq 0x5c84
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r15)
incq %r12
addq $0x8, %r15
cmpq %r12, 0x48(%r14)
ja 0x5f52
jmp 0x61e3
xorl %eax, %eax
jmp 0x61e6
leaq 0x38(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x10(%rbx), %rsi
leaq -0x3f8(%rbp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x33c0
movq (%r12), %rax
movq -0x18(%rax), %rcx
testb $0x5, -0x3d8(%rbp,%rcx)
jne 0x6158
addq $-0x18, %rax
leaq 0x50(%rbx), %rcx
movq %rcx, -0x60(%rbp)
leaq -0x30(%rbp), %r13
leaq -0x40(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
movq (%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %r12, %rdi
leaq -0x50(%rbp), %rsi
callq 0x3450
cmpq $0x0, -0x48(%rbp)
je 0x6122
movq -0x50(%rbp), %rax
cmpb $0x23, (%rax)
je 0x6122
movq $0x0, -0x30(%rbp)
leaq -0x1f0(%rbp), %r15
movq %r15, %rdi
leaq -0x50(%rbp), %rsi
movl $0x18, %edx
callq 0x33a0
movq %r15, %rdi
movq %r13, %rsi
callq 0x34b0
movq %rax, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x34b0
movss -0x2c(%rbp), %xmm0
ucomiss 0x6c(%rbx), %xmm0
jbe 0x609c
movss %xmm0, 0x6c(%rbx)
movq 0x80(%rbx), %rax
movq %rax, 0x70(%rbx)
ucomiss 0x3385(%rip), %xmm0     # 0x9428
jbe 0x60bf
movss 0x68(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x60bf
movss %xmm0, 0x68(%rbx)
movq 0x80(%rbx), %rax
movq %rax, 0x78(%rbx)
incq 0x80(%rbx)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x60de
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x40(%rbx)
jmp 0x60ea
movq -0x58(%rbp), %rdi
movq %r13, %rdx
callq 0x6c86
movq %r13, %rdi
callq 0x5c84
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6dac
leaq -0x1f0(%rbp), %rdi
movq 0x6e97(%rip), %rsi      # 0xcfa8
callq 0x3190
leaq -0x170(%rbp), %rdi
callq 0x30c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x613b
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 0x5fff
cmpq $0x0, 0x80(%rbx)
jne 0x61ac
movq 0x6e87(%rip), %r15      # 0xcff0
leaq 0x32bc(%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 0x6e55(%rip), %rdi      # 0xcff0
callq 0x3030
movq %rax, %rdi
callq 0x3170
movb $0x0, 0x8(%rbx)
movq %r14, %rdi
movq -0x58(%rbp), %rsi
callq 0x69d2
leaq 0x18(%r14), %rdi
leaq 0x50(%rbx), %rsi
callq 0x6ac8
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 0x6241
jmp 0x6225
jmp 0x6201
movq %rax, %rbx
movq 0x6d9d(%rip), %rsi      # 0xcfa8
leaq -0x1f0(%rbp), %rdi
callq 0x3190
leaq -0x170(%rbp), %rdi
callq 0x30c0
jmp 0x6228
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6241
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
leaq -0x3f8(%rbp), %rdi
callq 0x3070
movq %rbx, %rdi
callq 0x3430
nop