// File: manikandan5[P]Image-Matching-Stitching-Warping/./CImg.h
// Function: cimg_library::CImg<double>::_save_bmp(_IO_FILE*, char const*) const
const CImg<T>& _save_bmp(std::FILE *const file, const char *const filename) const {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "save_bmp(): Specified filename is (null).",
                                    cimg_instance);
      if (is_empty()) { cimg::fempty(file,filename); return *this; }
      if (_depth>1)
        cimg::warn(_cimg_instance
                   "save_bmp(): Instance is volumetric, only the first slice will be saved in file '%s'.",
                   cimg_instance,
                   filename?filename:"(FILE*)");
      if (_spectrum>3)
        cimg::warn(_cimg_instance
                   "save_bmp(): Instance is multispectral, only the three first channels will be saved in file '%s'.",
                   cimg_instance,
                   filename?filename:"(FILE*)");

      std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
      unsigned char header[54] = { 0 }, align_buf[4] = { 0 };
      const unsigned int
        align = (4 - (3*_width)%4)%4,
        buf_size = (3*_width + align)*height(),
        file_size = 54 + buf_size;
      header[0] = 'B'; header[1] = 'M';
      header[0x02] = file_size&0xFF;
      header[0x03] = (file_size>>8)&0xFF;
      header[0x04] = (file_size>>16)&0xFF;
      header[0x05] = (file_size>>24)&0xFF;
      header[0x0A] = 0x36;
      header[0x0E] = 0x28;
      header[0x12] = _width&0xFF;
      header[0x13] = (_width>>8)&0xFF;
      header[0x14] = (_width>>16)&0xFF;
      header[0x15] = (_width>>24)&0xFF;
      header[0x16] = _height&0xFF;
      header[0x17] = (_height>>8)&0xFF;
      header[0x18] = (_height>>16)&0xFF;
      header[0x19] = (_height>>24)&0xFF;
      header[0x1A] = 1;
      header[0x1B] = 0;
      header[0x1C] = 24;
      header[0x1D] = 0;
      header[0x22] = buf_size&0xFF;
      header[0x23] = (buf_size>>8)&0xFF;
      header[0x24] = (buf_size>>16)&0xFF;
      header[0x25] = (buf_size>>24)&0xFF;
      header[0x27] = 0x1;
      header[0x2B] = 0x1;
      cimg::fwrite(header,54,nfile);

      const T
        *ptr_r = data(0,_height-1,0,0),
        *ptr_g = (_spectrum>=2)?data(0,_height-1,0,1):0,
        *ptr_b = (_spectrum>=3)?data(0,_height-1,0,2):0;

      switch (_spectrum) {
      case 1 : {
        cimg_forY(*this,y) {
          cimg_forX(*this,x) {
            const unsigned char val = (unsigned char)*(ptr_r++);
            std::fputc(val,nfile); std::fputc(val,nfile); std::fputc(val,nfile);
          }
          cimg::fwrite(align_buf,align,nfile);
          ptr_r-=2*_width;
        }
      } break;
      case 2 : {
        cimg_forY(*this,y) {
          cimg_forX(*this,x) {
            std::fputc(0,nfile);
            std::fputc((unsigned char)(*(ptr_g++)),nfile);
            std::fputc((unsigned char)(*(ptr_r++)),nfile);
          }
          cimg::fwrite(align_buf,align,nfile);
          ptr_r-=2*_width; ptr_g-=2*_width;
        }
      } break;
      default : {
        cimg_forY(*this,y) {
          cimg_forX(*this,x) {
            std::fputc((unsigned char)(*(ptr_b++)),nfile);
            std::fputc((unsigned char)(*(ptr_g++)),nfile);
            std::fputc((unsigned char)(*(ptr_r++)),nfile);
          }
          cimg::fwrite(align_buf,align,nfile);
          ptr_r-=2*_width; ptr_g-=2*_width; ptr_b-=2*_width;
        }
      }
      }
      if (!file) cimg::fclose(nfile);
      return *this;
    }

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movq %rdi, 0x188(%rsp)
movq %rsi, 0x180(%rsp)
movq %rdx, 0x178(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0xd0(%rsp)
cmpq $0x0, 0x180(%rsp)
jne 0x9ca19
cmpq $0x0, 0x178(%rsp)
jne 0x9ca19
movl $0x4008, %edi           # imm = 0x4008
callq 0x5240
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0xa0(%rsp)
movl (%rax), %ecx
movl %ecx, 0xa8(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0xac(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0xb0(%rsp)
movl 0xc(%rax), %ecx
movl %ecx, 0xb4(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0xb8(%rsp)
movb 0x10(%rax), %dl
leaq 0x4c07b(%rip), %rcx     # 0xe89d2
leaq 0x2d183(%rip), %rax     # 0xc9ae1
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0xc0(%rsp)
callq 0x118f0
movq %rax, 0xc8(%rsp)
jmp 0x9c97c
movl 0xb4(%rsp), %r9d
movl 0xb0(%rsp), %r8d
movl 0xac(%rsp), %ecx
movl 0xa8(%rsp), %edx
movq 0xa0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %r10
movq 0xc8(%rsp), %r11
movq %rsp, %rax
movq %r11, 0x10(%rax)
movq %r10, 0x8(%rax)
movq %rsi, (%rax)
leaq 0x4ef0b(%rip), %rsi     # 0xeb8da
xorl %eax, %eax
callq 0x12220
jmp 0x9c9d8
movq 0xa0(%rsp), %rdi
leaq 0x63179(%rip), %rsi     # 0xffb60
leaq -0x8a58e(%rip), %rdx    # 0x12460
callq 0x5920
movq 0xa0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
callq 0x53a0
jmp 0x9d377
movq 0xd0(%rsp), %rdi
callq 0x10320
testb $0x1, %al
jne 0x9ca2c
jmp 0x9ca56
movq 0x180(%rsp), %rdi
movq 0x178(%rsp), %rsi
callq 0x9c310
movq 0xd0(%rsp), %rax
movq %rax, 0x190(%rsp)
jmp 0x9d367
movq 0xd0(%rsp), %rax
cmpl $0x1, 0x8(%rax)
jbe 0x9cb42
movq 0xd0(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x78(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0x7c(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x80(%rsp)
movl 0xc(%rax), %ecx
movl %ecx, 0x84(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x88(%rsp)
movb 0x10(%rax), %dl
leaq 0x2d03a(%rip), %rax     # 0xc9ae1
leaq 0x4bf24(%rip), %rcx     # 0xe89d2
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0x90(%rsp)
callq 0x118f0
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x178(%rsp)
je 0x9cae4
movq 0x178(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x9caf2
leaq 0x4c99f(%rip), %rax     # 0xe948a
movq %rax, 0x70(%rsp)
jmp 0x9caf2
movq 0x98(%rsp), %r10
movq 0x90(%rsp), %r11
movq 0x88(%rsp), %r9
movl 0x84(%rsp), %r8d
movl 0x80(%rsp), %ecx
movl 0x7c(%rsp), %edx
movl 0x78(%rsp), %esi
movq 0x70(%rsp), %rax
leaq 0x4ee05(%rip), %rdi     # 0xeb932
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x117e0
movq 0xd0(%rsp), %rax
cmpl $0x3, 0xc(%rax)
jbe 0x9cc10
movq 0xd0(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x48(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0x4c(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x50(%rsp)
movl 0xc(%rax), %ecx
movl %ecx, 0x54(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x58(%rsp)
movb 0x10(%rax), %dl
leaq 0x2cf57(%rip), %rax     # 0xc9ae1
leaq 0x4be41(%rip), %rcx     # 0xe89d2
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0x60(%rsp)
callq 0x118f0
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x178(%rsp)
je 0x9cbc1
movq 0x178(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x9cbcf
leaq 0x4c8c2(%rip), %rax     # 0xe948a
movq %rax, 0x40(%rsp)
jmp 0x9cbcf
movq 0x68(%rsp), %r10
movq 0x60(%rsp), %r11
movq 0x58(%rsp), %r9
movl 0x54(%rsp), %r8d
movl 0x50(%rsp), %ecx
movl 0x4c(%rsp), %edx
movl 0x48(%rsp), %esi
movq 0x40(%rsp), %rax
leaq 0x4edba(%rip), %rdi     # 0xeb9b5
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x117e0
cmpq $0x0, 0x180(%rsp)
je 0x9cc2a
movq 0x180(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x9cc43
movq 0x178(%rsp), %rdi
leaq 0x4c2c7(%rip), %rsi     # 0xe8f00
callq 0x654a0
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x160(%rsp)
leaq 0x120(%rsp), %rdi
xorl %esi, %esi
movl $0x36, %edx
callq 0x52a0
leaq 0x11c(%rsp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x52a0
movq 0xd0(%rsp), %rdi
imull $0x3, (%rdi), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
andl $0x3, %eax
movl %eax, 0x118(%rsp)
imull $0x3, (%rdi), %eax
addl 0x118(%rsp), %eax
movl %eax, 0x34(%rsp)
callq 0x89d0
movl 0x34(%rsp), %ecx
movl %eax, %edx
movq 0xd0(%rsp), %rax
imull %edx, %ecx
movl %ecx, 0x114(%rsp)
movl 0x114(%rsp), %ecx
addl $0x36, %ecx
movl %ecx, 0x110(%rsp)
movb $0x42, 0x120(%rsp)
movb $0x4d, 0x121(%rsp)
movl 0x110(%rsp), %ecx
andl $0xff, %ecx
movb %cl, 0x122(%rsp)
movl 0x110(%rsp), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movb %cl, 0x123(%rsp)
movl 0x110(%rsp), %ecx
shrl $0x10, %ecx
andl $0xff, %ecx
movb %cl, 0x124(%rsp)
movl 0x110(%rsp), %ecx
shrl $0x18, %ecx
andl $0xff, %ecx
movb %cl, 0x125(%rsp)
movb $0x36, 0x12a(%rsp)
movb $0x28, 0x12e(%rsp)
movl (%rax), %ecx
andl $0xff, %ecx
movb %cl, 0x132(%rsp)
movl (%rax), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movb %cl, 0x133(%rsp)
movl (%rax), %ecx
shrl $0x10, %ecx
andl $0xff, %ecx
movb %cl, 0x134(%rsp)
movl (%rax), %ecx
shrl $0x18, %ecx
andl $0xff, %ecx
movb %cl, 0x135(%rsp)
movl 0x4(%rax), %ecx
andl $0xff, %ecx
movb %cl, 0x136(%rsp)
movl 0x4(%rax), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movb %cl, 0x137(%rsp)
movl 0x4(%rax), %ecx
shrl $0x10, %ecx
andl $0xff, %ecx
movb %cl, 0x138(%rsp)
movl 0x4(%rax), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, 0x139(%rsp)
movb $0x1, 0x13a(%rsp)
movb $0x0, 0x13b(%rsp)
movb $0x18, 0x13c(%rsp)
movb $0x0, 0x13d(%rsp)
movl 0x114(%rsp), %eax
andl $0xff, %eax
movb %al, 0x142(%rsp)
movl 0x114(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, 0x143(%rsp)
movl 0x114(%rsp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, 0x144(%rsp)
movl 0x114(%rsp), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, 0x145(%rsp)
movb $0x1, 0x147(%rsp)
movb $0x1, 0x14b(%rsp)
leaq 0x120(%rsp), %rdi
movq 0x160(%rsp), %rdx
movl $0x36, %esi
callq 0x9d390
movq 0xd0(%rsp), %rdi
movl 0x4(%rdi), %edx
subl $0x1, %edx
xorl %r8d, %r8d
movl %r8d, %esi
movl %r8d, %ecx
callq 0x73790
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x108(%rsp)
cmpl $0x2, 0xc(%rax)
jb 0x9ced1
movq 0xd0(%rsp), %rdi
movl 0x4(%rdi), %edx
subl $0x1, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl %ecx, %esi
callq 0x73790
movq %rax, 0x28(%rsp)
jmp 0x9ceda
xorl %eax, %eax
movq %rax, 0x28(%rsp)
jmp 0x9ceda
movq 0xd0(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x100(%rsp)
cmpl $0x3, 0xc(%rax)
jb 0x9cf19
movq 0xd0(%rsp), %rdi
movl 0x4(%rdi), %edx
subl $0x1, %edx
xorl %ecx, %ecx
movl $0x2, %r8d
movl %ecx, %esi
callq 0x73790
movq %rax, 0x20(%rsp)
jmp 0x9cf22
xorl %eax, %eax
movq %rax, 0x20(%rsp)
jmp 0x9cf22
movq 0xd0(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, 0xf8(%rsp)
movl 0xc(%rax), %eax
movl %eax, 0x1c(%rsp)
subl $0x1, %eax
je 0x9cf57
jmp 0x9cf45
movl 0x1c(%rsp), %eax
subl $0x2, %eax
je 0x9d074
jmp 0x9d1b9
movl $0x0, 0xf4(%rsp)
movq 0xd0(%rsp), %rcx
movl 0xf4(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x9d06f
movl $0x0, 0xf0(%rsp)
movq 0xd0(%rsp), %rcx
movl 0xf0(%rsp), %eax
cmpl (%rcx), %eax
jge 0x9d00f
movq 0x108(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x108(%rsp)
cvttsd2si (%rax), %eax
movb %al, 0xef(%rsp)
movzbl 0xef(%rsp), %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movzbl 0xef(%rsp), %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movzbl 0xef(%rsp), %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x9cf85
leaq 0x11c(%rsp), %rdi
movl 0x118(%rsp), %eax
movl %eax, %esi
movq 0x160(%rsp), %rdx
callq 0x9d390
movq 0xd0(%rsp), %rax
movl (%rax), %ecx
shll %ecx
movq 0x108(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x108(%rsp)
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x9cf62
jmp 0x9d33f
movl $0x0, 0xe8(%rsp)
movq 0xd0(%rsp), %rcx
movl 0xe8(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x9d1b4
movl $0x0, 0xe4(%rsp)
movq 0xd0(%rsp), %rcx
movl 0xe4(%rsp), %eax
cmpl (%rcx), %eax
jge 0x9d130
movq 0x160(%rsp), %rsi
xorl %edi, %edi
callq 0x5630
movq 0x100(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x100(%rsp)
cvttsd2si (%rax), %eax
movzbl %al, %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movq 0x108(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x108(%rsp)
cvttsd2si (%rax), %eax
movzbl %al, %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x9d0a2
leaq 0x11c(%rsp), %rdi
movl 0x118(%rsp), %eax
movl %eax, %esi
movq 0x160(%rsp), %rdx
callq 0x9d390
movq 0xd0(%rsp), %rax
movl (%rax), %edx
shll %edx
movq 0x108(%rsp), %rcx
movl %edx, %edx
movl %edx, %esi
xorl %edx, %edx
subq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, 0x108(%rsp)
movl (%rax), %ecx
shll %ecx
movq 0x100(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x100(%rsp)
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x9d07f
jmp 0x9d33f
movl $0x0, 0xe0(%rsp)
movq 0xd0(%rsp), %rcx
movl 0xe0(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x9d33d
movl $0x0, 0xdc(%rsp)
movq 0xd0(%rsp), %rcx
movl 0xdc(%rsp), %eax
cmpl (%rcx), %eax
jge 0x9d295
movq 0xf8(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0xf8(%rsp)
cvttsd2si (%rax), %eax
movzbl %al, %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movq 0x100(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x100(%rsp)
cvttsd2si (%rax), %eax
movzbl %al, %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movq 0x108(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x108(%rsp)
cvttsd2si (%rax), %eax
movzbl %al, %edi
movq 0x160(%rsp), %rsi
callq 0x5630
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x9d1e7
leaq 0x11c(%rsp), %rdi
movl 0x118(%rsp), %eax
movl %eax, %esi
movq 0x160(%rsp), %rdx
callq 0x9d390
movq 0xd0(%rsp), %rax
movl (%rax), %edx
shll %edx
movq 0x108(%rsp), %rcx
movl %edx, %edx
movl %edx, %esi
xorl %edx, %edx
subq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, 0x108(%rsp)
movl (%rax), %edx
shll %edx
movq 0x100(%rsp), %rcx
movl %edx, %edx
movl %edx, %esi
xorl %edx, %edx
subq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, 0x100(%rsp)
movl (%rax), %ecx
shll %ecx
movq 0xf8(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xf8(%rsp)
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
jmp 0x9d1c4
jmp 0x9d33f
cmpq $0x0, 0x180(%rsp)
jne 0x9d357
movq 0x160(%rsp), %rdi
callq 0x5c6f0
movq 0xd0(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x190(%rsp), %rax
addq $0x198, %rsp            # imm = 0x198
retq
movq 0x170(%rsp), %rdi
callq 0x5970
nopw %cs:(%rax,%rax)
nop