// File: manikandan5[P]Image-Matching-Stitching-Warping/./CImg.h
// Function: cimg_library::CImg<double>::_load_jpeg(_IO_FILE*, char const*)
CImg<T>& _load_jpeg(std::FILE *const file, const char *const filename) {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "load_jpeg(): Specified filename is (null).",
                                    cimg_instance);

#ifndef cimg_use_jpeg
      if (file)
        throw CImgIOException(_cimg_instance
                              "load_jpeg(): Unable to load data from '(FILE*)' unless libjpeg is enabled.",
                              cimg_instance);
      else return load_other(filename);
#else

      struct jpeg_decompress_struct cinfo;
      struct _cimg_error_mgr jerr;
      cinfo.err = jpeg_std_error(&jerr.original);
      jerr.original.error_exit = _cimg_jpeg_error_exit;

      if (setjmp(jerr.setjmp_buffer)) { // JPEG error
        throw CImgIOException(_cimg_instance
                             "load_jpeg(): Error message returned by libjpeg: %s.",
                             cimg_instance,jerr.message);
      }

      std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
      jpeg_create_decompress(&cinfo);
      jpeg_stdio_src(&cinfo,nfile);
      jpeg_read_header(&cinfo,TRUE);
      jpeg_start_decompress(&cinfo);

      if (cinfo.output_components!=1 && cinfo.output_components!=3 && cinfo.output_components!=4) {
        if (!file) {
          cimg::fclose(nfile);
          return load_other(filename);
        } else
          throw CImgIOException(_cimg_instance
                                "load_jpeg(): Failed to load JPEG data from file '%s'.",
                                cimg_instance,filename?filename:"(FILE*)");
      }
      CImg<ucharT> buffer(cinfo.output_width*cinfo.output_components);
      JSAMPROW row_pointer[1];
      assign(cinfo.output_width,cinfo.output_height,1,cinfo.output_components);
      T *ptr_r = _data, *ptr_g = _data + 1UL*_width*_height, *ptr_b = _data + 2UL*_width*_height,
        *ptr_a = _data + 3UL*_width*_height;
      while (cinfo.output_scanline<cinfo.output_height) {
        *row_pointer = buffer._data;
        if (jpeg_read_scanlines(&cinfo,row_pointer,1)!=1) {
          cimg::warn(_cimg_instance
                     "load_jpeg(): Incomplete data in file '%s'.",
                     cimg_instance,filename?filename:"(FILE*)");
          break;
        }
        const unsigned char *ptrs = buffer._data;
        switch (_spectrum) {
        case 1 : {
          cimg_forX(*this,x) *(ptr_r++) = (T)*(ptrs++);
        } break;
        case 3 : {
          cimg_forX(*this,x) {
            *(ptr_r++) = (T)*(ptrs++);
            *(ptr_g++) = (T)*(ptrs++);
            *(ptr_b++) = (T)*(ptrs++);
          }
        } break;
        case 4 : {
          cimg_forX(*this,x) {
            *(ptr_r++) = (T)*(ptrs++);
            *(ptr_g++) = (T)*(ptrs++);
            *(ptr_b++) = (T)*(ptrs++);
            *(ptr_a++) = (T)*(ptrs++);
          }
        } break;
        }
      }
      jpeg_finish_decompress(&cinfo);
      jpeg_destroy_decompress(&cinfo);
      if (!file) cimg::fclose(nfile);
      return *this;
#endif
    }

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpq $0x0, 0x98(%rsp)
jne 0x768fd
cmpq $0x0, 0x90(%rsp)
jne 0x768fd
movl $0x4008, %edi           # imm = 0x4008
callq 0x5240
movq %rax, %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x48(%rsp)
movl (%rax), %ecx
movl %ecx, 0x50(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0x54(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x58(%rsp)
movl 0xc(%rax), %ecx
movl %ecx, 0x5c(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x60(%rsp)
movb 0x10(%rax), %dl
leaq 0x72173(%rip), %rcx     # 0xe89d2
leaq 0x5327b(%rip), %rax     # 0xc9ae1
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0x68(%rsp)
callq 0x118f0
movq %rax, 0x70(%rsp)
jmp 0x7687e
movl 0x5c(%rsp), %r9d
movl 0x58(%rsp), %r8d
movl 0x54(%rsp), %ecx
movl 0x50(%rsp), %edx
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %r10
movq 0x70(%rsp), %r11
movq %rsp, %rax
movq %r11, 0x10(%rax)
movq %r10, 0x8(%rax)
movq %rsi, (%rax)
leaq 0x72f0b(%rip), %rsi     # 0xe97c4
xorl %eax, %eax
callq 0x12220
jmp 0x768c2
movq 0x48(%rsp), %rdi
leaq 0x89292(%rip), %rsi     # 0xffb60
leaq -0x64475(%rip), %rdx    # 0x12460
callq 0x5920
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
callq 0x53a0
jmp 0x76a06
cmpq $0x0, 0x98(%rsp)
je 0x769ec
movl $0x4008, %edi           # imm = 0x4008
callq 0x5240
movq %rax, %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x18(%rsp)
movl (%rax), %ecx
movl %ecx, 0x20(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0x24(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x28(%rsp)
movl 0xc(%rax), %ecx
movl %ecx, 0x2c(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x30(%rsp)
movb 0x10(%rax), %dl
leaq 0x72081(%rip), %rcx     # 0xe89d2
leaq 0x53189(%rip), %rax     # 0xc9ae1
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0x38(%rsp)
callq 0x118f0
movq %rax, 0x40(%rsp)
jmp 0x76970
movl 0x2c(%rsp), %r9d
movl 0x28(%rsp), %r8d
movl 0x24(%rsp), %ecx
movl 0x20(%rsp), %edx
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %r10
movq 0x40(%rsp), %r11
movq %rsp, %rax
movq %r11, 0x10(%rax)
movq %r10, 0x8(%rax)
movq %rsi, (%rax)
leaq 0x72e72(%rip), %rsi     # 0xe981d
xorl %eax, %eax
callq 0x5c880
jmp 0x769b4
movq 0x18(%rsp), %rdi
leaq 0x892b0(%rip), %rsi     # 0xffc70
leaq -0x19f07(%rip), %rdx    # 0x5cac0
callq 0x5920
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
callq 0x53a0
jmp 0x76a06
movq 0x78(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x65ba0
addq $0xa8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x5970
nopw %cs:(%rax,%rax)
nopl (%rax)