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

  if (std::chrono::steady_clock::now() < next_cloud_time_)
    std::this_thread::sleep_until(next_cloud_time_);

  if (cloud.size == 0)
    next_cloud_time_ = std::chrono::steady_clock::now();

  cloud = Cloud();
  while (file_.good()) {
    std::string line;
    std::getline(file_, line);
    PointCyl pt_cyl;
    std::stringstream sline(line);

    if (line.empty() || line[0] == '#') {
      continue;
    } else if (line[0] == '!') {
      long long _, delay_ms = 0;
      char __;
      sline >> __ >> _ >> delay_ms;
      next_cloud_time_ = std::chrono::steady_clock::now() + std::chrono::milliseconds(delay_ms);
      break;
    }
    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 && clouds_cnt_ == 0) {
    std::cerr << "Error: File does not contain a valid cloud." << std::endl;
    status_ = false;
  }

  clouds_cnt_++;

  if (cloud.size == 0) {
    std::cerr << "Cloud series end." << std::endl;
    next_cloud_time_ += std::chrono::milliseconds(1000);
    file_.clear();
    file_.seekg(0);
    status_ = open();
  }

  return status_;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
cmpb $0x1, 0x8(%rdi)
jne 0x59db
movq %rsi, %r14
movq %rdi, %rbx
callq 0x3330
leaq 0x240(%rbx), %r15
cmpq 0x240(%rbx), %rax
jge 0x5879
movq %r15, %rdi
callq 0x5b77
cmpq $0x0, 0x48(%r14)
jne 0x5888
callq 0x3330
movq %rax, (%r15)
movq %r15, -0x70(%rbp)
pxor %xmm0, %xmm0
leaq -0x200(%rbp), %r13
movdqa %xmm0, 0x20(%r13)
movdqa %xmm0, 0x10(%r13)
movdqa %xmm0, (%r13)
movq $0x7f7fffff, 0x30(%r13) # imm = 0x7F7FFFFF
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x38(%r13)
andq $0x0, 0x48(%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0x5ba0
movq %r13, %rdi
callq 0x4dbe
leaq 0x30(%rbx), %r15
leaq 0x18(%r14), %rax
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %r12
movq 0x30(%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x50(%rbx,%rax)
jne 0x5a3b
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3050
andq $0x0, -0x34(%rbp)
movq %r13, %rdi
movq %r12, %rsi
pushq $0x18
popq %rdx
callq 0x33f0
cmpq $0x0, -0x60(%rbp)
je 0x59c6
movq -0x68(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x23, %eax
je 0x59c6
cmpl $0x21, %eax
je 0x59e2
movq %r13, %rdi
leaq -0x34(%rbp), %rsi
callq 0x34f0
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x34f0
movss -0x30(%rbp), %xmm0
ucomiss 0x34(%r14), %xmm0
movq 0x48(%r14), %rax
jbe 0x597b
movss %xmm0, 0x34(%r14)
movq %rax, 0x38(%r14)
ucomiss 0x2b7e(%rip), %xmm0     # 0x8500
jbe 0x5999
movss 0x30(%r14), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x5999
movss %xmm0, 0x30(%r14)
movq %rax, 0x40(%r14)
incq %rax
movq %rax, 0x48(%r14)
movq %r14, %rdi
leaq -0x34(%rbp), %rsi
callq 0x5b1a
leaq -0x34(%rbp), %rdi
callq 0x524c
movq %rax, -0x48(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x6106
movq %r13, %rdi
callq 0x3200
movq %r12, %rdi
callq 0x3130
jmp 0x58e3
xorl %eax, %eax
jmp 0x5adb
andq $0x0, -0x40(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x3320
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x3360
leaq -0x40(%rbp), %rsi
movq %rax, %rdi
callq 0x3360
callq 0x3330
imulq $0xf4240, -0x40(%rbp), %rcx # imm = 0xF4240
addq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, (%rax)
leaq -0x200(%rbp), %rdi
callq 0x3200
leaq -0x68(%rbp), %rdi
callq 0x3130
movq 0x48(%r14), %rax
movq 0x238(%rbx), %rcx
movq %rcx, %rdx
orq %rax, %rdx
jne 0x5a78
movq 0x659b(%rip), %rdi      # 0xbff0
leaq 0x2aa8(%rip), %rsi      # 0x8504
callq 0x3290
movq %rax, %rdi
callq 0x3150
movb $0x0, 0x8(%rbx)
movq 0x238(%rbx), %rcx
movq 0x48(%r14), %rax
incq %rcx
movq %rcx, 0x238(%rbx)
testq %rax, %rax
je 0x5a8c
movb 0x8(%rbx), %al
jmp 0x5adb
movq 0x655d(%rip), %rdi      # 0xbff0
leaq 0x2a96(%rip), %rsi      # 0x8530
callq 0x3290
movq %rax, %rdi
callq 0x3150
addq $0x3b9aca00, 0x240(%rbx) # imm = 0x3B9ACA00
movq 0x30(%rbx), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x3440
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3300
movq %rbx, %rdi
callq 0x5770
movb %al, 0x8(%rbx)
andb $0x1, %al
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5af3
jmp 0x5af3
movq %rax, %rbx
leaq -0x200(%rbp), %rdi
callq 0x3200
jmp 0x5b09
jmp 0x5b06
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3480