// File: lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: testCustomZlibCompress()
void testCustomZlibCompress() {
  std::cout << "testCustomZlibCompress" << std::endl;
  Image image;
  generateTestImage(image, 5, 5, LCT_RGBA, 8);

  std::vector<unsigned char> encoded;
  int customcontext = 5;

  struct TestFun {
    static unsigned custom_zlib(unsigned char**, size_t*,
                          const unsigned char*, size_t,
                          const LodePNGCompressSettings* settings) {
      ASSERT_EQUALS(5, *(int*)(settings->custom_context));
      custom_proof = 1;
      return 5555; // return a custom error code, which will be converted to an error known to lodepng.
    }
  };

  lodepng::State state;
  state.encoder.zlibsettings.custom_zlib = TestFun::custom_zlib;
  state.encoder.zlibsettings.custom_context = &customcontext;

  custom_proof = 0;
  unsigned error = lodepng::encode(encoded, image.data, image.width, image.height, state);
  ASSERT_EQUALS(1, custom_proof); // check that the custom zlib was called

  ASSERT_EQUALS(111, error); // expect a known lodepng error, not the custom 5555
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movq 0xa9ed6(%rip), %rdi     # 0xf7fd8
leaq 0x663fc(%rip), %rsi     # 0xb4505
callq 0x3230
movq %rax, %rdi
movq 0xa9ea8(%rip), %rsi     # 0xf7fc0
callq 0x3280
leaq -0x28(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
callq 0xaaae0
movq -0x4c8(%rbp), %rdi
movl $0x5, %edx
movl $0x6, %ecx
movl $0x8, %r8d
movl %edx, %esi
callq 0x29a40
jmp 0x4e14d
leaq -0x50(%rbp), %rdi
callq 0x1a4a0
jmp 0x4e158
movl $0x5, -0x54(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x11ad0
jmp 0x4e16d
leaq 0x6ec(%rip), %rax       # 0x4e860
movq %rax, -0x270(%rbp)
leaq -0x54(%rbp), %rax
movq %rax, -0x260(%rbp)
movl $0x0, 0xaa120(%rip)     # 0xf82b0
movl -0x10(%rbp), %edx
movl -0xc(%rbp), %ecx
leaq -0x50(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x2d8(%rbp), %r8
callq 0x12170
movl %eax, -0x4cc(%rbp)
jmp 0x4e1b2
movl -0x4cc(%rbp), %eax
movl %eax, -0x2dc(%rbp)
movl $0x1, %eax
cmpl 0xaa0e7(%rip), %eax     # 0xf82b0
je 0x4e4f8
leaq -0x381(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x3440
movq -0x4d8(%rbp), %rdx
leaq 0x64f25(%rip), %rsi     # 0xb3115
leaq -0x380(%rbp), %rdi
callq 0x3340
jmp 0x4e1fe
leaq 0x66317(%rip), %rdx     # 0xb451c
leaq -0x360(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e21a
leaq 0x684c2(%rip), %rdx     # 0xb66e3
leaq -0x340(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e236
leaq 0x662e4(%rip), %rdx     # 0xb4521
leaq -0x320(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e252
leaq 0x64f04(%rip), %rdx     # 0xb315d
leaq -0x300(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e26e
movq 0xa9d63(%rip), %rdi     # 0xf7fd8
leaq -0x300(%rbp), %rsi
callq 0x3200
jmp 0x4e283
leaq -0x300(%rbp), %rdi
callq 0x34a8
jmp 0x4e291
leaq -0x320(%rbp), %rdi
callq 0x34a8
jmp 0x4e29f
leaq -0x340(%rbp), %rdi
callq 0x34a8
jmp 0x4e2ad
leaq -0x360(%rbp), %rdi
callq 0x34a8
jmp 0x4e2bb
leaq -0x380(%rbp), %rdi
callq 0x34a8
jmp 0x4e2c9
leaq -0x381(%rbp), %rdi
callq 0x3290
movq 0xa9cfc(%rip), %rdi     # 0xf7fd8
leaq 0x8db68(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x4e0(%rbp)
jmp 0x4e2f1
movl $0x1, -0x3ac(%rbp)
leaq -0x3a8(%rbp), %rdi
leaq -0x3ac(%rbp), %rsi
callq 0xaaa20
jmp 0x4e310
movq -0x4e0(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
callq 0x3200
movq %rax, -0x4e8(%rbp)
jmp 0x4e32c
movq -0x4e8(%rbp), %rdi
leaq 0x64e3b(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x4f0(%rbp)
jmp 0x4e348
leaq 0xa9f61(%rip), %rsi     # 0xf82b0
leaq -0x3d0(%rbp), %rdi
callq 0xaaa20
jmp 0x4e35d
movq -0x4f0(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x3200
movq %rax, -0x4f8(%rbp)
jmp 0x4e379
movq -0x4f8(%rbp), %rdi
leaq 0x64cd5(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x500(%rbp)
jmp 0x4e395
movq -0x500(%rbp), %rdi
movq 0xa9c1d(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x4e3aa
leaq -0x3d0(%rbp), %rdi
callq 0x34a8
jmp 0x4e3b8
leaq -0x3a8(%rbp), %rdi
callq 0x34a8
jmp 0x4e3c6
callq 0x28bd0
jmp 0x4e3cd
jmp 0x4e4f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e841
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e834
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e824
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e4aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e49a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e48a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e47a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e46a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x34a8
jmp 0x4e468
jmp 0x4e46a
leaq -0x320(%rbp), %rdi
callq 0x34a8
jmp 0x4e478
jmp 0x4e47a
leaq -0x340(%rbp), %rdi
callq 0x34a8
jmp 0x4e488
jmp 0x4e48a
leaq -0x360(%rbp), %rdi
callq 0x34a8
jmp 0x4e498
jmp 0x4e49a
leaq -0x380(%rbp), %rdi
callq 0x34a8
jmp 0x4e4a8
jmp 0x4e4aa
leaq -0x381(%rbp), %rdi
callq 0x3290
jmp 0x4e824
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e4e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x3d0(%rbp), %rdi
callq 0x34a8
jmp 0x4e4e3
jmp 0x4e4e5
leaq -0x3a8(%rbp), %rdi
callq 0x34a8
jmp 0x4e4f3
jmp 0x4e824
movl $0x6f, %eax
cmpl -0x2dc(%rbp), %eax
je 0x4e7f9
leaq -0x471(%rbp), %rdi
movq %rdi, -0x508(%rbp)
callq 0x3440
movq -0x508(%rbp), %rdx
leaq 0x64beb(%rip), %rsi     # 0xb3115
leaq -0x470(%rbp), %rdi
callq 0x3340
jmp 0x4e538
leaq 0x65fef(%rip), %rdx     # 0xb452e
leaq -0x450(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e554
leaq 0x68188(%rip), %rdx     # 0xb66e3
leaq -0x430(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e570
leaq 0x64afe(%rip), %rdx     # 0xb3075
leaq -0x410(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e58c
leaq 0x64bca(%rip), %rdx     # 0xb315d
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0xaa1b0
jmp 0x4e5a8
movq 0xa9a29(%rip), %rdi     # 0xf7fd8
leaq -0x3f0(%rbp), %rsi
callq 0x3200
jmp 0x4e5bd
leaq -0x3f0(%rbp), %rdi
callq 0x34a8
jmp 0x4e5cb
leaq -0x410(%rbp), %rdi
callq 0x34a8
jmp 0x4e5d9
leaq -0x430(%rbp), %rdi
callq 0x34a8
jmp 0x4e5e7
leaq -0x450(%rbp), %rdi
callq 0x34a8
jmp 0x4e5f5
leaq -0x470(%rbp), %rdi
callq 0x34a8
jmp 0x4e603
leaq -0x471(%rbp), %rdi
callq 0x3290
movq 0xa99c2(%rip), %rdi     # 0xf7fd8
leaq 0x8d82e(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x510(%rbp)
jmp 0x4e62b
movl $0x6f, -0x49c(%rbp)
leaq -0x498(%rbp), %rdi
leaq -0x49c(%rbp), %rsi
callq 0xaaa20
jmp 0x4e64a
movq -0x510(%rbp), %rdi
leaq -0x498(%rbp), %rsi
callq 0x3200
movq %rax, -0x518(%rbp)
jmp 0x4e666
movq -0x518(%rbp), %rdi
leaq 0x64b01(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x520(%rbp)
jmp 0x4e682
leaq -0x4c0(%rbp), %rdi
leaq -0x2dc(%rbp), %rsi
callq 0xaa7f0
jmp 0x4e697
movq -0x520(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
callq 0x3200
movq %rax, -0x528(%rbp)
jmp 0x4e6b3
movq -0x528(%rbp), %rdi
leaq 0x6499b(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x530(%rbp)
jmp 0x4e6cf
movq -0x530(%rbp), %rdi
movq 0xa98e3(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x4e6e4
leaq -0x4c0(%rbp), %rdi
callq 0x34a8
jmp 0x4e6f2
leaq -0x498(%rbp), %rdi
callq 0x34a8
jmp 0x4e700
callq 0x28bd0
jmp 0x4e707
jmp 0x4e7f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e7b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e7a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e791
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e781
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e771
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x34a8
jmp 0x4e76f
jmp 0x4e771
leaq -0x410(%rbp), %rdi
callq 0x34a8
jmp 0x4e77f
jmp 0x4e781
leaq -0x430(%rbp), %rdi
callq 0x34a8
jmp 0x4e78f
jmp 0x4e791
leaq -0x450(%rbp), %rdi
callq 0x34a8
jmp 0x4e79f
jmp 0x4e7a1
leaq -0x470(%rbp), %rdi
callq 0x34a8
jmp 0x4e7af
jmp 0x4e7b1
leaq -0x471(%rbp), %rdi
callq 0x3290
jmp 0x4e824
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4e7e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x4c0(%rbp), %rdi
callq 0x34a8
jmp 0x4e7e7
jmp 0x4e7e9
leaq -0x498(%rbp), %rdi
callq 0x34a8
jmp 0x4e7f7
jmp 0x4e824
leaq -0x2d8(%rbp), %rdi
callq 0x11b20
jmp 0x4e807
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e812
leaq -0x28(%rbp), %rdi
callq 0xaab00
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
leaq -0x2d8(%rbp), %rdi
callq 0x11b20
jmp 0x4e832
jmp 0x4e834
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e83f
jmp 0x4e841
leaq -0x28(%rbp), %rdi
callq 0xaab00
jmp 0x4e84c
jmp 0x4e84e
movq -0x30(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nop