// File: rapirent[P]JPEG/./bitmap_image.hpp
// Function: bitmap_image::load_bitmap()
void load_bitmap()
   {
      std::ifstream stream(file_name_.c_str(),std::ios::binary);

      if (!stream)
      {
         std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - file " << file_name_ << " not found!" << std::endl;
         return;
      }

      width_  = 0;
      height_ = 0;

      bitmap_file_header bfh;
      bitmap_information_header bih;

      bfh.clear();
      bih.clear();

      read_bfh(stream,bfh);
      read_bih(stream,bih);

      if (bfh.type != 19778)
      {
         bfh.clear();
         bih.clear();

         stream.close();

         std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Invalid type value " << bfh.type << " expected 19778." << std::endl;
         return;
      }

      if (bih.bit_count != 24)
      {
         bfh.clear();
         bih.clear();

         stream.close();

         std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Invalid bit depth " << bih.bit_count << " expected 24." << std::endl;

         return;
      }

      if (bih.size != bih.struct_size())
      {
         bfh.clear();
         bih.clear();

         stream.close();

         std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Invalid BIH size " << bih.size << " expected " << bih.struct_size() << std::endl;

         return;
      }

      width_  = bih.width;
      height_ = bih.height;

      bytes_per_pixel_ = bih.bit_count >> 3;

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

      std::size_t bitmap_file_size = file_size(file_name_);

      std::size_t bitmap_logical_size = (height_ * width_ * bytes_per_pixel_) +
                                        (height_ * padding)                   +
                                         bih.struct_size()                    +
                                         bfh.struct_size()                    ;

      if (bitmap_file_size != bitmap_logical_size)
      {
         bfh.clear();
         bih.clear();

         stream.close();

         std::cerr << "bitmap_image::load_bitmap() ERROR: bitmap_image - Mismatch between logical and physical sizes of bitmap. " <<
                      "Logical: "  << bitmap_logical_size << " " <<
                      "Physical: " << bitmap_file_size    << std::endl;

         return;
      }

      create_bitmap();

      for (unsigned int i = 0; i < height_; ++i)
      {
         unsigned char* data_ptr = row(height_ - i - 1); // read in inverted row order

         stream.read(reinterpret_cast<char*>(data_ptr), sizeof(char) * bytes_per_pixel_ * width_);
         stream.read(padding_data,padding);
      }
   }

