// File: /workspace/github_cpp_makefile_star2_O2/knei-knurow[P]lidar-visualizations/src/cloud-writers.cpp
// Function: CloudFileWriter::write(Cloud const&)
bool CloudFileWriter::write(const Cloud& cloud) {
  std::string filename;
  if (coord_sys_ == CoordSystem::CART) {
    filename = generate_filename("txt", output_dir_, "cloud-cart", ++files_cnt_);
  } else if (coord_sys_ == CoordSystem::CYL) {
    filename = generate_filename("txt", output_dir_, "cloud-cyl", ++files_cnt_);
  }

  std::ofstream file(filename);
  if (!file) {
    status_ = false;
    std::cerr << "ERROR: Unable to save cloud file." << std::endl;
    return false;
  }

  file << "# RPLIDAR SCAN DATA" << std::endl;
  file << "# Software: https://github.com/knei-knurow/lidar-visualizations" << std::endl;
  file << "# Authors: Szymon Bednorz, Bartek Dudek" << std::endl;
  if (coord_sys_ == CoordSystem::CART) {
    file << "# X Y" << std::endl;
    for (const auto& pt : cloud.pts_cart) {
      file << pt.x << " " << pt.y << std::endl;
    }
  } else if (coord_sys_ == CoordSystem::CYL) {
    file << "# Angle Dist" << std::endl;
    for (const auto& pt : cloud.pts_cyl) {
      file << pt.angle << " " << pt.dist << std::endl;
    }
  }

  std::cout << "Cloud file saved: " << filename << std::endl;
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, %rbx
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, %r14
movb $0x0, (%rax)
movl 0x38(%rdi), %eax
cmpl $0x1, %eax
je 0x6591
testl %eax, %eax
jne 0x660c
leaq 0x207b(%rip), %rsi      # 0x85c6
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x37f8
leaq 0x206b(%rip), %rsi      # 0x85ca
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x37f8
leaq 0x10(%r14), %rdx
movq 0x30(%r14), %r8
incq %r8
movq %r8, 0x30(%r14)
leaq -0x290(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rcx
callq 0x62a8
jmp 0x65dc
leaq 0x202e(%rip), %rsi      # 0x85c6
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x37f8
leaq 0x2029(%rip), %rsi      # 0x85d5
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x37f8
leaq 0x10(%r14), %rdx
movq 0x30(%r14), %r8
incq %r8
movq %r8, 0x30(%r14)
leaq -0x290(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rcx
callq 0x62a8
leaq -0x90(%rbp), %rdi
leaq -0x290(%rbp), %r15
movq %r15, %rsi
callq 0x32f0
movq %r15, %rdi
callq 0x3130
leaq -0x50(%rbp), %rdi
callq 0x3130
leaq -0x70(%rbp), %rdi
callq 0x3130
leaq -0x290(%rbp), %rdi
leaq -0x90(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x34d0
movq -0x290(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x270(%rbp,%rax), %r15d
testb $0x5, %r15b
je 0x6658
movb $0x0, 0x8(%r14)
movq 0x59a9(%rip), %rdi      # 0xbff0
leaq 0x1f91(%rip), %rsi      # 0x85df
callq 0x3290
jmp 0x67b3
leaq 0x1fa2(%rip), %rsi      # 0x8601
leaq -0x290(%rbp), %rdi
callq 0x3290
movq %rax, %rdi
callq 0x3150
leaq 0x1f9b(%rip), %rsi      # 0x8615
leaq -0x290(%rbp), %rdi
callq 0x3290
movq %rax, %rdi
callq 0x3150
leaq 0x1fc0(%rip), %rsi      # 0x8655
leaq -0x290(%rbp), %rdi
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl 0x38(%r14), %eax
cmpl $0x1, %eax
je 0x6726
testl %eax, %eax
jne 0x6791
leaq 0x1fbc(%rip), %rsi      # 0x867d
leaq -0x290(%rbp), %rdi
callq 0x3290
movq %rax, %rdi
callq 0x3150
movq 0x18(%rbx), %r12
movq 0x20(%rbx), %r13
leaq -0x290(%rbp), %rbx
leaq 0x20df(%rip), %r14      # 0x87ca
cmpq %r13, %r12
je 0x6791
movl (%r12), %esi
movq %rbx, %rdi
callq 0x3470
movq %rax, %rdi
movq %r14, %rsi
callq 0x3290
movl 0x4(%r12), %esi
movq %rax, %rdi
callq 0x3470
movq %rax, %rdi
callq 0x3150
addq $0x8, %r12
jmp 0x66eb
leaq 0x1f56(%rip), %rsi      # 0x8683
leaq -0x290(%rbp), %rdi
callq 0x3290
movq %rax, %rdi
callq 0x3150
movq (%rbx), %r12
movq 0x8(%rbx), %r13
leaq -0x290(%rbp), %rbx
leaq 0x2074(%rip), %r14      # 0x87ca
cmpq %r13, %r12
je 0x6791
movss (%r12), %xmm0
movq %rbx, %rdi
callq 0x31f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3290
movss 0x4(%r12), %xmm0
movq %rax, %rdi
callq 0x31f0
movq %rax, %rdi
callq 0x3150
addq $0x8, %r12
jmp 0x6756
movq 0x5838(%rip), %rdi      # 0xbfd0
leaq 0x1ef1(%rip), %rsi      # 0x8690
callq 0x3290
leaq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3150
testb $0x5, %r15b
sete %bl
leaq -0x290(%rbp), %rdi
callq 0x33b0
leaq -0x90(%rbp), %rdi
callq 0x3130
movl %ebx, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x67f0
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3130
jmp 0x6803
jmp 0x6800
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x3130
jmp 0x682a
jmp 0x6812
jmp 0x6812
movq %rax, %rbx
jmp 0x682a
jmp 0x681b
jmp 0x681b
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x33b0
leaq -0x90(%rbp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3480