// File: /workspace/github_cpp_makefile_star2_O1/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 0x743d
testl %eax, %eax
jne 0x74fd
leaq -0x60(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x2106(%rip), %rsi      # 0x94ee
leaq 0x2102(%rip), %rdx      # 0x94f1
leaq -0x70(%rbp), %rdi
callq 0x3906
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x20ea(%rip), %rsi      # 0x94f2
leaq 0x20ed(%rip), %rdx      # 0x94fc
leaq -0x50(%rbp), %rdi
callq 0x3906
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 0x6f0c
jmp 0x749f
leaq -0x60(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x20a2(%rip), %rsi      # 0x94ee
leaq 0x209e(%rip), %rdx      # 0x94f1
leaq -0x70(%rbp), %rdi
callq 0x3906
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x2091(%rip), %rsi      # 0x94fd
leaq 0x2093(%rip), %rdx      # 0x9506
leaq -0x50(%rbp), %rdi
callq 0x3906
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 0x6f0c
leaq -0x90(%rbp), %rdi
leaq -0x290(%rbp), %r15
movq %r15, %rsi
callq 0x32c0
movq (%r15), %rdi
leaq -0x280(%rbp), %rax
cmpq %rax, %rdi
je 0x74d3
movq -0x280(%rbp), %rsi
incq %rsi
callq 0x3260
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x74e8
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x74fd
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 0x7567
movb $0x0, 0x8(%r14)
movq 0x5ab6(%rip), %rbx      # 0xcff0
leaq 0x1fc6(%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 0x7845
leaq 0x1fbb(%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 0x1f85(%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 0x1f7b(%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 0x772b
testl %eax, %eax
jne 0x77f8
leaq 0x1f40(%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 0x77f8
leaq -0x290(%rbp), %rbx
leaq 0x202b(%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 0x76c7
jmp 0x77f8
leaq 0x1e79(%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 0x77f8
leaq -0x290(%rbp), %rbx
leaq 0x1f63(%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 0x778f
movq 0x57d1(%rip), %rdi      # 0xcfd0
leaq 0x1db2(%rip), %rsi      # 0x95b8
movl $0x12, %edx
callq 0x32a0
movl -0x2c(%rbp), %r12d
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq 0x57a7(%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 0x5761(%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 0x78aa
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 0x78c5
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x78e4
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x78e4
jmp 0x78e1
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x7917
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3260
jmp 0x7917
jmp 0x78ff
jmp 0x78ff
movq %rax, %rbx
jmp 0x7917
jmp 0x7908
jmp 0x7908
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x3360
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x7933
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3430
nop