// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x548, %rsp            # imm = 0x548
movq %rsi, %r14
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, (%rsp)
leaq 0x2c8(%rsp), %r15
movq %r15, %rdi
callq 0xd258
movq 0x20(%r14), %rax
movq %rax, 0xa8(%r15)
cmpb $0x1, 0xc6f8(%rip)      # 0x1d1c9
jne 0x10ade
movl $0x1, 0x320(%rsp)
callq 0x21d0
movl %eax, %ebp
movq (%r14), %rdx
movl 0x18(%r14), %ecx
movl 0x1c(%r14), %r8d
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
leaq 0x2c8(%rsp), %r9
callq 0xa954
movl %eax, 0x1c(%rsp)
callq 0x21d0
movl %eax, %r15d
movl $0x0, 0x20(%rsp)
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x7267(%rip), %rsi      # 0x17d90
leaq 0x726d(%rip), %rdx      # 0x17d9d
leaq 0x48(%rsp), %rdi
callq 0x12d56
leaq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x129e4
leaq 0x370(%rsp), %r12
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x10b65
callq 0x2180
movl 0x18(%r14), %edi
movl 0x1c(%r14), %esi
movq %r12, %rdx
callq 0x597f
movl %ebp, %ecx
movl %r15d, %edx
cvtsi2sd %rcx, %xmm0
cvtsi2sd %rdx, %xmm1
divsd 0x7194(%rip), %xmm0     # 0x17d20
divsd 0x718c(%rip), %xmm1     # 0x17d20
subsd %xmm0, %xmm1
addq %rax, 0xc671(%rip)      # 0x1d210
movq (%rsp), %rax
addq %rax, 0xc66e(%rip)      # 0x1d218
movsd 0xc656(%rip), %xmm0     # 0x1d208
addsd %xmm1, %xmm0
movsd %xmm0, 0xc64a(%rip)     # 0x1d208
cmpb $0x1, 0xc663(%rip)      # 0x1d228
jne 0x10df7
movsd %xmm1, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x71be(%rip), %rsi      # 0x17d9e
leaq 0x71c4(%rip), %rdx      # 0x17dab
callq 0x12d56
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7228(%rip), %rsi      # 0x17e30
leaq 0x7222(%rip), %rdx      # 0x17e31
leaq 0x20(%rsp), %rdi
callq 0x12d56
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x12a86
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x10c3c
callq 0x2180
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x10c4b
callq 0x2180
movq 0xc386(%rip), %rdi      # 0x1cfd8
leaq 0x7153(%rip), %rsi      # 0x17dac
movl $0xd, %edx
callq 0x2200
movsd (%rsp), %xmm1
movsd 0x70e0(%rip), %xmm2     # 0x17d50
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x70e5(%rip), %xmm3     # 0x17d60
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq 0x8(%r14), %rax
subq (%r14), %rax
movq %rax, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
mulsd 0x7071(%rip), %xmm0     # 0x17d28
movq 0xc31a(%rip), %rdi      # 0x1cfd8
callq 0x22a0
movq %rax, %r15
leaq 0x70ed(%rip), %rsi      # 0x17dba
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
leaq 0x70db(%rip), %rsi      # 0x17dbc
movl $0x9, %edx
movq %r15, %rdi
callq 0x2200
movq 0x8(%r14), %rax
subq (%r14), %rax
movq %rax, %xmm1
movq 0x704e(%rip), %xmm2     # 0x17d50
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x7052(%rip), %xmm3     # 0x17d60
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq (%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq %r15, %rdi
callq 0x22a0
movq %rax, %r15
leaq 0x7079(%rip), %rsi      # 0x17dc6
movl $0x8, %edx
movq %rax, %rdi
callq 0x2200
movq (%rsp), %rsi
movq %r15, %rdi
callq 0x2110
movq %rax, %r15
leaq 0x742f(%rip), %rsi      # 0x1819f
movl $0x7, %edx
movq %rax, %rdi
callq 0x2200
movsd (%rsp), %xmm1
unpcklps 0x6fc7(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x6fcf(%rip), %xmm1     # 0x17d60
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x6f8b(%rip), %xmm0     # 0x17d30
movl 0x18(%r14), %eax
movl 0x1c(%r14), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movq %r15, %rdi
callq 0x22a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0xc43a(%rip), %rdx      # 0x1d238
testq %rdx, %rdx
je 0x10f34
leaq 0x48(%rsp), %rdi
movq %r13, (%rdi)
movq 0xc41a(%rip), %rsi      # 0x1d230
addq %rsi, %rdx
callq 0x12dec
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpb $0x2f, -0x1(%rax,%rcx)
je 0x10e40
leaq 0x6f99(%rip), %rsi      # 0x17dcf
leaq 0x48(%rsp), %rdi
callq 0x2320
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdx
leaq 0x48(%rsp), %rdi
callq 0x2070
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x2555
testl %eax, %eax
je 0x10ec4
movq 0xc168(%rip), %rdi      # 0x1cfd8
leaq 0x6f5a(%rip), %rsi      # 0x17dd1
movl $0x18, %edx
callq 0x2200
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xc146(%rip), %rdi      # 0x1cfd8
callq 0x2200
movq %rax, %r14
leaq 0x6f49(%rip), %rsi      # 0x17dea
movl $0x1d, %edx
movq %rax, %rdi
callq 0x2200
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
jmp 0x10f12
cmpb $0x1, 0xc35d(%rip)      # 0x1d228
jne 0x10f25
movq 0xc104(%rip), %rdi      # 0x1cfd8
leaq 0x6f2d(%rip), %rsi      # 0x17e08
movl $0xa, %edx
callq 0x2200
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xc0e2(%rip), %rdi      # 0x1cfd8
callq 0x2200
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x10f34
callq 0x2180
leaq 0x48(%rsp), %rdi
callq 0xd258
movq 0x8(%rsp), %rcx
movq (%rsp), %r8
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x80a5
movl 0x20(%rsp), %edi
movl 0x10(%rsp), %esi
leaq 0x128(%rsp), %rdx
callq 0x597f
addq %rax, 0xc2a9(%rip)      # 0x1d220
leaq 0x48(%rsp), %rdi
callq 0xd280
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rcx
movq %rbx, %rdi
callq 0x12b06
movq 0x8(%rsp), %rdi
callq 0x2220
leaq 0x2c8(%rsp), %rdi
callq 0xd280
movq %rbx, %rax
addq $0x548, %rsp            # imm = 0x548
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x10ffe
callq 0x2180
jmp 0x10ffe
jmp 0x10ffb
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
jmp 0x10ffb
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
jmp 0x1100f
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xd280
jmp 0x11012
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x11012
callq 0x2180
jmp 0x11012
movq %rax, %rbx
leaq 0x2c8(%rsp), %rdi
callq 0xd280
movq %rbx, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x12a7b