// File: /workspace/github_cpp_makefile_star2_O1/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 0xd030
movl 0x20(%r14), %eax
movl %eax, 0xa8(%r15)
movl 0x24(%r14), %eax
movl %eax, 0xac(%r15)
cmpb $0x1, 0xc35d(%rip)      # 0x1d1c1
jne 0x10e71
movl $0x1, 0x320(%rsp)
callq 0x21c0
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 0xa652
movl %eax, 0x1c(%rsp)
callq 0x21c0
movl %eax, %r15d
movl $0x0, 0x20(%rsp)
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x6db4(%rip), %rsi      # 0x17c70
leaq 0x6dba(%rip), %rdx      # 0x17c7d
leaq 0x48(%rsp), %rdi
callq 0x130da
leaq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x12d7e
leaq 0x370(%rsp), %r12
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x10ef8
callq 0x2170
movl 0x18(%r14), %edi
movl 0x1c(%r14), %esi
movq %r12, %rdx
callq 0x53a7
movl %ebp, %ecx
movl %r15d, %edx
cvtsi2sd %rcx, %xmm0
cvtsi2sd %rdx, %xmm1
divsd 0x6ce1(%rip), %xmm0     # 0x17c00
divsd 0x6cd9(%rip), %xmm1     # 0x17c00
subsd %xmm0, %xmm1
addq %rax, 0xc2d6(%rip)      # 0x1d208
movq (%rsp), %rax
addq %rax, 0xc2d3(%rip)      # 0x1d210
movsd 0xc2bb(%rip), %xmm0     # 0x1d200
addsd %xmm1, %xmm0
movsd %xmm0, 0xc2af(%rip)     # 0x1d200
cmpb $0x1, 0xc2c8(%rip)      # 0x1d220
jne 0x1118a
movsd %xmm1, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x6d0b(%rip), %rsi      # 0x17c7e
leaq 0x6d11(%rip), %rdx      # 0x17c8b
callq 0x130da
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x6d75(%rip), %rsi      # 0x17d10
leaq 0x6d6f(%rip), %rdx      # 0x17d11
leaq 0x20(%rsp), %rdi
callq 0x130da
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x12e20
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x10fcf
callq 0x2170
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x10fde
callq 0x2170
movq 0xbff3(%rip), %rdi      # 0x1cfd8
leaq 0x6ca0(%rip), %rsi      # 0x17c8c
movl $0xd, %edx
callq 0x21f0
movsd (%rsp), %xmm1
movsd 0x6c2d(%rip), %xmm2     # 0x17c30
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x6c32(%rip), %xmm3     # 0x17c40
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 0x6bbe(%rip), %xmm0     # 0x17c08
movq 0xbf87(%rip), %rdi      # 0x1cfd8
callq 0x2290
movq %rax, %r15
leaq 0x6c3a(%rip), %rsi      # 0x17c9a
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x6c28(%rip), %rsi      # 0x17c9c
movl $0x9, %edx
movq %r15, %rdi
callq 0x21f0
movq 0x8(%r14), %rax
subq (%r14), %rax
movq %rax, %xmm1
movq 0x6b9b(%rip), %xmm2     # 0x17c30
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x6b9f(%rip), %xmm3     # 0x17c40
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 0x2290
movq %rax, %r15
leaq 0x6bc6(%rip), %rsi      # 0x17ca6
movl $0x8, %edx
movq %rax, %rdi
callq 0x21f0
movq (%rsp), %rsi
movq %r15, %rdi
callq 0x2100
movq %rax, %r15
leaq 0x6f7c(%rip), %rsi      # 0x1807f
movl $0x7, %edx
movq %rax, %rdi
callq 0x21f0
movsd (%rsp), %xmm1
unpcklps 0x6b14(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x6b1c(%rip), %xmm1     # 0x17c40
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x6ad8(%rip), %xmm0     # 0x17c10
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 0x2290
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0xc09f(%rip), %rdx      # 0x1d230
testq %rdx, %rdx
je 0x112c7
leaq 0x48(%rsp), %rdi
movq %r13, (%rdi)
movq 0xc07f(%rip), %rsi      # 0x1d228
addq %rsi, %rdx
callq 0x1316a
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpb $0x2f, -0x1(%rax,%rcx)
je 0x111d3
leaq 0x6ae6(%rip), %rsi      # 0x17caf
leaq 0x48(%rsp), %rdi
callq 0x2310
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 0x2545
testl %eax, %eax
je 0x11257
movq 0xbdd5(%rip), %rdi      # 0x1cfd8
leaq 0x6aa7(%rip), %rsi      # 0x17cb1
movl $0x18, %edx
callq 0x21f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xbdb3(%rip), %rdi      # 0x1cfd8
callq 0x21f0
movq %rax, %r14
leaq 0x6a96(%rip), %rsi      # 0x17cca
movl $0x1d, %edx
movq %rax, %rdi
callq 0x21f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
jmp 0x112a5
cmpb $0x1, 0xbfc2(%rip)      # 0x1d220
jne 0x112b8
movq 0xbd71(%rip), %rdi      # 0x1cfd8
leaq 0x6a7a(%rip), %rsi      # 0x17ce8
movl $0xa, %edx
callq 0x21f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xbd4f(%rip), %rdi      # 0x1cfd8
callq 0x21f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x112c7
callq 0x2170
leaq 0x48(%rsp), %rdi
callq 0xd030
movq 0x8(%rsp), %rcx
movq (%rsp), %r8
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x7af9
movl 0x20(%rsp), %edi
movl 0x10(%rsp), %esi
leaq 0x128(%rsp), %rdx
callq 0x53a7
addq %rax, 0xbf0e(%rip)      # 0x1d218
leaq 0x48(%rsp), %rdi
callq 0xd058
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rcx
movq %rbx, %rdi
callq 0x12ea0
movq 0x8(%rsp), %rdi
callq 0x2210
leaq 0x2c8(%rsp), %rdi
callq 0xd058
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 0x11391
callq 0x2170
jmp 0x11391
jmp 0x1138e
jmp 0x113a2
jmp 0x113a2
jmp 0x113a2
jmp 0x1138e
jmp 0x113a2
jmp 0x113a2
jmp 0x113a2
jmp 0x113a2
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xd058
jmp 0x113a5
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x113a5
callq 0x2170
jmp 0x113a5
movq %rax, %rbx
leaq 0x2c8(%rsp), %rdi
callq 0xd058
movq %rbx, %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x12e15