// File: /workspace/github_cpp_makefile_star2_O2/shirat74[P]resample/resample.cc
// Function: main
int
main (int argc, char *argv[])
{
  extern int   optind;
  extern char *optarg;
  int32_t      xsize = 0, ysize = 0, dpi = 0;
  std::string  filter;
  std::string  dstfile, srcfile;
  bool         keep_aspect = false;
  int          error = 0;

  // process command line options.
  {
    int  c;
    while ((c = getopt(argc, argv, "r:x:y:af:V")) != EOF) {
      switch(c) {
      case 'a': keep_aspect = true;   break;
      case 'r': dpi   = atoi(optarg); break;
      case 'x': xsize = atoi(optarg); break;
      case 'y': ysize = atoi(optarg); break;
      case 'f':
        switch(*optarg) {
        case 'b': filter = "Box"      ; break;
        case 'l': filter = "Bilinear" ; break;
        case 'B': filter = "B-Spline" ; break;
        case 'c': filter = "Bicubic"  ; break;
        case 'L': filter = "Lanczos3" ; break;
        case 'm': filter = "Mitchell" ; break;
        default: usage();
        }
        break;
      case '?': usage();
      default:  usage();
      }
    }
  }
  if((argc - optind) != 2)
    usage();
  srcfile = argv[optind];
  dstfile = argv[optind + 1];

  PNGImage src(srcfile);
  if (!src.valid()) {
    std::cerr << "Loading PNG image \"" << srcfile << "\" failed." << std::endl;
    exit(2);
  }
  if (xsize > 0 && ysize > 0) {
    if (keep_aspect)
      std::cerr << "Ignoring -a option." << std::endl;
  } else if (keep_aspect) {
    if (xsize == 0)
      xsize = ysize * src.getWidth()  / src.getHeight();
    if (ysize == 0)
      ysize = xsize * src.getHeight() / src.getWidth();
  }
  if (xsize <= 0)
    xsize = src.getWidth();
  if (ysize <= 0)
    ysize = src.getHeight();

  Resampler resampler(filter);
  Image ras = resampler.resampleImage(src, xsize, ysize);
  PNGImage dst(ras.getWidth(), ras.getHeight(),
               ras.getNComps(), ras.getBPC(), ras.getPixelBytes());
  if (dpi > 0)
    dst.setResolution(dpi, dpi);
  else { // Copy resolution setting from source image.
    dst.setResolution(src.getResolutionX(), src.getResolutionY());
  }
  // Copy colorspace related information
  // There are currently no easy way to copy it.
  {
    enum png_colorspace_type_e type = src.getColorSpaceType();
    dst.setColorSpaceType(type);
    switch (type) {
    case png_colorspace_iccp:
      dst.setICCProfileName(src.getICCProfileName());
      dst.setICCProfile(src.getICCProfile());
      break;
    case png_colorspace_srgb:
      dst.setsRGBIntent(src.getsRGBIntent());
      break;
    case png_colorspace_calibrated:
      {
        std::vector<float> c = src.getChromaticity();
        dst.setChromaticity(c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
        dst.setGamma(src.getGamma());
      }
      break;
    case png_colorspace_gamma_only:
      dst.setGamma(src.getGamma());
      break;
    case png_colorspace_device:
      // do nothing
      break;
    }
  }
  error = dst.save(dstfile);
  if (error) {
    std::cerr << "Could not save destination image: " << dstfile << std::endl;
    exit(2);
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %r15
movl %edi, %r12d
xorl %edx, %edx
leaq 0x48(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %dl, (%rax)
movb %dl, (%rcx)
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movl $0x0, 0x14(%rsp)
movb %dl, (%rax)
leaq 0x1c21(%rip), %r13      # 0x63d0
movq 0x4802(%rip), %r14      # 0x8fb8
leaq 0x1c22(%rip), %rbp      # 0x63df
leaq 0x88(%rsp), %rbx
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x20a0
cmpl $0x66, %eax
jne 0x4850
movq (%r14), %rax
movzbl (%rax), %eax
cmpl $0x42, %eax
je 0x483f
cmpl $0x4c, %eax
je 0x4824
cmpl $0x6d, %eax
je 0x482d
cmpl $0x63, %eax
je 0x4836
movq %rbp, %rsi
cmpl $0x6c, %eax
je 0x4846
cmpl $0x62, %eax
jne 0x4c3c
leaq 0x1bb9(%rip), %rsi      # 0x63db
jmp 0x4846
leaq 0x1bc6(%rip), %rsi      # 0x63f1
jmp 0x4846
leaq 0x1bc6(%rip), %rsi      # 0x63fa
jmp 0x4846
leaq 0x198f(%rip), %rsi      # 0x61cc
jmp 0x4846
leaq 0x1ba2(%rip), %rsi      # 0x63e8
movq %rbx, %rdi
callq 0x24a0
jmp 0x47dd
cmpl $-0x1, %eax
je 0x48ab
cmpl $0x61, %eax
je 0x487e
cmpl $0x79, %eax
je 0x4889
cmpl $0x78, %eax
je 0x489a
cmpl $0x72, %eax
jne 0x4c3c
movq (%r14), %rdi
callq 0x23b0
movl %eax, 0xc(%rsp)
jmp 0x47dd
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x47dd
movq (%r14), %rdi
callq 0x23b0
movl %eax, 0x14(%rsp)
jmp 0x47dd
movq (%r14), %rdi
callq 0x23b0
movl %eax, 0x10(%rsp)
jmp 0x47dd
movq 0x4716(%rip), %rbx      # 0x8fc8
movslq (%rbx), %rax
subl %eax, %r12d
cmpl $0x2, %r12d
jne 0x4c41
movq (%r15,%rax,8), %rsi
leaq 0x18(%rsp), %rdi
callq 0x24a0
movslq (%rbx), %rax
movq 0x8(%r15,%rax,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x24a0
leaq 0x108(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2360
leaq 0x128(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x2b6c
movl 0x14(%rsp), %ebx
movl 0x10(%rsp), %ebp
leaq 0x108(%rsp), %rdi
callq 0x2140
cmpb $0x0, 0x140(%rsp)
je 0x4c46
testl %ebp, %ebp
setg %al
testl %ebx, %ebx
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4961
testb $0x1, 0x8(%rsp)
je 0x49b2
movq 0x469d(%rip), %rdi      # 0x8fe8
leaq 0x1acf(%rip), %rsi      # 0x6421
callq 0x22b0
movq %rax, %rdi
callq 0x2160
jmp 0x49b2
testb $0x1, 0x8(%rsp)
je 0x4997
movl 0x128(%rsp), %ecx
testl %ebp, %ebp
jne 0x4982
movl %ecx, %eax
imull %ebx, %eax
cltd
idivl 0x12c(%rsp)
movl %eax, %ebp
testl %ebx, %ebx
jne 0x499e
movl 0x12c(%rsp), %eax
imull %ebp, %eax
cltd
idivl %ecx
movl %eax, %ebx
jmp 0x499e
movl 0x128(%rsp), %ecx
movl %ebp, %eax
testl %ebp, %ebp
movl %ecx, %ebp
cmovgl %eax, %ebp
testl %ebx, %ebx
jg 0x49b2
movl 0x12c(%rsp), %ebx
leaq 0x1c0(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3a62
cvtsi2ss %ebp, %xmm0
cvtsi2ss %ebx, %xmm1
leaq 0x70(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0x4096
leaq 0x70(%rsp), %rsi
movl (%rsi), %ebx
movl 0x4(%rsi), %ebp
movb 0x8(%rsi), %r14b
movb 0x9(%rsi), %r15b
leaq 0xe8(%rsp), %rdi
callq 0x2a20
movsbl %r14b, %ecx
movsbl %r15b, %r8d
leaq 0x1e8(%rsp), %rdi
leaq 0xe8(%rsp), %r9
movl %ebx, %esi
movl %ebp, %edx
callq 0x4d7e
leaq 0xe8(%rsp), %rdi
callq 0x2140
xorl %eax, %eax
movl 0xc(%rsp), %ecx
cvtsi2ss %ecx, %xmm0
testl %ecx, %ecx
setg %al
movsd 0x1b4(%rsp), %xmm1
movd %eax, %xmm2
pshufd $0x50, %xmm2, %xmm2     # xmm2 = xmm2[0,0,1,1]
pslld $0x1f, %xmm2
psrad $0x1f, %xmm2
unpcklps %xmm0, %xmm0            # xmm0 = xmm0[0,0,1,1]
andps %xmm2, %xmm0
andnps %xmm1, %xmm2
orps %xmm0, %xmm2
movlps %xmm2, 0x274(%rsp)
movl 0x1b0(%rsp), %eax
movl %eax, 0x270(%rsp)
decl %eax
cmpl $0x3, %eax
ja 0x4b98
leaq 0x177b(%rip), %rcx      # 0x6210
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x150(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x2360
leaq 0x210(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x21a0
leaq 0xc8(%rsp), %rdi
callq 0x2140
leaq 0x170(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0x4f44
leaq 0x230(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x4e50
leaq 0x58(%rsp), %rdi
callq 0x3518
jmp 0x4b98
leaq 0x280(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x4dc2
leaq 0x280(%rsp), %rdi
movq (%rdi), %rax
movsd 0x4(%rax), %xmm0
movss 0x1c(%rax), %xmm1
movups 0xc(%rax), %xmm2
movss (%rax), %xmm3
movups %xmm2, 0x258(%rsp)
movhps 0x188(%rsp), %xmm3      # xmm3 = xmm3[0,1],mem[0,1]
movss %xmm1, 0x268(%rsp)
shufps $0x42, %xmm0, %xmm3     # xmm3 = xmm3[2,0],xmm0[0,1]
movups %xmm3, 0x248(%rsp)
movb $0x1, 0x26c(%rsp)
callq 0x5032
jmp 0x4b98
movss 0x188(%rsp), %xmm0
movss %xmm0, 0x248(%rsp)
movb $0x1, 0x26c(%rsp)
jmp 0x4b98
movb 0x148(%rsp), %al
movb %al, 0x208(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2360
leaq 0x1e8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x302e
movl %eax, %ebx
leaq 0xa8(%rsp), %rdi
callq 0x2140
testl %ebx, %ebx
jne 0x4c7f
leaq 0x1e8(%rsp), %rdi
callq 0x4e3a
leaq 0x70(%rsp), %rdi
callq 0x28f4
leaq 0x1c0(%rsp), %rdi
callq 0x3ad6
leaq 0x128(%rsp), %rdi
callq 0x4e3a
leaq 0x18(%rsp), %rdi
callq 0x2140
leaq 0x38(%rsp), %rdi
callq 0x2140
leaq 0x88(%rsp), %rdi
callq 0x2140
xorl %eax, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4730
callq 0x4730
movq 0x439b(%rip), %rdi      # 0x8fe8
leaq 0x17af(%rip), %rsi      # 0x6403
callq 0x22b0
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x2290
leaq 0x17aa(%rip), %rsi      # 0x6417
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x2160
jmp 0x4ca7
movq 0x4362(%rip), %rdi      # 0x8fe8
leaq 0x17a8(%rip), %rsi      # 0x6435
callq 0x22b0
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x2160
pushq $0x2
popq %rdi
callq 0x2330
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x3518
jmp 0x4d1b
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x4cda
jmp 0x4d18
jmp 0x4d18
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x2140
jmp 0x4d1b
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x2140
jmp 0x4d28
movq %rax, %rbx
jmp 0x4d28
movq %rax, %rbx
jmp 0x4d32
jmp 0x4d13
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x2140
jmp 0x4d55
jmp 0x4d52
movq %rax, %rbx
jmp 0x4d3f
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0x4e3a
leaq 0x70(%rsp), %rdi
callq 0x28f4
leaq 0x1c0(%rsp), %rdi
callq 0x3ad6
leaq 0x128(%rsp), %rdi
callq 0x4e3a
jmp 0x4d55
jmp 0x4d52
jmp 0x4d52
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2140
leaq 0x38(%rsp), %rdi
callq 0x2140
leaq 0x88(%rsp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x2420