// File: /workspace/github_cpp_makefile_star2_O1/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 0x680b
movq %rsi, %r14
movq %rdi, %rbx
callq 0x32f0
cmpq 0x240(%rbx), %rax
jge 0x64c1
callq 0x32f0
movq 0x240(%rbx), %rcx
subq %rax, %rcx
jle 0x64c1
jle 0x64c1
movq %rcx, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
shrq $0xb, %rdx
imulq $-0x3b9aca00, %rdx, %rax # imm = 0xC4653600
addq %rcx, %rax
leaq -0x200(%rbp), %r15
movq %rdx, (%r15)
movq %rax, 0x8(%r15)
movq %r15, %rdi
movq %r15, %rsi
callq 0x30a0
cmpl $-0x1, %eax
jne 0x64c1
callq 0x3040
cmpl $0x4, (%rax)
je 0x64a7
cmpq $0x0, 0x48(%r14)
jne 0x64d4
callq 0x32f0
movq %rax, 0x240(%rbx)
pxor %xmm0, %xmm0
leaq -0x200(%rbp), %rsi
movdqa %xmm0, 0x30(%rsi)
movdqa %xmm0, 0x40(%rsi)
movdqa %xmm0, 0x20(%rsi)
movdqa %xmm0, 0x10(%rsi)
movdqa %xmm0, (%rsi)
movq $0x7f7fffff, 0x30(%rsi) # imm = 0x7F7FFFFF
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x38(%rsi)
movq $0x0, 0x48(%rsi)
movq %r14, %rdi
callq 0x6bfa
leaq 0x18(%r14), %rdi
leaq -0x1e8(%rbp), %r15
movq %rdi, -0x78(%rbp)
movq %r15, %rsi
callq 0x6c40
movaps 0x18(%r15), %xmm0
movaps 0x28(%r15), %xmm1
movups %xmm1, 0x40(%r14)
movups %xmm0, 0x30(%r14)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x655a
movq -0x1d8(%rbp), %rsi
subq %rdi, %rsi
callq 0x3260
movq -0x200(%rbp), %rdi
testq %rdi, %rdi
je 0x6575
movq -0x1f0(%rbp), %rsi
subq %rdi, %rsi
callq 0x3260
leaq 0x30(%r14), %rax
movq %rax, -0x70(%rbp)
leaq 0x30(%rbx), %r15
leaq -0x58(%rbp), %r12
leaq -0x200(%rbp), %r13
movq 0x30(%rbx), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0x50(%rbx,%rcx)
jne 0x672e
leaq -0x48(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3450
movq $0x0, -0x38(%rbp)
movq %r13, %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x33a0
cmpq $0x0, -0x50(%rbp)
je 0x66ea
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x21, %eax
je 0x667c
cmpl $0x23, %eax
je 0x66ea
movq %r13, %rdi
leaq -0x38(%rbp), %rsi
callq 0x34b0
movq %rax, %rdi
leaq -0x34(%rbp), %rsi
callq 0x34b0
movss -0x34(%rbp), %xmm0
ucomiss 0x34(%r14), %xmm0
jbe 0x663c
movss %xmm0, 0x34(%r14)
movq 0x48(%r14), %rax
movq %rax, 0x38(%r14)
ucomiss 0x2de5(%rip), %xmm0     # 0x9428
jbe 0x6660
movq -0x70(%rbp), %rax
movss (%rax), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x6660
movss %xmm0, 0x30(%r14)
movq 0x48(%r14), %rax
movq %rax, 0x40(%r14)
incq 0x48(%r14)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x66c4
movq -0x38(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0x66d0
movq $0x0, -0x60(%rbp)
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
callq 0x32e0
movq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x3310
movq %rax, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3310
callq 0x32f0
imulq $0xf4240, -0x60(%rbp), %rcx # imm = 0xF4240
addq %rax, %rcx
movq %rcx, 0x240(%rbx)
movb $0x1, %r12b
jmp 0x66ed
movq %r14, %rdi
leaq -0x38(%rbp), %rdx
callq 0x6c86
leaq -0x38(%rbp), %rdi
callq 0x5c84
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6dac
xorl %r12d, %r12d
movq %r13, %rdi
movq 0x68b1(%rip), %rsi      # 0xcfa8
callq 0x3190
leaq -0x180(%rbp), %rdi
callq 0x30c0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6721
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3260
testb %r12b, %r12b
leaq -0x58(%rbp), %r12
je 0x658c
movq 0x238(%rbx), %rax
orq 0x48(%r14), %rax
jne 0x6782
movq 0x68ae(%rip), %r12      # 0xcff0
leaq 0x2ce3(%rip), %rsi      # 0x942c
movl $0x2b, %edx
movq %r12, %rdi
callq 0x32a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movb $0x0, 0x8(%rbx)
incq 0x238(%rbx)
cmpq $0x0, 0x48(%r14)
jne 0x6806
movq 0x6859(%rip), %r14      # 0xcff0
leaq 0x2cba(%rip), %rsi      # 0x9458
movl $0x11, %edx
movq %r14, %rdi
callq 0x32a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
addq $0x3b9aca00, 0x240(%rbx) # imm = 0x3B9ACA00
movq 0x30(%rbx), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x33f0
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32d0
movq %rbx, %rdi
callq 0x631c
movb %al, 0x8(%rbx)
movb 0x8(%rbx), %al
jmp 0x680d
xorl %eax, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6823
jmp 0x6823
movq %rax, %rbx
movq 0x677b(%rip), %rsi      # 0xcfa8
leaq -0x200(%rbp), %rdi
callq 0x3190
leaq -0x180(%rbp), %rdi
callq 0x30c0
jmp 0x684c
jmp 0x6849
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6865
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3430
nop