// File: lvandeve[P]lodepng/lodepng_benchmark.cpp
// Function: testEncode(Image&)
std::vector<unsigned char> testEncode(Image& image) {
  unsigned char* encoded = 0;
  size_t encoded_size = 0;
  lodepng::State state;
  state.info_raw.colortype = image.colorType;
  state.info_raw.bitdepth = image.bitDepth;

  // Try custom compression settings
  if(apply_mods) {
    //state.encoder.filter_strategy = LFS_ZERO;
    //state.encoder.filter_strategy = LFS_ENTROPY;
    //state.encoder.filter_strategy = LFS_FOUR;
    //state.encoder.zlibsettings.btype = 0;
    //state.encoder.zlibsettings.btype = 1;
    //state.encoder.auto_convert = 0;
    //state.encoder.zlibsettings.use_lz77 = 0;
    state.encoder.zlibsettings.windowsize = 1;
    //state.encoder.zlibsettings.windowsize = 32768;
  }

  double t_enc0 = getTime();

  unsigned error_enc = lodepng_encode(&encoded, &encoded_size, &image.data[0],
                                      image.width, image.height, &state);

  double t_enc1 = getTime();

  assertEquals(0, error_enc, "encoder error");

  total_raw_enc_size += lodepng_get_raw_size(image.width, image.height, &state.info_raw);
  total_png_out_size += encoded_size;
  total_enc_time += (t_enc1 - t_enc0);

  if(verbose) {
    printValue("encoding time", t_enc1 - t_enc0, "s");
    std::cout << "compression: " << ((double)(encoded_size) / (double)(image.data.size())) * 100 << "%"
              << ", ratio: " << ((double)(image.data.size()) / (double)(encoded_size))
              << ", size: " << encoded_size
              << ", bpp: " << (8.0 * encoded_size / image.width / image.height) << std::endl;
  }

  if(!dumpdir.empty()) {
    std::string dumpname = dumpdir;
    if(dumpname[dumpname.size() - 1] != '/') dumpname += "/";
    dumpname += image.name;
    if(lodepng_save_file(encoded, encoded_size, dumpname.c_str())) {
      std::cout << "WARNING: failed to dump " << dumpname << ". The dir must already exist." << std::endl;
    } else if(verbose) {
      std::cout << "saved to: " << dumpname << std::endl;
    }
  }

  // output image stats
  {
    lodepng::State inspect;
    unsigned w, h;
    lodepng_inspect(&w, &h, &inspect, encoded, encoded_size);
    total_raw_out_size += lodepng_get_raw_size(w, h, &inspect.info_png.color);
  }

  std::vector<unsigned char> result(encoded, encoded + encoded_size);
  free(encoded);
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x730, %rsp            # imm = 0x730
movq %rdi, -0x608(%rbp)
movq %rdi, %rax
movq %rax, -0x600(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x108d0
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x1f8(%rbp)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x1f4(%rbp)
testb $0x1, 0xf218(%rip)      # 0x2a1c9
je 0x1afbd
movl $0x1, -0x248(%rbp)
callq 0x1aeb0
movsd %xmm0, -0x610(%rbp)
jmp 0x1afcc
movsd -0x610(%rbp), %xmm0
movsd %xmm0, -0x2a8(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x193f0
movq %rax, -0x618(%rbp)
jmp 0x1aff2
movq -0x618(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
movl 0x1c(%rax), %r8d
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x2a0(%rbp), %r9
callq 0xc4b0
movl %eax, -0x61c(%rbp)
jmp 0x1b020
movl -0x61c(%rbp), %eax
movl %eax, -0x2b8(%rbp)
callq 0x1aeb0
movsd %xmm0, -0x628(%rbp)
jmp 0x1b03b
movsd -0x628(%rbp), %xmm0
movsd %xmm0, -0x2c0(%rbp)
movl $0x0, -0x2c4(%rbp)
leaq -0x2e9(%rbp), %rdi
movq %rdi, -0x630(%rbp)
callq 0x2300
movq -0x630(%rbp), %rdx
leaq 0x89ea(%rip), %rsi      # 0x23a60
leaq -0x2e8(%rbp), %rdi
callq 0x2250
jmp 0x1b084
leaq -0x2c4(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
leaq -0x2e8(%rbp), %rdx
callq 0x1d7f0
jmp 0x1b0a0
leaq -0x2e8(%rbp), %rdi
callq 0x2348
jmp 0x1b0ae
leaq -0x2e9(%rbp), %rdi
callq 0x21b0
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
movl 0x1c(%rax), %esi
leaq -0x1f8(%rbp), %rdx
callq 0x4a80
movq %rax, -0x638(%rbp)
jmp 0x1b0d9
movq -0x638(%rbp), %rax
addq 0xf129(%rip), %rax      # 0x2a210
movq %rax, 0xf122(%rip)      # 0x2a210
movq -0x20(%rbp), %rax
addq 0xf11f(%rip), %rax      # 0x2a218
movq %rax, 0xf118(%rip)      # 0x2a218
movsd -0x2c0(%rbp), %xmm0
subsd -0x2a8(%rbp), %xmm0
addsd 0xf0f0(%rip), %xmm0     # 0x2a208
movsd %xmm0, 0xf0e8(%rip)     # 0x2a208
testb $0x1, 0xf101(%rip)      # 0x2a228
je 0x1b4fc
leaq -0x311(%rbp), %rdi
movq %rdi, -0x640(%rbp)
callq 0x2300
movq -0x640(%rbp), %rdx
leaq 0x8920(%rip), %rsi      # 0x23a6e
leaq -0x310(%rbp), %rdi
callq 0x2250
jmp 0x1b15c
movsd -0x2c0(%rbp), %xmm0
movsd -0x2a8(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x320(%rbp)
leaq -0x341(%rbp), %rdi
movq %rdi, -0x648(%rbp)
callq 0x2300
movq -0x648(%rbp), %rdx
leaq 0x8967(%rip), %rsi      # 0x23b00
leaq -0x340(%rbp), %rdi
callq 0x2250
jmp 0x1b1a7
leaq -0x310(%rbp), %rdi
leaq -0x320(%rbp), %rsi
leaq -0x340(%rbp), %rdx
callq 0x1d8b0
jmp 0x1b1c3
leaq -0x340(%rbp), %rdi
callq 0x2348
jmp 0x1b1d1
leaq -0x341(%rbp), %rdi
callq 0x21b0
leaq -0x310(%rbp), %rdi
callq 0x2348
jmp 0x1b1eb
leaq -0x311(%rbp), %rdi
callq 0x21b0
movq 0xedda(%rip), %rdi      # 0x29fd8
leaq 0x8877(%rip), %rsi      # 0x23a7c
callq 0x2150
movq %rax, -0x650(%rbp)
jmp 0x1b213
movaps 0x8806(%rip), %xmm1     # 0x23a20
movq -0x20(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x8805(%rip), %xmm1     # 0x23a30
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x660(%rbp)
movq -0x10(%rbp), %rdi
callq 0x19200
movq %rax, -0x658(%rbp)
jmp 0x1b254
movq -0x650(%rbp), %rdi
movsd -0x660(%rbp), %xmm0
movq -0x658(%rbp), %rax
movq %rax, %xmm1
movaps 0x87aa(%rip), %xmm2     # 0x23a20
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x87ae(%rip), %xmm2     # 0x23a30
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x875b(%rip), %xmm1     # 0x239f8
mulsd %xmm1, %xmm0
callq 0x2310
movq %rax, -0x668(%rbp)
jmp 0x1b2af
movq -0x668(%rbp), %rdi
leaq 0x87cd(%rip), %rsi      # 0x23a8a
callq 0x2150
movq %rax, -0x670(%rbp)
jmp 0x1b2cb
movq -0x670(%rbp), %rdi
leaq 0x87b3(%rip), %rsi      # 0x23a8c
callq 0x2150
movq %rax, -0x678(%rbp)
jmp 0x1b2e7
movq -0x10(%rbp), %rdi
callq 0x19200
movq %rax, -0x680(%rbp)
jmp 0x1b2f9
movq -0x678(%rbp), %rdi
movq -0x680(%rbp), %rax
movq %rax, %xmm0
movaps 0x870d(%rip), %xmm3     # 0x23a20
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x8711(%rip), %xmm2     # 0x23a30
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0x2310
movq %rax, -0x688(%rbp)
jmp 0x1b358
movq -0x688(%rbp), %rdi
leaq 0x8730(%rip), %rsi      # 0x23a96
callq 0x2150
movq %rax, -0x690(%rbp)
jmp 0x1b374
movq -0x690(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2050
movq %rax, -0x698(%rbp)
jmp 0x1b38d
movq -0x698(%rbp), %rdi
leaq 0x8ad4(%rip), %rsi      # 0x23e6f
callq 0x2150
movq %rax, -0x6a0(%rbp)
jmp 0x1b3a9
movq -0x6a0(%rbp), %rdi
movaps 0x8669(%rip), %xmm1     # 0x23a20
movq -0x20(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x8668(%rip), %xmm1     # 0x23a30
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x8621(%rip), %xmm1     # 0x23a00
mulsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
movl 0x1c(%rax), %eax
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
callq 0x2310
movq %rax, -0x6a8(%rbp)
jmp 0x1b40d
movq -0x6a8(%rbp), %rdi
movq 0xeba5(%rip), %rsi      # 0x29fc0
callq 0x21a0
jmp 0x1b422
jmp 0x1b4fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x1b85e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x1b474
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x2348
jmp 0x1b472
jmp 0x1b474
leaq -0x2e9(%rbp), %rdi
callq 0x21b0
jmp 0x1b85e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x1b4eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x1b4cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x2348
jmp 0x1b4cd
jmp 0x1b4cf
leaq -0x341(%rbp), %rdi
callq 0x21b0
leaq -0x310(%rbp), %rdi
callq 0x2348
jmp 0x1b4e9
jmp 0x1b4eb
leaq -0x311(%rbp), %rdi
callq 0x21b0
jmp 0x1b85e
leaq 0xed2d(%rip), %rdi      # 0x2a230
callq 0x22d0
movb %al, -0x6a9(%rbp)
jmp 0x1b510
movb -0x6a9(%rbp), %al
testb $0x1, %al
jne 0x1b6fa
jmp 0x1b520
leaq 0xed09(%rip), %rsi      # 0x2a230
leaq -0x368(%rbp), %rdi
callq 0x20b0
jmp 0x1b535
leaq -0x368(%rbp), %rdi
callq 0x20e0
movq %rax, -0x6b8(%rbp)
jmp 0x1b54a
movq -0x6b8(%rbp), %rsi
decq %rsi
leaq -0x368(%rbp), %rdi
callq 0x2330
movq %rax, -0x6c0(%rbp)
jmp 0x1b569
movq -0x6c0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x1b5b2
leaq 0x8520(%rip), %rsi      # 0x23a9f
leaq -0x368(%rbp), %rdi
callq 0x2140
jmp 0x1b58d
jmp 0x1b5b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x2348
jmp 0x1b6f5
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
leaq -0x368(%rbp), %rdi
callq 0x2210
jmp 0x1b5c8
movq -0x18(%rbp), %rax
movq %rax, -0x6d8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x6d0(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x20a0
movq %rax, -0x6c8(%rbp)
jmp 0x1b5f3
movq -0x6c8(%rbp), %rdx
movq -0x6d0(%rbp), %rsi
movq -0x6d8(%rbp), %rdi
callq 0x25d0
movl %eax, -0x6dc(%rbp)
jmp 0x1b615
movl -0x6dc(%rbp), %eax
cmpl $0x0, %eax
je 0x1b68b
movq 0xe9b1(%rip), %rdi      # 0x29fd8
leaq 0x8473(%rip), %rsi      # 0x23aa1
callq 0x2150
movq %rax, -0x6e8(%rbp)
jmp 0x1b63c
movq -0x6e8(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0x2120
movq %rax, -0x6f0(%rbp)
jmp 0x1b658
movq -0x6f0(%rbp), %rdi
leaq 0x8454(%rip), %rsi      # 0x23aba
callq 0x2150
movq %rax, -0x6f8(%rbp)
jmp 0x1b674
movq -0x6f8(%rbp), %rdi
movq 0xe93e(%rip), %rsi      # 0x29fc0
callq 0x21a0
jmp 0x1b689
jmp 0x1b6e5
testb $0x1, 0xeb96(%rip)      # 0x2a228
je 0x1b6e3
movq 0xe93d(%rip), %rdi      # 0x29fd8
leaq 0x8436(%rip), %rsi      # 0x23ad8
callq 0x2150
movq %rax, -0x700(%rbp)
jmp 0x1b6b0
movq -0x700(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0x2120
movq %rax, -0x708(%rbp)
jmp 0x1b6cc
movq -0x708(%rbp), %rdi
movq 0xe8e6(%rip), %rsi      # 0x29fc0
callq 0x21a0
jmp 0x1b6e1
jmp 0x1b6e3
jmp 0x1b6e5
leaq -0x368(%rbp), %rdi
callq 0x2348
jmp 0x1b6f3
jmp 0x1b6fa
jmp 0x1b85e
leaq -0x5e8(%rbp), %rdi
callq 0x108d0
jmp 0x1b708
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x5ec(%rbp), %rdi
leaq -0x5f0(%rbp), %rsi
leaq -0x5e8(%rbp), %rdx
callq 0x8fd0
jmp 0x1b72c
movl -0x5ec(%rbp), %edi
movl -0x5f0(%rbp), %esi
leaq -0x508(%rbp), %rdx
callq 0x4a80
movq %rax, -0x710(%rbp)
jmp 0x1b74d
movq -0x710(%rbp), %rcx
movq 0xeac5(%rip), %rax      # 0x2a220
addq %rcx, %rax
movq %rax, 0xeabb(%rip)      # 0x2a220
leaq -0x5e8(%rbp), %rdi
callq 0x10920
jmp 0x1b773
movb $0x0, -0x5f1(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x728(%rbp)
movq -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x720(%rbp)
leaq -0x5f2(%rbp), %rdi
movq %rdi, -0x718(%rbp)
callq 0x1ada0
movq -0x608(%rbp), %rdi
movq -0x728(%rbp), %rsi
movq -0x720(%rbp), %rdx
movq -0x718(%rbp), %rcx
callq 0x1d920
jmp 0x1b7c9
leaq -0x5f2(%rbp), %rdi
callq 0x1adf0
movq -0x18(%rbp), %rdi
callq 0x21f0
movb $0x1, -0x5f1(%rbp)
testb $0x1, -0x5f1(%rbp)
jne 0x1b842
jmp 0x1b832
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x5e8(%rbp), %rdi
callq 0x10920
jmp 0x1b810
jmp 0x1b85e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x5f2(%rbp), %rdi
callq 0x1adf0
jmp 0x1b85e
movq -0x608(%rbp), %rdi
callq 0x192c0
jmp 0x1b840
jmp 0x1b842
leaq -0x2a0(%rbp), %rdi
callq 0x10920
movq -0x600(%rbp), %rax
addq $0x730, %rsp            # imm = 0x730
popq %rbp
retq
leaq -0x2a0(%rbp), %rdi
callq 0x10920
jmp 0x1b86c
jmp 0x1b86e
movq -0x2b0(%rbp), %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x19290
nopw %cs:(%rax,%rax)