// File: drummyfish[P]flowchart/src/bitmap_image.hpp
// Function: bitmap_image::save_image(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool save_image(const std::string& file_name)
   {
      std::ofstream stream(file_name.c_str(),std::ios::binary);

      if (!stream)
      {
         //std::cout << "bitmap_image::save_image(): Error - Could not open file "  << file_name << " for writing!" << std::endl;
         return false;
      }

      bitmap_file_header bfh;
      bitmap_information_header bih;

      bih.width            = width_;
      bih.height           = height_;
      bih.bit_count        = static_cast<unsigned short>(bytes_per_pixel_ << 3);
      bih.clr_important    =  0;
      bih.clr_used         =  0;
      bih.compression      =  0;
      bih.planes           =  1;
      bih.size             = 40;
      bih.x_pels_per_meter =  0;
      bih.y_pels_per_meter =  0;
      bih.size_image       = (((bih.width * bytes_per_pixel_) + 3) & 0x0000FFFC) * bih.height;

      bfh.type      = 19778;
      bfh.size      = 55 + bih.size_image;
      bfh.reserved1 = 0;
      bfh.reserved2 = 0;
      bfh.off_bits  = bih.struct_size() + bfh.struct_size();

      write_bfh(stream,bfh);
      write_bih(stream,bih);

      unsigned int padding = (4 - ((3 * width_) % 4)) % 4;
      char padding_data[4] = {0x0,0x0,0x0,0x0};

      for (unsigned int i = 0; i < height_; ++i)
      {
         unsigned char* data_ptr = data_ + (row_increment_ * (height_ - i - 1));
         stream.write(reinterpret_cast<char*>(data_ptr),sizeof(unsigned char) * bytes_per_pixel_ * width_);
         stream.write(padding_data,padding);
      }

      stream.close();

      return true;
   }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30e0
movq %rax, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x3280
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x3110
movb %al, -0x279(%rbp)
jmp 0x1643b
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x16447
jmp 0x1647d
movb $0x0, -0x1(%rbp)
movl $0x1, -0x228(%rbp)
jmp 0x1668e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x33c0
jmp 0x166a8
movq -0x288(%rbp), %rax
movl 0x30(%rax), %ecx
movl %ecx, -0x25c(%rbp)
movl 0x34(%rax), %ecx
movl %ecx, -0x258(%rbp)
movl 0x28(%rax), %ecx
shll $0x3, %ecx
movw %cx, -0x252(%rbp)
movl $0x0, -0x23c(%rbp)
movl $0x0, -0x240(%rbp)
movl $0x0, -0x250(%rbp)
movw $0x1, -0x254(%rbp)
movl $0x28, -0x260(%rbp)
movl $0x0, -0x248(%rbp)
movl $0x0, -0x244(%rbp)
movl 0x28(%rax), %edx
movl -0x25c(%rbp), %eax
movl -0x258(%rbp), %ecx
imull %edx, %eax
addl $0x3, %eax
andl $0xfffc, %eax           # imm = 0xFFFC
imull %ecx, %eax
movl %eax, -0x24c(%rbp)
movw $0x4d42, -0x238(%rbp)   # imm = 0x4D42
movl -0x24c(%rbp), %eax
addl $0x37, %eax
movl %eax, -0x234(%rbp)
movw $0x0, -0x230(%rbp)
movw $0x0, -0x22e(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x16f00
movl %eax, -0x28c(%rbp)
jmp 0x16549
leaq -0x238(%rbp), %rdi
callq 0x16f10
movl %eax, -0x290(%rbp)
jmp 0x1655d
movq -0x288(%rbp), %rdi
movl -0x290(%rbp), %ecx
movl -0x28c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x22c(%rbp)
leaq -0x218(%rbp), %rsi
leaq -0x238(%rbp), %rdx
callq 0x16f20
jmp 0x1658d
movq -0x288(%rbp), %rdi
leaq -0x218(%rbp), %rsi
leaq -0x260(%rbp), %rdx
callq 0x170a0
jmp 0x165a9
movq -0x288(%rbp), %rax
imull $0x3, 0x30(%rax), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
andl $0x3, %eax
movl %eax, -0x264(%rbp)
leaq -0x268(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x3130
movl $0x0, -0x26c(%rbp)
movq -0x288(%rbp), %rcx
movl -0x26c(%rbp), %eax
cmpl 0x34(%rcx), %eax
jae 0x16672
movq -0x288(%rbp), %rax
movq 0x20(%rax), %rcx
movl 0x38(%rax), %edx
movl 0x34(%rax), %edi
movl -0x26c(%rbp), %esi
notl %esi
addl %edi, %esi
imull %esi, %edx
addq %rdx, %rcx
movq %rcx, -0x278(%rbp)
movq -0x278(%rbp), %rsi
movl 0x28(%rax), %ecx
movl 0x30(%rax), %eax
movl %ecx, %edx
imulq %rax, %rdx
leaq -0x218(%rbp), %rdi
callq 0x3330
jmp 0x1663f
movl -0x264(%rbp), %eax
movl %eax, %edx
leaq -0x218(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x3330
jmp 0x1665c
jmp 0x1665e
movl -0x26c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x26c(%rbp)
jmp 0x165e4
leaq -0x218(%rbp), %rdi
callq 0x33a0
jmp 0x16680
movb $0x1, -0x1(%rbp)
movl $0x1, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x33c0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x220(%rbp), %rdi
callq 0x3460
nopw %cs:(%rax,%rax)
nop