// Assembly:
subq $0x358, %rsp            # imm = 0x358
movq %rdi, 0x350(%rsp)
movq 0x350(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x50c0
movq %rax, %rsi
leaq 0x148(%rsp), %rdi
movl $0x4, %edx
callq 0x5350
movq 0x148(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x148(%rsp,%rax), %rdi
callq 0x5100
movb %al, 0xd7(%rsp)
jmp 0x777b
movb 0xd7(%rsp), %al
testb $0x1, %al
jne 0x778b
jmp 0x7831
movq 0x685e(%rip), %rdi      # 0xdff0
leaq 0x31c0(%rip), %rsi      # 0xa959
callq 0x51c0
movq %rax, 0xc0(%rsp)
jmp 0x77a8
movq 0xc8(%rsp), %rsi
movq 0xc0(%rsp), %rdi
callq 0x51b0
movq %rax, 0xb8(%rsp)
jmp 0x77c7
movq 0xb8(%rsp), %rdi
leaq 0x31bb(%rip), %rsi      # 0xa991
callq 0x51c0
movq %rax, 0xb0(%rsp)
jmp 0x77e5
movq 0xb0(%rsp), %rdi
movq 0x67d4(%rip), %rsi      # 0xdfc8
callq 0x5200
jmp 0x77fb
movl $0x1, 0x138(%rsp)
jmp 0x7daa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x5080
jmp 0x7dbf
movq 0xc8(%rsp), %rax
movl $0x0, 0x20(%rax)
movl $0x0, 0x24(%rax)
leaq 0x128(%rsp), %rdi
callq 0x7dd0
jmp 0x7856
leaq 0x100(%rsp), %rdi
callq 0x7df0
jmp 0x7865
movq 0xc8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0x7e10
jmp 0x7884
movq 0xc8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x100(%rsp), %rdx
callq 0x7f50
jmp 0x78a3
movzwl 0x128(%rsp), %eax
cmpl $0x4d42, %eax           # imm = 0x4D42
je 0x7963
leaq 0x128(%rsp), %rdi
callq 0x7dd0
jmp 0x78c5
leaq 0x100(%rsp), %rdi
callq 0x7df0
jmp 0x78d4
leaq 0x148(%rsp), %rdi
callq 0x5060
jmp 0x78e3
movq 0x6706(%rip), %rdi      # 0xdff0
leaq 0x30ac(%rip), %rsi      # 0xa99d
callq 0x51c0
movq %rax, 0xa8(%rsp)
jmp 0x7900
movq 0xa8(%rsp), %rdi
movzwl 0x128(%rsp), %esi
callq 0x5300
movq %rax, 0xa0(%rsp)
jmp 0x791f
movq 0xa0(%rsp), %rdi
leaq 0x30b5(%rip), %rsi      # 0xa9e3
callq 0x51c0
movq %rax, 0x98(%rsp)
jmp 0x793d
movq 0x98(%rsp), %rdi
movq 0x667c(%rip), %rsi      # 0xdfc8
callq 0x5200
jmp 0x7953
movl $0x1, 0x138(%rsp)
jmp 0x7daa
movzwl 0x10e(%rsp), %eax
cmpl $0x18, %eax
je 0x7a21
leaq 0x128(%rsp), %rdi
callq 0x7dd0
jmp 0x7983
leaq 0x100(%rsp), %rdi
callq 0x7df0
jmp 0x7992
leaq 0x148(%rsp), %rdi
callq 0x5060
jmp 0x79a1
movq 0x6648(%rip), %rdi      # 0xdff0
leaq 0x3045(%rip), %rsi      # 0xa9f4
callq 0x51c0
movq %rax, 0x90(%rsp)
jmp 0x79be
movq 0x90(%rsp), %rdi
movzwl 0x10e(%rsp), %esi
callq 0x5300
movq %rax, 0x88(%rsp)
jmp 0x79dd
movq 0x88(%rsp), %rdi
leaq 0x304d(%rip), %rsi      # 0xaa39
callq 0x51c0
movq %rax, 0x80(%rsp)
jmp 0x79fb
movq 0x80(%rsp), %rdi
movq 0x65be(%rip), %rsi      # 0xdfc8
callq 0x5200
jmp 0x7a11
movl $0x1, 0x138(%rsp)
jmp 0x7daa
movl 0x100(%rsp), %eax
movl %eax, 0x78(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x81d0
movl %eax, 0x7c(%rsp)
jmp 0x7a3f
movl 0x78(%rsp), %eax
movl 0x7c(%rsp), %ecx
cmpl %ecx, %eax
je 0x7b11
leaq 0x128(%rsp), %rdi
callq 0x7dd0
jmp 0x7a5e
leaq 0x100(%rsp), %rdi
callq 0x7df0
jmp 0x7a6d
leaq 0x148(%rsp), %rdi
callq 0x5060
jmp 0x7a7c
movq 0x656d(%rip), %rdi      # 0xdff0
leaq 0x2fbd(%rip), %rsi      # 0xaa47
callq 0x51c0
movq %rax, 0x70(%rsp)
jmp 0x7a96
movq 0x70(%rsp), %rdi
movl 0x100(%rsp), %esi
callq 0x5290
movq %rax, 0x68(%rsp)
jmp 0x7aae
movq 0x68(%rsp), %rdi
leaq 0x2fd1(%rip), %rsi      # 0xaa8b
callq 0x51c0
movq %rax, 0x60(%rsp)
jmp 0x7ac6
leaq 0x100(%rsp), %rdi
callq 0x81d0
movl %eax, 0x5c(%rsp)
jmp 0x7ad9
movl 0x5c(%rsp), %esi
movq 0x60(%rsp), %rdi
callq 0x5290
movq %rax, 0x50(%rsp)
jmp 0x7aee
movq 0x50(%rsp), %rdi
movq 0x64ce(%rip), %rsi      # 0xdfc8
callq 0x5200
jmp 0x7b01
movl $0x1, 0x138(%rsp)
jmp 0x7daa
movq 0xc8(%rsp), %rsi
movl 0x104(%rsp), %eax
movl %eax, 0x20(%rsi)
movl 0x108(%rsp), %eax
movl %eax, 0x24(%rsi)
movzwl 0x10e(%rsp), %eax
shrl $0x3, %eax
movl %eax, 0x2c(%rsi)
movl 0x20(%rsi), %eax
addl $0x4, %eax
andl $0x3, %eax
movl %eax, 0xfc(%rsp)
movl $0x0, 0xf8(%rsp)
movq %rsi, %rdi
callq 0x81e0
movq %rax, 0x48(%rsp)
jmp 0x7b65
movq 0xc8(%rsp), %rdx
movq 0x48(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl 0x20(%rdx), %esi
movl 0x24(%rdx), %ecx
movl %ecx, %eax
imull %esi, %eax
movl 0x2c(%rdx), %edx
imull %edx, %eax
movl 0xfc(%rsp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, 0x40(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x81d0
movl %eax, 0x44(%rsp)
jmp 0x7bae
movl 0x44(%rsp), %ecx
movl 0x40(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x38(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x8310
movl %eax, 0x3c(%rsp)
jmp 0x7bcf
movl 0x3c(%rsp), %ecx
movl 0x38(%rsp), %eax
addl %ecx, %eax
movl %eax, %eax
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rax
cmpq 0xe8(%rsp), %rax
je 0x7cdd
leaq 0x128(%rsp), %rdi
callq 0x7dd0
jmp 0x7c08
leaq 0x100(%rsp), %rdi
callq 0x7df0
jmp 0x7c17
leaq 0x148(%rsp), %rdi
callq 0x5060
jmp 0x7c26
movq 0x63c3(%rip), %rdi      # 0xdff0
leaq 0x2e62(%rip), %rsi      # 0xaa96
callq 0x51c0
movq %rax, 0x30(%rsp)
jmp 0x7c40
movq 0x30(%rsp), %rdi
leaq 0x2eb4(%rip), %rsi      # 0xab00
callq 0x51c0
movq %rax, 0x28(%rsp)
jmp 0x7c58
movq 0x28(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x5070
movq %rax, 0x20(%rsp)
jmp 0x7c71
movq 0x20(%rsp), %rdi
leaq 0x2e81(%rip), %rsi      # 0xaafe
callq 0x51c0
movq %rax, 0x18(%rsp)
jmp 0x7c89
movq 0x18(%rsp), %rdi
leaq 0x2e75(%rip), %rsi      # 0xab0a
callq 0x51c0
movq %rax, 0x10(%rsp)
jmp 0x7ca1
movq 0x10(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x5070
movq %rax, 0x8(%rsp)
jmp 0x7cba
movq 0x8(%rsp), %rdi
movq 0x6302(%rip), %rsi      # 0xdfc8
callq 0x5200
jmp 0x7ccd
movl $0x1, 0x138(%rsp)
jmp 0x7daa
movq 0xc8(%rsp), %rdi
callq 0x8320
jmp 0x7cec
movl $0x0, 0xe4(%rsp)
movq 0xc8(%rsp), %rcx
movl 0xe4(%rsp), %eax
cmpl 0x24(%rcx), %eax
jae 0x7d9f
movq 0xc8(%rsp), %rdi
movl 0x24(%rdi), %eax
movl 0xe4(%rsp), %esi
notl %esi
addl %eax, %esi
callq 0x8350
movq %rax, (%rsp)
jmp 0x7d30
movq 0xc8(%rsp), %rcx
movq (%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rsi
movl 0x20(%rcx), %eax
movl 0x2c(%rcx), %ecx
movl %ecx, %edx
imulq %rax, %rdx
leaq 0x148(%rsp), %rdi
callq 0x5280
jmp 0x7d67
movl 0xfc(%rsp), %eax
movl %eax, %edx
leaq 0x148(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x5280
jmp 0x7d87
jmp 0x7d89
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x7cf7
movl $0x0, 0x138(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x5080
addq $0x358, %rsp            # imm = 0x358
retq
movq 0x140(%rsp), %rdi
callq 0x5320
nopl (%rax)