// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x560, %rsp            # imm = 0x560
movq %rsi, %r14
andq $0x0, 0x18(%rsp)
movq %rdi, %rbx
andq $0x0, 0x8(%rsp)
leaq 0x2e0(%rsp), %r15
movq %r15, %rdi
callq 0xb74c
movq 0x20(%r14), %rax
movq %rax, 0xa8(%r15)
cmpb $0x1, 0xb75a(%rip)      # 0x1a191
jne 0xea44
movl $0x1, 0x338(%rsp)
callq 0xe98c
movsd %xmm0, 0x38(%rsp)
movq (%r14), %rdx
movl 0x18(%r14), %ecx
movl 0x1c(%r14), %r8d
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x2e0(%rsp), %r9
callq 0x91bd
movl %eax, 0x34(%rsp)
callq 0xe98c
movsd %xmm0, 0x28(%rsp)
andl $0x0, 0x40(%rsp)
leaq 0x6204(%rip), %rsi      # 0x14c90
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x2070
leaq 0x40(%rsp), %rdi
leaq 0x34(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x101bc
leaq 0x60(%rsp), %rdi
callq 0x21c0
leaq 0x388(%rsp), %rdx
movl 0x18(%r14), %edi
movl 0x1c(%r14), %esi
callq 0x4a9a
addq %rax, 0xb703(%rip)      # 0x1a1d8
movq 0x8(%rsp), %rax
addq %rax, 0xb6ff(%rip)      # 0x1a1e0
movsd 0x28(%rsp), %xmm1
subsd 0x38(%rsp), %xmm1
movsd 0xb6db(%rip), %xmm0     # 0x1a1d0
movsd %xmm1, 0x28(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0xb6c9(%rip)     # 0x1a1d0
cmpb $0x1, 0xb6e2(%rip)      # 0x1a1f0
jne 0xecd6
leaq 0x6183(%rip), %rsi      # 0x14c9e
leaq 0x60(%rsp), %rdi
leaq 0x17(%rsp), %rdx
callq 0x2070
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x61f3(%rip), %rsi      # 0x14d30
leaq 0x40(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x2070
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x10251
leaq 0x40(%rsp), %rdi
callq 0x21c0
leaq 0x60(%rsp), %rdi
callq 0x21c0
movq 0xb45d(%rip), %rdi      # 0x19fd8
leaq 0x612a(%rip), %rsi      # 0x14cac
callq 0x2130
movsd 0x8(%rsp), %xmm1
movsd 0x60bb(%rip), %xmm2     # 0x14c50
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x60c0(%rip), %xmm3     # 0x14c60
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq 0x8(%r14), %rcx
subq (%r14), %rcx
movq %rcx, %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 0x604c(%rip), %xmm0     # 0x14c28
movq %rax, %rdi
callq 0x2230
leaq 0x60cf(%rip), %rsi      # 0x14cba
movq %rax, %rdi
callq 0x2130
leaq 0x60c2(%rip), %rsi      # 0x14cbc
movq %rax, %rdi
callq 0x2130
movq 0x8(%r14), %rcx
subq (%r14), %rcx
movq %rcx, %xmm1
movq 0x603a(%rip), %xmm2     # 0x14c50
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x603e(%rip), %xmm3     # 0x14c60
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq 0x8(%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 %rax, %rdi
callq 0x2230
leaq 0x6067(%rip), %rsi      # 0x14cc6
movq %rax, %rdi
callq 0x2130
movq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
leaq 0x6424(%rip), %rsi      # 0x1509f
movq %rax, %rdi
callq 0x2130
movsd 0x8(%rsp), %xmm1
unpcklps 0x5fc0(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x5fc8(%rip), %xmm1     # 0x14c60
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x5f84(%rip), %xmm0     # 0x14c30
movl 0x18(%r14), %ecx
movl 0x1c(%r14), %edx
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
cvtsi2sd %rdx, %xmm1
divsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2090
cmpq $0x0, 0xb522(%rip)      # 0x1a200
je 0xedac
leaq 0xb50d(%rip), %rsi      # 0x1a1f8
leaq 0x60(%rsp), %rdi
callq 0x21f0
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
cmpb $0x2f, -0x1(%rax,%rcx)
je 0xed17
leaq 0x5fc2(%rip), %rsi      # 0x14ccf
leaq 0x60(%rsp), %rdi
callq 0x2290
addq $0x28, %r14
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x22c0
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x24cc
testl %eax, %eax
je 0xed71
movq 0xb291(%rip), %rdi      # 0x19fd8
leaq 0x5f83(%rip), %rsi      # 0x14cd1
callq 0x2130
leaq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x2110
leaq 0x5f83(%rip), %rsi      # 0x14cea
movq %rax, %rdi
callq 0x2130
jmp 0xed9a
cmpb $0x1, 0xb478(%rip)      # 0x1a1f0
jne 0xeda2
movq 0xb257(%rip), %rdi      # 0x19fd8
leaq 0x5f80(%rip), %rsi      # 0x14d08
callq 0x2130
leaq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x2090
leaq 0x60(%rsp), %rdi
callq 0x21c0
leaq 0x60(%rsp), %rdi
callq 0xb74c
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r8
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x6e45
movl 0x40(%rsp), %edi
movl 0x20(%rsp), %esi
leaq 0x140(%rsp), %rdx
callq 0x4a9a
addq %rax, 0xb3f8(%rip)      # 0x1a1e8
leaq 0x60(%rsp), %rdi
callq 0xb774
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rcx
movq %rbx, %rdi
callq 0x102a0
movq 0x18(%rsp), %rdi
callq 0x21a0
leaq 0x2e0(%rsp), %rdi
callq 0xb774
movq %rbx, %rax
addq $0x560, %rsp            # imm = 0x560
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x21c0
jmp 0xee51
jmp 0xee94
jmp 0xee94
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x21c0
jmp 0xee97
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x21c0
jmp 0xee97
jmp 0xee94
jmp 0xee94
jmp 0xee94
jmp 0xee94
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xb774
jmp 0xee97
jmp 0xee94
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x21c0
jmp 0xee97
movq %rax, %rbx
leaq 0x2e0(%rsp), %rdi
callq 0xb774
movq %rbx, %rdi
callq 0x2280
movq %rax, %rdi
callq 0xe5cc