// File: /workspace/github_cpp_makefile_star2_O3/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 0x67e3
movq %rsi, %r14
movq %rdi, %rbx
callq 0x32f0
cmpq 0x240(%rbx), %rax
jge 0x653b
callq 0x32f0
movq 0x240(%rbx), %rcx
subq %rax, %rcx
jle 0x653b
jle 0x653b
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 -0x1f8(%rbp), %r15
movq %rdx, (%r15)
movq %rax, 0x8(%r15)
movq %r15, %rdi
movq %r15, %rsi
callq 0x30a0
cmpl $-0x1, %eax
jne 0x653b
callq 0x3040
cmpl $0x4, (%rax)
je 0x6521
cmpq $0x0, 0x48(%r14)
jne 0x654e
callq 0x32f0
movq %rax, 0x240(%rbx)
movq (%r14), %rdi
movq 0x10(%r14), %rsi
pxor %xmm0, %xmm0
movdqu %xmm0, (%r14)
movq $0x0, 0x10(%r14)
testq %rdi, %rdi
je 0x6577
subq %rdi, %rsi
callq 0x3260
pxor %xmm0, %xmm0
movq 0x18(%r14), %rdi
movq 0x28(%r14), %rsi
movdqu %xmm0, 0x18(%r14)
movq $0x0, 0x28(%r14)
testq %rdi, %rdi
je 0x659a
subq %rdi, %rsi
callq 0x3260
leaq 0x18(%r14), %rax
movq %rax, -0x70(%rbp)
movq $0x7f7fffff, 0x30(%r14) # imm = 0x7F7FFFFF
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x38(%r14)
movq $0x0, 0x48(%r14)
leaq 0x30(%rbx), %r15
leaq -0x58(%rbp), %r13
leaq -0x1f8(%rbp), %r12
movq 0x30(%rbx), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0x50(%rbx,%rcx)
jne 0x676a
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 %r13, %rsi
callq 0x3450
movq $0x0, -0x38(%rbp)
movq %r12, %rdi
movq %r13, %rsi
movl $0x18, %edx
callq 0x33a0
cmpq $0x0, -0x50(%rbp)
je 0x6726
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x21, %eax
je 0x66b8
cmpl $0x23, %eax
je 0x6726
movq %r12, %rdi
leaq -0x38(%rbp), %rsi
callq 0x34b0
movq %rax, %rdi
leaq -0x34(%rbp), %rsi
callq 0x34b0
movss -0x34(%rbp), %xmm0
ucomiss 0x34(%r14), %xmm0
movq 0x48(%r14), %rax
jbe 0x667b
movss %xmm0, 0x34(%r14)
movq %rax, 0x38(%r14)
ucomiss 0x2da6(%rip), %xmm0     # 0x9428
jbe 0x6699
movss 0x30(%r14), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x6699
movss %xmm0, 0x30(%r14)
movq %rax, 0x40(%r14)
incq %rax
movq %rax, 0x48(%r14)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x6700
movq -0x38(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0x670c
movq $0x0, -0x60(%rbp)
movq %r12, %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, %r13b
jmp 0x6729
movq %r14, %rdi
leaq -0x38(%rbp), %rdx
callq 0x6c4a
leaq -0x38(%rbp), %rdi
callq 0x5d00
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6d70
xorl %r13d, %r13d
movq %r12, %rdi
movq 0x6875(%rip), %rsi      # 0xcfa8
callq 0x3190
leaq -0x178(%rbp), %rdi
callq 0x30c0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x675d
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3260
testb %r13b, %r13b
leaq -0x58(%rbp), %r13
je 0x65cb
movq 0x48(%r14), %rax
movq 0x238(%rbx), %rcx
movq %rcx, %rdx
orq %rax, %rdx
jne 0x67cf
movq 0x686c(%rip), %r12      # 0xcff0
leaq 0x2ca1(%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)
movq 0x238(%rbx), %rcx
movq 0x48(%r14), %rax
incq %rcx
movq %rcx, 0x238(%rbx)
testq %rax, %rax
je 0x67e7
movb 0x8(%rbx), %al
jmp 0x685d
xorl %eax, %eax
jmp 0x685d
movq 0x6802(%rip), %r14      # 0xcff0
leaq 0x2c63(%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 0x6394
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 0x6875
jmp 0x6875
movq %rax, %rbx
movq 0x6729(%rip), %rsi      # 0xcfa8
leaq -0x1f8(%rbp), %rdi
callq 0x3190
leaq -0x178(%rbp), %rdi
callq 0x30c0
jmp 0x689e
jmp 0x689b
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x68b7
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3430
nop