// File: /workspace/github_cpp_makefile_star2_O1/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 0x1ab8(%rip), %r13      # 0x640b
movq 0x465e(%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 0x4a1a
movq (%rbp), %rax
movzbl (%rax), %eax
movl $0x8, %r8d
cmpl $0x62, %eax
jg 0x49c2
cmpl $0x42, %eax
je 0x49f0
cmpl $0x4c, %eax
je 0x49de
cmpl $0x62, %eax
jne 0x50f5
movl $0x3, %r8d
leaq 0x1a56(%rip), %rcx      # 0x6416
jmp 0x4a06
cmpl $0x63, %eax
je 0x49f9
cmpl $0x6c, %eax
je 0x49e7
cmpl $0x6d, %eax
jne 0x50f5
leaq 0x1a59(%rip), %rcx      # 0x6435
jmp 0x4a06
leaq 0x1a47(%rip), %rcx      # 0x642c
jmp 0x4a06
leaq 0x1a2c(%rip), %rcx      # 0x641a
jmp 0x4a06
leaq 0x1a2c(%rip), %rcx      # 0x6423
jmp 0x4a06
movl $0x7, %r8d
leaq 0x1816(%rip), %rcx      # 0x621c
movq 0x70(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2390
jmp 0x4977
cmpl $0x71, %eax
jle 0x4a43
cmpl $0x79, %eax
je 0x4a6f
cmpl $0x78, %eax
je 0x4a5d
cmpl $0x72, %eax
jne 0x50f5
movq (%rbp), %rdi
callq 0x23b0
movl %eax, (%rsp)
jmp 0x4977
cmpl $-0x1, %eax
je 0x4a80
cmpl $0x61, %eax
jne 0x50f5
movb $0x1, %al
movq %rax, 0x8(%rsp)
jmp 0x4977
movq (%rbp), %rdi
callq 0x23b0
movl %eax, 0x4(%rsp)
jmp 0x4977
movq (%rbp), %rdi
callq 0x23b0
movl %eax, %r14d
jmp 0x4977
movq 0x4541(%rip), %rbp      # 0x8fc8
subl (%rbp), %r12d
cmpl $0x2, %r12d
jne 0x50fa
movslq (%rbp), %rax
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 0x170(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x160(%rsp), %rdi
callq 0x2bfe
leaq 0x88(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x2c90
movq 0x160(%rsp), %rdi
cmpq %r15, %rdi
je 0x4b47
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x22d0
cmpb $0x0, 0xa0(%rsp)
movl 0x4(%rsp), %r15d
je 0x50ff
testl %r15d, %r15d
setg %al
testl %r14d, %r14d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4bc0
testb $0x1, 0x8(%rsp)
je 0x4bfd
movq 0x4469(%rip), %rbx      # 0x8fe8
leaq 0x18d6(%rip), %rsi      # 0x645c
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 0x4437(%rip), %rdi      # 0x8fe8
callq 0x2060
movq %rax, %rdi
callq 0x21f0
jmp 0x4bfd
testb $0x1, 0x8(%rsp)
je 0x4bfd
testl %r15d, %r15d
jne 0x4be2
movl 0x88(%rsp), %eax
imull %r14d, %eax
cltd
idivl 0x8c(%rsp)
movl %eax, %r15d
testl %r14d, %r14d
jne 0x4bfd
movl 0x8c(%rsp), %eax
imull %r15d, %eax
cltd
idivl 0x88(%rsp)
movl %eax, %r14d
movl 0x88(%rsp), %ebp
movl 0x8c(%rsp), %ebx
leaq 0x250(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3cfa
testl %r14d, %r14d
cmovgl %r14d, %ebx
testl %r15d, %r15d
cmovgl %r15d, %ebp
cvtsi2ss %ebp, %xmm0
cvtsi2ss %ebx, %xmm1
leaq 0x238(%rsp), %rdi
leaq 0x250(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x43ee
leaq 0x238(%rsp), %rsi
movl (%rsi), %ebx
movl 0x4(%rsi), %ebp
movb 0x8(%rsi), %r14b
movb 0x9(%rsi), %r15b
leaq 0x180(%rsp), %rdi
callq 0x2abe
movsbl %r14b, %ecx
movsbl %r15b, %r8d
leaq 0x1a0(%rsp), %rdi
leaq 0x180(%rsp), %r9
movl %ebx, %esi
movl %ebp, %edx
callq 0x2640
leaq 0x1d8(%rsp), %r12
movq %r12, -0x10(%r12)
xorl %eax, %eax
movq %rax, -0x8(%r12)
movb $0x0, (%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movq %rax, 0x20(%r12)
movb $0x1, -0x20(%r12)
movabsq $0x4290000000000000, %rax # imm = 0x4290000000000000
movq %rax, 0x50(%r12)
movl $0x42900000, 0x58(%r12) # imm = 0x42900000
leaq 0x190(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4cf9
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x22d0
movl (%rsp), %eax
testl %eax, %eax
jg 0x4d14
movss 0x114(%rsp), %xmm0
movss 0x118(%rsp), %xmm1
jmp 0x4d1e
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movaps %xmm0, %xmm1
movss %xmm0, 0x22c(%rsp)
movss %xmm1, 0x230(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x228(%rsp)
decl %eax
cmpl $0x3, %eax
ja 0x4f7a
leaq 0x1510(%rip), %rcx      # 0x6260
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x150(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x140(%rsp), %rdi
callq 0x2bfe
leaq 0x1c8(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x2180
movq 0x140(%rsp), %rdi
cmpq %r14, %rdi
je 0x4db7
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0xd8(%rsp), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
subq 0xd0(%rsp), %rbx
je 0x4f12
js 0x50f0
movq %rbx, %rdi
callq 0x22c0
movq %rax, %r14
jmp 0x4f15
movl $0x20, %edi
callq 0x22c0
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movss 0xec(%rsp), %xmm0
movss %xmm0, (%rax)
movss 0xf0(%rsp), %xmm1
movss %xmm1, 0x4(%rax)
movss 0xf4(%rsp), %xmm2
movss %xmm2, 0x8(%rax)
movss 0xf8(%rsp), %xmm3
movss %xmm3, 0xc(%rax)
movss 0xfc(%rsp), %xmm4
movss %xmm4, 0x10(%rax)
movss 0x100(%rsp), %xmm5
movss %xmm5, 0x14(%rax)
movss 0x104(%rsp), %xmm6
movss %xmm6, 0x18(%rax)
movss 0x108(%rsp), %xmm7
movss %xmm7, 0x1c(%rax)
movss %xmm0, 0x204(%rsp)
movss %xmm1, 0x208(%rsp)
movss %xmm2, 0x20c(%rsp)
movss %xmm3, 0x210(%rsp)
movss %xmm4, 0x214(%rsp)
movss %xmm5, 0x218(%rsp)
movss %xmm6, 0x21c(%rsp)
movss %xmm7, 0x220(%rsp)
movss 0xe8(%rsp), %xmm0
movss %xmm0, 0x200(%rsp)
movb $0x1, 0x224(%rsp)
movl $0x20, %esi
movq %rax, %rdi
jmp 0x4f75
movss 0xe8(%rsp), %xmm0
movss %xmm0, 0x200(%rsp)
movb $0x1, 0x224(%rsp)
jmp 0x4f7a
movb 0xa8(%rsp), %al
movb %al, 0x1c0(%rsp)
jmp 0x4f7a
xorl %r14d, %r14d
leaq 0x1e8(%rsp), %r15
movq %r14, 0x50(%rsp)
movq %r14, 0x58(%rsp)
addq %r14, %rbx
movq %rbx, 0x60(%rsp)
movq 0xd0(%rsp), %rsi
movq 0xd8(%rsp), %rbx
subq %rsi, %rbx
je 0x4f4f
movq %r14, %rdi
movq %rbx, %rdx
callq 0x23d0
addq %rbx, %r14
leaq 0x50(%rsp), %rsi
movq %r14, 0x8(%rsi)
movq %r15, %rdi
callq 0x5322
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4f7a
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
leaq 0x130(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x120(%rsp), %rdi
callq 0x2bfe
leaq 0x1a0(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x322e
movl %eax, %ebx
movq 0x120(%rsp), %rdi
cmpq %r14, %rdi
je 0x4fd4
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x22d0
testl %ebx, %ebx
jne 0x514e
movq 0x1e8(%rsp), %rdi
testq %rdi, %rdi
je 0x4ff9
movq 0x1f8(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
movq 0x1c8(%rsp), %rdi
cmpq %r12, %rdi
je 0x5016
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x22d0
leaq 0x1a0(%rsp), %rdi
callq 0x2a0a
leaq 0x238(%rsp), %rdi
callq 0x2a0a
leaq 0x250(%rsp), %rdi
callq 0x3d72
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
leaq 0x78(%rsp), %rbx
leaq 0x40(%rsp), %r14
leaq 0x20(%rsp), %r15
je 0x5069
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x508a
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x22d0
leaq 0x88(%rsp), %rdi
callq 0x2a0a
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x50ae
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x50c5
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x50dc
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 0x48dc
callq 0x48dc
movq 0x3ee2(%rip), %rdi      # 0x8fe8
leaq 0x1331(%rip), %rsi      # 0x643e
movl $0x13, %edx
callq 0x2310
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x3ec0(%rip), %rdi      # 0x8fe8
callq 0x2310
movq %rax, %rbx
leaq 0x131b(%rip), %rsi      # 0x6452
movl $0x9, %edx
movq %rax, %rdi
callq 0x2310
movq %rbx, %rdi
callq 0x2140
jmp 0x5184
movq 0x3e93(%rip), %rdi      # 0x8fe8
leaq 0x1314(%rip), %rsi      # 0x6470
movl $0x22, %edx
callq 0x2310
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x3e71(%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 0x5257
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
jmp 0x51e7
movq %rax, %rbx
movq 0x140(%rsp), %rdi
cmpq %r14, %rdi
je 0x5257
movq 0x150(%rsp), %rsi
jmp 0x51e4
jmp 0x5254
movq %rax, %rbx
movq 0x120(%rsp), %rdi
cmpq %r14, %rdi
je 0x5257
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x22d0
jmp 0x5257
movq %rax, %rbx
leaq 0x190(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5264
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x22d0
jmp 0x5264
movq %rax, %rbx
jmp 0x5264
movq %rax, %rbx
jmp 0x5271
jmp 0x5246
movq %rax, %rbx
movq 0x160(%rsp), %rdi
cmpq %r15, %rdi
je 0x528b
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x22d0
jmp 0x528b
jmp 0x524f
jmp 0x5254
movq %rax, %rbx
jmp 0x527e
jmp 0x524f
jmp 0x524f
movq %rax, %rbx
jmp 0x528b
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x52e8
leaq 0x238(%rsp), %rdi
callq 0x2a0a
leaq 0x250(%rsp), %rdi
callq 0x3d72
leaq 0x88(%rsp), %rdi
callq 0x52e8
leaq 0x78(%rsp), %r14
leaq 0x40(%rsp), %r15
leaq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdi
cmpq %rax, %rdi
je 0x52b1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x52c8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x52df
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x22d0
movq %rbx, %rdi
callq 0x2400
nop