// File: 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
subq $0x420, %rsp            # imm = 0x420
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x378(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x44c0
movq -0x378(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0xfe9f
leaq -0x79(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x4620
movq -0x380(%rbp), %rdx
leaq 0x3870(%rip), %rsi      # 0x135e6
leaq -0x78(%rbp), %rdi
callq 0x4ae0
jmp 0xfd81
movq -0x378(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x390(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x388(%rbp)
callq 0x4620
movq -0x388(%rbp), %rdx
leaq 0x3836(%rip), %rsi      # 0x135ea
leaq -0xb0(%rbp), %rdi
callq 0x4ae0
jmp 0xfdc2
movq -0x390(%rbp), %rdx
movq -0x378(%rbp), %rax
movq 0x30(%rax), %r8
incq %r8
movq %r8, 0x30(%rax)
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0xb0(%rbp), %rcx
callq 0xf900
jmp 0xfdf1
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x4430
leaq -0x58(%rbp), %rdi
callq 0x4230
leaq -0xb0(%rbp), %rdi
callq 0x4230
leaq -0xb1(%rbp), %rdi
callq 0x43c0
leaq -0x78(%rbp), %rdi
callq 0x4230
leaq -0x79(%rbp), %rdi
callq 0x43c0
jmp 0x10014
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xfe91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xfe7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4230
leaq -0xb1(%rbp), %rdi
callq 0x43c0
leaq -0x78(%rbp), %rdi
callq 0x4230
leaq -0x79(%rbp), %rdi
callq 0x43c0
jmp 0x10448
movq -0x378(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jne 0x10012
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x4620
movq -0x398(%rbp), %rdx
leaq 0x3715(%rip), %rsi      # 0x135e6
leaq -0xf8(%rbp), %rdi
callq 0x4ae0
jmp 0xfedf
movq -0x378(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x3a8(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x4620
movq -0x3a0(%rbp), %rdx
leaq 0x36e3(%rip), %rsi      # 0x135f5
leaq -0x120(%rbp), %rdi
callq 0x4ae0
jmp 0xff20
movq -0x3a8(%rbp), %rdx
movq -0x378(%rbp), %rax
movq 0x30(%rax), %r8
incq %r8
movq %r8, 0x30(%rax)
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x120(%rbp), %rcx
callq 0xf900
jmp 0xff55
leaq -0x38(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x4430
leaq -0xd8(%rbp), %rdi
callq 0x4230
leaq -0x120(%rbp), %rdi
callq 0x4230
leaq -0x121(%rbp), %rdi
callq 0x43c0
leaq -0xf8(%rbp), %rdi
callq 0x4230
leaq -0xf9(%rbp), %rdi
callq 0x43c0
jmp 0x10012
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x10001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xffe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x4230
leaq -0x121(%rbp), %rdi
callq 0x43c0
leaq -0xf8(%rbp), %rdi
callq 0x4230
leaq -0xf9(%rbp), %rdi
callq 0x43c0
jmp 0x10448
jmp 0x10014
leaq -0x328(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0x10, %edx
callq 0x4670
jmp 0x1002b
movq -0x328(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x328(%rbp,%rax), %rdi
callq 0x41b0
movb %al, -0x3a9(%rbp)
jmp 0x1004b
movb -0x3a9(%rbp), %al
testb $0x1, %al
jne 0x1005a
jmp 0x100e3
movq -0x378(%rbp), %rax
movb $0x0, 0x8(%rax)
movq 0xcf84(%rip), %rdi      # 0x1cff0
leaq 0x358c(%rip), %rsi      # 0x135ff
callq 0x4360
movq %rax, -0x3b8(%rbp)
jmp 0x10081
movq -0x3b8(%rbp), %rdi
movq 0xcf31(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x10096
movb $0x0, -0x1(%rbp)
movl $0x1, -0x32c(%rbp)
jmp 0x10425
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x10448
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x328(%rbp), %rdi
callq 0x4510
jmp 0x10448
leaq 0x3537(%rip), %rsi      # 0x13621
leaq -0x328(%rbp), %rdi
callq 0x4360
movq %rax, -0x3c0(%rbp)
jmp 0x100ff
movq -0x3c0(%rbp), %rdi
movq 0xceb3(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x10114
leaq 0x351a(%rip), %rsi      # 0x13635
leaq -0x328(%rbp), %rdi
callq 0x4360
movq %rax, -0x3c8(%rbp)
jmp 0x10130
movq -0x3c8(%rbp), %rdi
movq 0xce82(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x10145
leaq 0x3529(%rip), %rsi      # 0x13675
leaq -0x328(%rbp), %rdi
callq 0x4360
movq %rax, -0x3d0(%rbp)
jmp 0x10161
movq -0x3d0(%rbp), %rdi
movq 0xce51(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x10176
movq -0x378(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x102a2
leaq 0x350f(%rip), %rsi      # 0x1369d
leaq -0x328(%rbp), %rdi
callq 0x4360
movq %rax, -0x3d8(%rbp)
jmp 0x101a3
movq -0x3d8(%rbp), %rdi
movq 0xce0f(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x101b8
movq -0x18(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x338(%rbp)
movq -0x338(%rbp), %rdi
callq 0xd7a0
movq %rax, -0x340(%rbp)
movq -0x338(%rbp), %rdi
callq 0xd7d0
movq %rax, -0x348(%rbp)
leaq -0x340(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0xdbd0
testb $0x1, %al
jne 0x10209
jmp 0x1029d
leaq -0x340(%rbp), %rdi
callq 0xdc30
movq %rax, -0x350(%rbp)
movq -0x350(%rbp), %rax
movl (%rax), %esi
leaq -0x328(%rbp), %rdi
callq 0x4600
movq %rax, -0x3e0(%rbp)
jmp 0x1023a
movq -0x3e0(%rbp), %rdi
leaq 0x35a2(%rip), %rsi      # 0x137ea
callq 0x4360
movq %rax, -0x3e8(%rbp)
jmp 0x10256
movq -0x3e8(%rbp), %rdi
movq -0x350(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x4600
movq %rax, -0x3f0(%rbp)
jmp 0x10275
movq -0x3f0(%rbp), %rdi
movq 0xcd3d(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x1028a
jmp 0x1028c
leaq -0x340(%rbp), %rdi
callq 0xdc50
jmp 0x101ed
jmp 0x103cd
movq -0x378(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jne 0x103cb
leaq 0x33e9(%rip), %rsi      # 0x136a3
leaq -0x328(%rbp), %rdi
callq 0x4360
movq %rax, -0x3f8(%rbp)
jmp 0x102cf
movq -0x3f8(%rbp), %rdi
movq 0xcce3(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x102e4
movq -0x18(%rbp), %rax
movq %rax, -0x358(%rbp)
movq -0x358(%rbp), %rdi
callq 0xccd0
movq %rax, -0x360(%rbp)
movq -0x358(%rbp), %rdi
callq 0xcd00
movq %rax, -0x368(%rbp)
leaq -0x360(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0xd100
testb $0x1, %al
jne 0x10331
jmp 0x103c9
leaq -0x360(%rbp), %rdi
callq 0xd160
movq %rax, -0x370(%rbp)
movq -0x370(%rbp), %rax
movss (%rax), %xmm0
leaq -0x328(%rbp), %rdi
callq 0x42b0
movq %rax, -0x400(%rbp)
jmp 0x10364
movq -0x400(%rbp), %rdi
leaq 0x3478(%rip), %rsi      # 0x137ea
callq 0x4360
movq %rax, -0x408(%rbp)
jmp 0x10380
movq -0x408(%rbp), %rdi
movq -0x370(%rbp), %rax
movss 0x4(%rax), %xmm0
callq 0x42b0
movq %rax, -0x410(%rbp)
jmp 0x103a1
movq -0x410(%rbp), %rdi
movq 0xcc11(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x103b6
jmp 0x103b8
leaq -0x360(%rbp), %rdi
callq 0xd180
jmp 0x10315
jmp 0x103cb
jmp 0x103cd
movq 0xcbfc(%rip), %rdi      # 0x1cfd0
leaq 0x32d5(%rip), %rsi      # 0x136b0
callq 0x4360
movq %rax, -0x418(%rbp)
jmp 0x103e9
movq -0x418(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4330
movq %rax, -0x420(%rbp)
jmp 0x10402
movq -0x420(%rbp), %rdi
movq 0xcbb0(%rip), %rsi      # 0x1cfc0
callq 0x43a0
jmp 0x10417
movb $0x1, -0x1(%rbp)
movl $0x1, -0x32c(%rbp)
leaq -0x328(%rbp), %rdi
callq 0x4510
leaq -0x38(%rbp), %rdi
callq 0x4230
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x4230
movq -0x88(%rbp), %rdi
callq 0x4610
nopl (%rax)