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

  std::vector<unsigned char> encoded;

  unsigned error_enc = lodepng::encode(encoded, image.data, image.width, image.height,
                                   image.colorType, image.bitDepth);
  ASSERT_NO_PNG_ERROR_MSG(error_enc, "encoder error not expected");


  std::vector<unsigned char> decoded;
  unsigned w, h;
  int customcontext = 5;

  struct TestFun {
    static unsigned custom_zlib(unsigned char**, size_t*,
                          const unsigned char*, size_t,
                          const LodePNGDecompressSettings* 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.decoder.zlibsettings.custom_zlib = TestFun::custom_zlib;
  state.decoder.zlibsettings.custom_context = &customcontext;
  state.decoder.zlibsettings.ignore_adler32 = 0;
  state.decoder.ignore_crc = 0;
  custom_proof = 0;
  unsigned error = lodepng::decode(decoded, w, h, state, encoded);
  ASSERT_EQUALS(1, custom_proof); // check that the custom zlib was called

  ASSERT_EQUALS(110, error);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x670, %rsp            # imm = 0x670
movq 0xa7a56(%rip), %rdi     # 0xf7fd8
leaq 0x63ff2(%rip), %rsi     # 0xb457b
callq 0x3230
movq %rax, %rdi
movq 0xa7a28(%rip), %rsi     # 0xf7fc0
callq 0x3280
leaq -0x28(%rbp), %rdi
movq %rdi, -0x5c8(%rbp)
callq 0xaaae0
movq -0x5c8(%rbp), %rdi
movl $0x5, %edx
movl $0x6, %ecx
movl $0x8, %r8d
movl %edx, %esi
callq 0x29a40
jmp 0x505cd
leaq -0x50(%rbp), %rdi
callq 0x1a4a0
jmp 0x505d8
movl -0x10(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x8(%rbp), %r8d
movl -0x4(%rbp), %r9d
leaq -0x50(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x12040
movl %eax, -0x5cc(%rbp)
jmp 0x505fb
movl -0x5cc(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x5dc(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x5d8(%rbp)
callq 0x3440
movq -0x5d8(%rbp), %rdx
leaq 0x62ae7(%rip), %rsi     # 0xb3115
leaq -0xb8(%rbp), %rdi
callq 0x3340
jmp 0x5063c
leaq 0x63f51(%rip), %rdx     # 0xb4594
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xaa1b0
jmp 0x50658
leaq -0x101(%rbp), %rdi
movq %rdi, -0x5e8(%rbp)
callq 0x3440
movq -0x5e8(%rbp), %rdx
movb $0x0, -0x103(%rbp)
movb $0x0, -0x12a(%rbp)
movb $0x0, -0x12b(%rbp)
leaq 0x63f0b(%rip), %rsi     # 0xb4599
leaq -0x100(%rbp), %rdi
callq 0x3340
jmp 0x5069c
leaq -0x100(%rbp), %rdi
callq 0x33f0
movb %al, -0x5e9(%rbp)
jmp 0x506b0
movb -0x5e9(%rbp), %al
testb $0x1, %al
jne 0x506bc
jmp 0x506f4
leaq -0x102(%rbp), %rdi
movq %rdi, -0x5f8(%rbp)
callq 0x3440
movq -0x5f8(%rbp), %rdx
movb $0x1, -0x103(%rbp)
leaq 0x63e20(%rip), %rsi     # 0xb4504
leaq -0xe0(%rbp), %rdi
callq 0x3340
jmp 0x506f2
jmp 0x5074f
leaq -0x129(%rbp), %rdi
movq %rdi, -0x600(%rbp)
callq 0x3440
movq -0x600(%rbp), %rdx
movb $0x1, -0x12a(%rbp)
leaq 0x63e7d(%rip), %rsi     # 0xb4599
leaq -0x128(%rbp), %rdi
callq 0x3340
jmp 0x5072a
movb $0x1, -0x12b(%rbp)
leaq 0x65fab(%rip), %rsi     # 0xb66e3
leaq -0xe0(%rbp), %rdi
leaq -0x128(%rbp), %rdx
callq 0xaa6d0
jmp 0x5074d
jmp 0x5074f
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0xaa240
jmp 0x50768
movl -0x5dc(%rbp), %edi
leaq -0x78(%rbp), %rsi
callq 0x28d30
jmp 0x50779
leaq -0x78(%rbp), %rdi
callq 0x34a8
jmp 0x50784
leaq -0xe0(%rbp), %rdi
callq 0x34a8
jmp 0x50792
testb $0x1, -0x12b(%rbp)
jne 0x5079d
jmp 0x507ad
leaq -0x128(%rbp), %rdi
callq 0x34a8
jmp 0x507ab
jmp 0x507ad
testb $0x1, -0x12a(%rbp)
jne 0x507b8
jmp 0x507c4
leaq -0x129(%rbp), %rdi
callq 0x3290
testb $0x1, -0x103(%rbp)
jne 0x507cf
jmp 0x507db
leaq -0x102(%rbp), %rdi
callq 0x3290
leaq -0x100(%rbp), %rdi
callq 0x34a8
jmp 0x507e9
leaq -0x101(%rbp), %rdi
callq 0x3290
leaq -0x98(%rbp), %rdi
callq 0x34a8
jmp 0x50803
leaq -0xb8(%rbp), %rdi
callq 0x34a8
jmp 0x50811
leaq -0xb9(%rbp), %rdi
callq 0x3290
leaq -0x148(%rbp), %rdi
callq 0x1a4a0
jmp 0x5082b
movl $0x5, -0x154(%rbp)
leaq -0x3d8(%rbp), %rdi
callq 0x11ad0
jmp 0x50843
leaq 0x886(%rip), %rax       # 0x510d0
movq %rax, -0x3c8(%rbp)
leaq -0x154(%rbp), %rax
movq %rax, -0x3b8(%rbp)
movl $0x0, -0x3d8(%rbp)
movl $0x0, -0x3b0(%rbp)
movl $0x0, 0xa7a33(%rip)     # 0xf82b0
leaq -0x148(%rbp), %rdi
leaq -0x14c(%rbp), %rsi
leaq -0x150(%rbp), %rdx
leaq -0x3d8(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0x11e30
movl %eax, -0x604(%rbp)
jmp 0x508aa
movl -0x604(%rbp), %eax
movl %eax, -0x3dc(%rbp)
movl $0x1, %eax
cmpl 0xa79ef(%rip), %eax     # 0xf82b0
je 0x50d45
leaq -0x481(%rbp), %rdi
movq %rdi, -0x610(%rbp)
callq 0x3440
movq -0x610(%rbp), %rdx
leaq 0x6282d(%rip), %rsi     # 0xb3115
leaq -0x480(%rbp), %rdi
callq 0x3340
jmp 0x508f6
leaq 0x63cb7(%rip), %rdx     # 0xb45b4
leaq -0x460(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0xaa1b0
jmp 0x50912
leaq 0x65dca(%rip), %rdx     # 0xb66e3
leaq -0x440(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0xaa1b0
jmp 0x5092e
leaq 0x63bec(%rip), %rdx     # 0xb4521
leaq -0x420(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0xaa1b0
jmp 0x5094a
leaq 0x6280c(%rip), %rdx     # 0xb315d
leaq -0x400(%rbp), %rdi
leaq -0x420(%rbp), %rsi
callq 0xaa1b0
jmp 0x50966
movq 0xa766b(%rip), %rdi     # 0xf7fd8
leaq -0x400(%rbp), %rsi
callq 0x3200
jmp 0x5097b
leaq -0x400(%rbp), %rdi
callq 0x34a8
jmp 0x50989
leaq -0x420(%rbp), %rdi
callq 0x34a8
jmp 0x50997
leaq -0x440(%rbp), %rdi
callq 0x34a8
jmp 0x509a5
leaq -0x460(%rbp), %rdi
callq 0x34a8
jmp 0x509b3
leaq -0x480(%rbp), %rdi
callq 0x34a8
jmp 0x509c1
leaq -0x481(%rbp), %rdi
callq 0x3290
movq 0xa7604(%rip), %rdi     # 0xf7fd8
leaq 0x8b470(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x618(%rbp)
jmp 0x509e9
movl $0x1, -0x4ac(%rbp)
leaq -0x4a8(%rbp), %rdi
leaq -0x4ac(%rbp), %rsi
callq 0xaaa20
jmp 0x50a08
movq -0x618(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x3200
movq %rax, -0x620(%rbp)
jmp 0x50a24
movq -0x620(%rbp), %rdi
leaq 0x62743(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x628(%rbp)
jmp 0x50a40
leaq 0xa7869(%rip), %rsi     # 0xf82b0
leaq -0x4d0(%rbp), %rdi
callq 0xaaa20
jmp 0x50a55
movq -0x628(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x3200
movq %rax, -0x630(%rbp)
jmp 0x50a71
movq -0x630(%rbp), %rdi
leaq 0x625dd(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x638(%rbp)
jmp 0x50a8d
movq -0x638(%rbp), %rdi
movq 0xa7525(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x50aa2
leaq -0x4d0(%rbp), %rdi
callq 0x34a8
jmp 0x50ab0
leaq -0x4a8(%rbp), %rdi
callq 0x34a8
jmp 0x50abe
callq 0x28bd0
jmp 0x50ac5
jmp 0x50d45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x510ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5109f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50c1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50c0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50bf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50be3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50bca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50bb1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50b94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50b84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x34a8
jmp 0x50b82
jmp 0x50b84
leaq -0xe0(%rbp), %rdi
callq 0x34a8
jmp 0x50b92
jmp 0x50b94
testb $0x1, -0x12b(%rbp)
jne 0x50b9f
jmp 0x50baf
leaq -0x128(%rbp), %rdi
callq 0x34a8
jmp 0x50bad
jmp 0x50baf
jmp 0x50bb1
testb $0x1, -0x12a(%rbp)
jne 0x50bbc
jmp 0x50bc8
leaq -0x129(%rbp), %rdi
callq 0x3290
jmp 0x50bca
testb $0x1, -0x103(%rbp)
jne 0x50bd5
jmp 0x50be1
leaq -0x102(%rbp), %rdi
callq 0x3290
jmp 0x50be3
leaq -0x100(%rbp), %rdi
callq 0x34a8
jmp 0x50bf1
jmp 0x50bf3
leaq -0x101(%rbp), %rdi
callq 0x3290
leaq -0x98(%rbp), %rdi
callq 0x34a8
jmp 0x50c0d
jmp 0x50c0f
leaq -0xb8(%rbp), %rdi
callq 0x34a8
jmp 0x50c1d
jmp 0x50c1f
leaq -0xb9(%rbp), %rdi
callq 0x3290
jmp 0x5109f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5108f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5107f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50ce7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50cd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50cc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50cb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x34a8
jmp 0x50cb5
jmp 0x50cb7
leaq -0x420(%rbp), %rdi
callq 0x34a8
jmp 0x50cc5
jmp 0x50cc7
leaq -0x440(%rbp), %rdi
callq 0x34a8
jmp 0x50cd5
jmp 0x50cd7
leaq -0x460(%rbp), %rdi
callq 0x34a8
jmp 0x50ce5
jmp 0x50ce7
leaq -0x480(%rbp), %rdi
callq 0x34a8
jmp 0x50cf5
jmp 0x50cf7
leaq -0x481(%rbp), %rdi
callq 0x3290
jmp 0x5107f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50d32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x4d0(%rbp), %rdi
callq 0x34a8
jmp 0x50d30
jmp 0x50d32
leaq -0x4a8(%rbp), %rdi
callq 0x34a8
jmp 0x50d40
jmp 0x5107f
movl $0x6e, %eax
cmpl -0x3dc(%rbp), %eax
je 0x51046
leaq -0x571(%rbp), %rdi
movq %rdi, -0x640(%rbp)
callq 0x3440
movq -0x640(%rbp), %rdx
leaq 0x6239e(%rip), %rsi     # 0xb3115
leaq -0x570(%rbp), %rdi
callq 0x3340
jmp 0x50d85
leaq 0x6382d(%rip), %rdx     # 0xb45b9
leaq -0x550(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0xaa1b0
jmp 0x50da1
leaq 0x6593b(%rip), %rdx     # 0xb66e3
leaq -0x530(%rbp), %rdi
leaq -0x550(%rbp), %rsi
callq 0xaa1b0
jmp 0x50dbd
leaq 0x622b1(%rip), %rdx     # 0xb3075
leaq -0x510(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0xaa1b0
jmp 0x50dd9
leaq 0x6237d(%rip), %rdx     # 0xb315d
leaq -0x4f0(%rbp), %rdi
leaq -0x510(%rbp), %rsi
callq 0xaa1b0
jmp 0x50df5
movq 0xa71dc(%rip), %rdi     # 0xf7fd8
leaq -0x4f0(%rbp), %rsi
callq 0x3200
jmp 0x50e0a
leaq -0x4f0(%rbp), %rdi
callq 0x34a8
jmp 0x50e18
leaq -0x510(%rbp), %rdi
callq 0x34a8
jmp 0x50e26
leaq -0x530(%rbp), %rdi
callq 0x34a8
jmp 0x50e34
leaq -0x550(%rbp), %rdi
callq 0x34a8
jmp 0x50e42
leaq -0x570(%rbp), %rdi
callq 0x34a8
jmp 0x50e50
leaq -0x571(%rbp), %rdi
callq 0x3290
movq 0xa7175(%rip), %rdi     # 0xf7fd8
leaq 0x8afe1(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x648(%rbp)
jmp 0x50e78
movl $0x6e, -0x59c(%rbp)
leaq -0x598(%rbp), %rdi
leaq -0x59c(%rbp), %rsi
callq 0xaaa20
jmp 0x50e97
movq -0x648(%rbp), %rdi
leaq -0x598(%rbp), %rsi
callq 0x3200
movq %rax, -0x650(%rbp)
jmp 0x50eb3
movq -0x650(%rbp), %rdi
leaq 0x622b4(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x658(%rbp)
jmp 0x50ecf
leaq -0x5c0(%rbp), %rdi
leaq -0x3dc(%rbp), %rsi
callq 0xaa7f0
jmp 0x50ee4
movq -0x658(%rbp), %rdi
leaq -0x5c0(%rbp), %rsi
callq 0x3200
movq %rax, -0x660(%rbp)
jmp 0x50f00
movq -0x660(%rbp), %rdi
leaq 0x6214e(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x668(%rbp)
jmp 0x50f1c
movq -0x668(%rbp), %rdi
movq 0xa7096(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x50f31
leaq -0x5c0(%rbp), %rdi
callq 0x34a8
jmp 0x50f3f
leaq -0x598(%rbp), %rdi
callq 0x34a8
jmp 0x50f4d
callq 0x28bd0
jmp 0x50f54
jmp 0x51046
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50ffe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50fee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50fde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50fce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50fbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x4f0(%rbp), %rdi
callq 0x34a8
jmp 0x50fbc
jmp 0x50fbe
leaq -0x510(%rbp), %rdi
callq 0x34a8
jmp 0x50fcc
jmp 0x50fce
leaq -0x530(%rbp), %rdi
callq 0x34a8
jmp 0x50fdc
jmp 0x50fde
leaq -0x550(%rbp), %rdi
callq 0x34a8
jmp 0x50fec
jmp 0x50fee
leaq -0x570(%rbp), %rdi
callq 0x34a8
jmp 0x50ffc
jmp 0x50ffe
leaq -0x571(%rbp), %rdi
callq 0x3290
jmp 0x5107f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51036
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x5c0(%rbp), %rdi
callq 0x34a8
jmp 0x51034
jmp 0x51036
leaq -0x598(%rbp), %rdi
callq 0x34a8
jmp 0x51044
jmp 0x5107f
leaq -0x3d8(%rbp), %rdi
callq 0x11b20
jmp 0x51054
leaq -0x148(%rbp), %rdi
callq 0x1a4c0
jmp 0x51062
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x5106d
leaq -0x28(%rbp), %rdi
callq 0xaab00
addq $0x670, %rsp            # imm = 0x670
popq %rbp
retq
leaq -0x3d8(%rbp), %rdi
callq 0x11b20
jmp 0x5108d
jmp 0x5108f
leaq -0x148(%rbp), %rdi
callq 0x1a4c0
jmp 0x5109d
jmp 0x5109f
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x510aa
jmp 0x510ac
leaq -0x28(%rbp), %rdi
callq 0xaab00
jmp 0x510b7
jmp 0x510b9
movq -0x30(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nopw (%rax,%rax)