// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, %r14
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl 0x38(%rdi), %eax
cmpl $0x1, %eax
je 0x7417
testl %eax, %eax
jne 0x74d7
leaq -0x60(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x212c(%rip), %rsi      # 0x94ee
leaq 0x2128(%rip), %rdx      # 0x94f1
leaq -0x70(%rbp), %rdi
callq 0x38fa
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x2110(%rip), %rsi      # 0x94f2
leaq 0x2113(%rip), %rdx      # 0x94fc
leaq -0x50(%rbp), %rdi
callq 0x38fa
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 0x6ed8
jmp 0x7479
leaq -0x60(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x20c8(%rip), %rsi      # 0x94ee
leaq 0x20c4(%rip), %rdx      # 0x94f1
leaq -0x70(%rbp), %rdi
callq 0x38fa
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x20b7(%rip), %rsi      # 0x94fd
leaq 0x20b9(%rip), %rdx      # 0x9506
leaq -0x50(%rbp), %rdi
callq 0x38fa
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 0x6ed8
leaq -0x90(%rbp), %rdi
leaq -0x290(%rbp), %r15
movq %r15, %rsi
callq 0x32c0
movq (%r15), %rdi
leaq -0x280(%rbp), %rax
cmpq %rax, %rdi
je 0x74ad
movq -0x280(%rbp), %rsi
incq %rsi
callq 0x3260
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x74c2
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x74d7
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3260
leaq -0x290(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x10, %edx
callq 0x34a0
movq -0x290(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x270(%rbp,%rax), %r12d
testb $0x5, %r12b
je 0x7541
movb $0x0, 0x8(%r14)
movq 0x5adc(%rip), %rbx      # 0xcff0
leaq 0x1fec(%rip), %rsi      # 0x9507
movl $0x21, %edx
movq %rbx, %rdi
callq 0x32a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
jmp 0x781f
leaq 0x1fe1(%rip), %rsi      # 0x9529
leaq -0x290(%rbp), %r15
movl $0x13, %edx
movq %r15, %rdi
callq 0x32a0
movq -0x290(%rbp), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
leaq -0x290(%rbp), %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
leaq 0x1fab(%rip), %rsi      # 0x953d
leaq -0x290(%rbp), %r15
movl $0x3f, %edx
movq %r15, %rdi
callq 0x32a0
movq -0x290(%rbp), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
leaq -0x290(%rbp), %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
leaq 0x1fa1(%rip), %rsi      # 0x957d
leaq -0x290(%rbp), %r15
movl $0x27, %edx
movq %r15, %rdi
callq 0x32a0
movq -0x290(%rbp), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
leaq -0x290(%rbp), %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movl 0x38(%r14), %eax
cmpl $0x1, %eax
movl %r12d, -0x2c(%rbp)
je 0x7705
testl %eax, %eax
jne 0x77d2
leaq 0x1f66(%rip), %rsi      # 0x95a5
leaq -0x290(%rbp), %r14
movl $0x5, %edx
movq %r14, %rdi
callq 0x32a0
movq -0x290(%rbp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
leaq -0x290(%rbp), %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x18(%rbx), %r12
movq 0x20(%rbx), %r13
cmpq %r13, %r12
je 0x77d2
leaq -0x290(%rbp), %rbx
leaq 0x2051(%rip), %r14      # 0x96f2
movl (%r12), %esi
movq %rbx, %rdi
callq 0x3420
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movl 0x4(%r12), %esi
movq %r15, %rdi
callq 0x3420
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
addq $0x8, %r12
cmpq %r13, %r12
jne 0x76a1
jmp 0x77d2
leaq 0x1e9f(%rip), %rsi      # 0x95ab
leaq -0x290(%rbp), %r14
movl $0xc, %edx
movq %r14, %rdi
callq 0x32a0
movq -0x290(%rbp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
leaq -0x290(%rbp), %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq (%rbx), %r12
movq 0x8(%rbx), %r13
cmpq %r13, %r12
je 0x77d2
leaq -0x290(%rbp), %rbx
leaq 0x1f89(%rip), %r14      # 0x96f2
xorps %xmm0, %xmm0
cvtss2sd (%r12), %xmm0
movq %rbx, %rdi
callq 0x33b0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
xorps %xmm0, %xmm0
cvtss2sd 0x4(%r12), %xmm0
movq %r15, %rdi
callq 0x33b0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
addq $0x8, %r12
cmpq %r13, %r12
jne 0x7769
movq 0x57f7(%rip), %rdi      # 0xcfd0
leaq 0x1dd8(%rip), %rsi      # 0x95b8
movl $0x12, %edx
callq 0x32a0
movl -0x2c(%rbp), %r12d
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq 0x57cd(%rip), %rdi      # 0xcfd0
callq 0x32a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq 0x5787(%rip), %rax      # 0xcfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x288(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x290(%rbp,%rcx)
callq 0x31e0
leaq -0x198(%rbp), %rdi
callq 0x30c0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x7884
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x3260
testb $0x5, %r12b
sete %al
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x789f
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x78be
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x78be
jmp 0x78bb
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x78f1
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x78f1
jmp 0x78d9
jmp 0x78d9
movq %rax, %rbx
jmp 0x78f1
jmp 0x78e2
jmp 0x78e2
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x3360
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x790d
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3430
nop