// File: /workspace/github_cpp_makefile_star2_O2/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 0x5507
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x80(%rdi)
je 0x550e
movss 0x30(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x54ab
jnp 0x567b
xorl %r15d, %r15d
cmpq %r15, 0x48(%r14)
jbe 0x567b
movss 0x30(%rbx), %xmm0
movq (%r14), %rax
leaq (%rax,%r15,8), %rdi
addss (%rdi), %xmm0
movss %xmm0, (%rdi)
ucomiss 0x3029(%rip), %xmm0     # 0x84fc
movss 0x301d(%rip), %xmm1     # 0x84f8
jae 0x54ed
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
movss 0x3011(%rip), %xmm1     # 0x84fc
jbe 0x54f5
addss %xmm1, %xmm0
movss %xmm0, (%rdi)
callq 0x524c
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x54ae
xorl %eax, %eax
jmp 0x567e
leaq 0x38(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x10(%rbx), %rsi
leaq -0x270(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x3410
leaq 0x50(%rbx), %rax
movq %rax, -0x40(%rbp)
leaq -0x68(%rbp), %r15
leaq -0x30(%rbp), %r13
movq -0x270(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x250(%rbp,%rax)
jne 0x563a
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
leaq -0x270(%rbp), %rdi
movq %r15, %rsi
callq 0x3050
cmpq $0x0, -0x60(%rbp)
je 0x562d
movq -0x68(%rbp), %rax
cmpb $0x23, (%rax)
je 0x562d
andq $0x0, -0x30(%rbp)
leaq -0x3f8(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
pushq $0x18
popq %rdx
callq 0x33f0
movq %r12, %rdi
movq %r13, %rsi
callq 0x34f0
movq %rax, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x34f0
movss -0x2c(%rbp), %xmm0
ucomiss 0x6c(%rbx), %xmm0
movq 0x80(%rbx), %rax
jbe 0x55d6
movss %xmm0, 0x6c(%rbx)
movq %rax, 0x70(%rbx)
ucomiss 0x2f23(%rip), %xmm0     # 0x8500
jbe 0x55f2
movss 0x68(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x55f2
movss %xmm0, 0x68(%rbx)
movq %rax, 0x78(%rbx)
incq %rax
movq %rax, 0x80(%rbx)
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x5b1a
movq %r13, %rdi
callq 0x524c
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x6106
leaq -0x3f8(%rbp), %rdi
callq 0x3200
movq %r15, %rdi
callq 0x3130
jmp 0x5539
cmpq $0x0, 0x80(%rbx)
jne 0x5663
movq 0x69a5(%rip), %rdi      # 0xbff0
leaq 0x2eb2(%rip), %rsi      # 0x8504
callq 0x3290
movq %rax, %rdi
callq 0x3150
movb $0x0, 0x8(%rbx)
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x5b3e
leaq -0x270(%rbp), %rdi
callq 0x3090
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 0x56b6
jmp 0x56aa
jmp 0x5699
movq %rax, %rbx
leaq -0x3f8(%rbp), %rdi
callq 0x3200
jmp 0x56ad
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3130
leaq -0x270(%rbp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3480