// File: /workspace/github_cpp_makefile_star2_O3/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 $0x278, %rsp            # imm = 0x278
movq %rsi, %r15
movl %edi, %r12d
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
xorl %r14d, %r14d
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0x1a2c(%rip), %r13      # 0x645b
movq 0x4582(%rip), %rbp      # 0x8fb8
leaq 0x68(%rsp), %rbx
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x20b0
cmpl $0x66, %eax
jne 0x4af6
movq (%rbp), %rax
movzbl (%rax), %eax
movl $0x8, %r8d
cmpl $0x62, %eax
jg 0x4a9e
cmpl $0x42, %eax
je 0x4acc
cmpl $0x4c, %eax
je 0x4aba
cmpl $0x62, %eax
jne 0x5144
movl $0x3, %r8d
leaq 0x19ca(%rip), %rcx      # 0x6466
jmp 0x4ae2
cmpl $0x63, %eax
je 0x4ad5
cmpl $0x6c, %eax
je 0x4ac3
cmpl $0x6d, %eax
jne 0x5144
leaq 0x19cd(%rip), %rcx      # 0x6485
jmp 0x4ae2
leaq 0x19bb(%rip), %rcx      # 0x647c
jmp 0x4ae2
leaq 0x19a0(%rip), %rcx      # 0x646a
jmp 0x4ae2
leaq 0x19a0(%rip), %rcx      # 0x6473
jmp 0x4ae2
movl $0x7, %r8d
leaq 0x177a(%rip), %rcx      # 0x625c
movq 0x70(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2390
jmp 0x4a53
cmpl $0x71, %eax
jle 0x4b1f
cmpl $0x79, %eax
je 0x4b4b
cmpl $0x78, %eax
je 0x4b39
cmpl $0x72, %eax
jne 0x5144
movq (%rbp), %rdi
callq 0x23b0
movl %eax, (%rsp)
jmp 0x4a53
cmpl $-0x1, %eax
je 0x4b5c
cmpl $0x61, %eax
jne 0x5144
movb $0x1, %al
movq %rax, 0x8(%rsp)
jmp 0x4a53
movq (%rbp), %rdi
callq 0x23b0
movl %eax, 0x4(%rsp)
jmp 0x4a53
movq (%rbp), %rdi
callq 0x23b0
movl %eax, %r14d
jmp 0x4a53
movq 0x4465(%rip), %rbp      # 0x8fc8
movslq (%rbp), %rax
subl %eax, %r12d
cmpl $0x2, %r12d
jne 0x5149
movq (%r15,%rax,8), %rbx
leaq 0x10(%rsp), %r12
movq 0x8(%r12), %r13
movq %rbx, %rdi
callq 0x2120
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2390
movslq (%rbp), %rax
movq 0x8(%r15,%rax,8), %rbx
leaq 0x30(%rsp), %r15
movq 0x8(%r15), %r12
movq %rbx, %rdi
callq 0x2120
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2390
leaq 0xd8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x2be8
leaq 0x108(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x2c80
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4c22
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x22d0
cmpb $0x0, 0x120(%rsp)
movl 0x4(%rsp), %ebp
je 0x514e
testl %ebp, %ebp
setg %al
testl %r14d, %r14d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4c99
testb $0x1, 0x8(%rsp)
je 0x4cef
movq 0x4390(%rip), %rbx      # 0x8fe8
leaq 0x184d(%rip), %rsi      # 0x64ac
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2310
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2290
movsbl %al, %esi
movq 0x435e(%rip), %rdi      # 0x8fe8
callq 0x2060
movq %rax, %rdi
callq 0x21f0
jmp 0x4cef
testb $0x1, 0x8(%rsp)
je 0x4cd2
movl 0x108(%rsp), %ecx
testl %ebp, %ebp
jne 0x4cbb
movl %ecx, %eax
imull %r14d, %eax
cltd
idivl 0x10c(%rsp)
movl %eax, %ebp
testl %r14d, %r14d
jne 0x4cd9
movl 0x10c(%rsp), %eax
imull %ebp, %eax
cltd
idivl %ecx
movl %eax, %r14d
jmp 0x4cd9
movl 0x108(%rsp), %ecx
movl %ebp, %eax
testl %ebp, %ebp
movl %ecx, %ebp
cmovgl %eax, %ebp
testl %r14d, %r14d
jg 0x4cef
movl 0x10c(%rsp), %r14d
leaq 0x250(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3d2e
cvtsi2ss %ebp, %xmm0
cvtsi2ss %r14d, %xmm1
leaq 0x1a0(%rsp), %rdi
leaq 0x250(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x4412
leaq 0x1a0(%rsp), %rsi
movl (%rsi), %ebx
movl 0x4(%rsi), %ebp
movb 0x8(%rsi), %r14b
movb 0x9(%rsi), %r15b
leaq 0xe8(%rsp), %rdi
callq 0x2a98
movsbl %r14b, %ecx
movsbl %r15b, %r8d
leaq 0x1b8(%rsp), %rdi
leaq 0xe8(%rsp), %r9
movl %ebx, %esi
movl %ebp, %edx
callq 0x2640
leaq 0x1f0(%rsp), %r13
movq %r13, -0x10(%r13)
xorl %eax, %eax
movq %rax, -0x8(%r13)
movb $0x0, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13)
movq %rax, 0x20(%r13)
movb $0x1, -0x20(%r13)
movl $0x0, 0x50(%r13)
movsd 0x14fe(%rip), %xmm0     # 0x62a0
movsd %xmm0, 0x54(%r13)
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4dc9
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x22d0
xorl %eax, %eax
movl (%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
testl %ecx, %ecx
setg %al
movsd 0x194(%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, 0x244(%rsp)
movl 0x190(%rsp), %eax
movl %eax, 0x240(%rsp)
decl %eax
cmpl $0x3, %eax
ja 0x4fc9
leaq 0x1486(%rip), %rcx      # 0x62b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x2be8
leaq 0x1e0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2180
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x4e91
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rax
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
subq %rsi, %rbx
je 0x4f6e
js 0x513f
movq %rbx, %rdi
callq 0x22c0
movq %rax, %r14
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rax
movq %rax, %r15
subq %rsi, %r15
jmp 0x4f74
movl $0x20, %edi
callq 0x22c0
movups 0x16c(%rsp), %xmm0
movups %xmm0, (%rax)
movups 0x17c(%rsp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, 0x21c(%rsp)
movups %xmm1, 0x22c(%rsp)
movss 0x168(%rsp), %xmm0
movss %xmm0, 0x218(%rsp)
movb $0x1, 0x23c(%rsp)
movl $0x20, %esi
movq %rax, %rdi
jmp 0x4fc4
movss 0x168(%rsp), %xmm0
movss %xmm0, 0x218(%rsp)
movb $0x1, 0x23c(%rsp)
jmp 0x4fc9
movb 0x128(%rsp), %al
movb %al, 0x1d8(%rsp)
jmp 0x4fc9
xorl %r14d, %r14d
movq %rbx, %r15
leaq 0x200(%rsp), %r12
movq %r14, 0x50(%rsp)
movq %r14, 0x58(%rsp)
addq %r14, %rbx
movq %rbx, 0x60(%rsp)
cmpq %rsi, %rax
je 0x4f9e
movq %r14, %rdi
movq %r15, %rdx
callq 0x23d0
addq %r15, %r14
leaq 0x50(%rsp), %rsi
movq %r14, 0x8(%rsi)
movq %r12, %rdi
callq 0x5370
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4fc9
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x2be8
leaq 0x1b8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3278
movl %eax, %ebx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x5023
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x22d0
testl %ebx, %ebx
jne 0x519d
movq 0x200(%rsp), %rdi
testq %rdi, %rdi
je 0x5048
movq 0x210(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
movq 0x1e0(%rsp), %rdi
cmpq %r13, %rdi
je 0x5065
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x22d0
leaq 0x1b8(%rsp), %rdi
callq 0x29e4
leaq 0x1a0(%rsp), %rdi
callq 0x29e4
leaq 0x250(%rsp), %rdi
callq 0x3da6
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
leaq 0x78(%rsp), %rbx
leaq 0x40(%rsp), %r14
leaq 0x20(%rsp), %r15
je 0x50b8
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50d9
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x22d0
leaq 0x108(%rsp), %rdi
callq 0x29e4
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x50fd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x5114
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x512b
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x22d0
xorl %eax, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20f0
callq 0x49b8
callq 0x49b8
movq 0x3e93(%rip), %rdi      # 0x8fe8
leaq 0x1332(%rip), %rsi      # 0x648e
movl $0x13, %edx
callq 0x2310
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x3e71(%rip), %rdi      # 0x8fe8
callq 0x2310
movq %rax, %rbx
leaq 0x131c(%rip), %rsi      # 0x64a2
movl $0x9, %edx
movq %rax, %rdi
callq 0x2310
movq %rbx, %rdi
callq 0x2140
jmp 0x51d3
movq 0x3e44(%rip), %rdi      # 0x8fe8
leaq 0x1315(%rip), %rsi      # 0x64c0
movl $0x22, %edx
callq 0x2310
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x3e22(%rip), %rdi      # 0x8fe8
callq 0x2310
movq %rax, %rdi
callq 0x2140
movl $0x2, %edi
callq 0x2340
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x52a6
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
jmp 0x5236
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x52a6
movq 0xb8(%rsp), %rsi
jmp 0x5233
jmp 0x52a3
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x52a6
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x22d0
jmp 0x52a6
movq %rax, %rbx
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x52b3
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x22d0
jmp 0x52b3
movq %rax, %rbx
jmp 0x52b3
movq %rax, %rbx
jmp 0x52c0
jmp 0x5295
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x52da
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x22d0
jmp 0x52da
jmp 0x529e
jmp 0x52a3
movq %rax, %rbx
jmp 0x52cd
jmp 0x529e
jmp 0x529e
movq %rax, %rbx
jmp 0x52da
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x5336
leaq 0x1a0(%rsp), %rdi
callq 0x29e4
leaq 0x250(%rsp), %rdi
callq 0x3da6
leaq 0x108(%rsp), %rdi
callq 0x5336
leaq 0x78(%rsp), %r14
leaq 0x40(%rsp), %r15
leaq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdi
cmpq %rax, %rdi
je 0x5300
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x5317
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x532e
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x22d0
movq %rbx, %rdi
callq 0x2400