// File: lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: testCustomInflate()
void testCustomInflate() {
  std::cout << "testCustomInflate" << 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_inflate(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_inflate = TestFun::custom_inflate;
  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 0xa6b86(%rip), %rdi     # 0xf7fd8
leaq 0x63165(%rip), %rsi     # 0xb45be
callq 0x3230
movq %rax, %rdi
movq 0xa6b58(%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 0x5149d
leaq -0x50(%rbp), %rdi
callq 0x1a4a0
jmp 0x514a8
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 0x514cb
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 0x61c17(%rip), %rsi     # 0xb3115
leaq -0xb8(%rbp), %rdi
callq 0x3340
jmp 0x5150c
leaq 0x630bd(%rip), %rdx     # 0xb45d0
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xaa1b0
jmp 0x51528
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 0x6303b(%rip), %rsi     # 0xb4599
leaq -0x100(%rbp), %rdi
callq 0x3340
jmp 0x5156c
leaq -0x100(%rbp), %rdi
callq 0x33f0
movb %al, -0x5e9(%rbp)
jmp 0x51580
movb -0x5e9(%rbp), %al
testb $0x1, %al
jne 0x5158c
jmp 0x515c4
leaq -0x102(%rbp), %rdi
movq %rdi, -0x5f8(%rbp)
callq 0x3440
movq -0x5f8(%rbp), %rdx
movb $0x1, -0x103(%rbp)
leaq 0x62f50(%rip), %rsi     # 0xb4504
leaq -0xe0(%rbp), %rdi
callq 0x3340
jmp 0x515c2
jmp 0x5161f
leaq -0x129(%rbp), %rdi
movq %rdi, -0x600(%rbp)
callq 0x3440
movq -0x600(%rbp), %rdx
movb $0x1, -0x12a(%rbp)
leaq 0x62fad(%rip), %rsi     # 0xb4599
leaq -0x128(%rbp), %rdi
callq 0x3340
jmp 0x515fa
movb $0x1, -0x12b(%rbp)
leaq 0x650db(%rip), %rsi     # 0xb66e3
leaq -0xe0(%rbp), %rdi
leaq -0x128(%rbp), %rdx
callq 0xaa6d0
jmp 0x5161d
jmp 0x5161f
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0xaa240
jmp 0x51638
movl -0x5dc(%rbp), %edi
leaq -0x78(%rbp), %rsi
callq 0x28d30
jmp 0x51649
leaq -0x78(%rbp), %rdi
callq 0x34a8
jmp 0x51654
leaq -0xe0(%rbp), %rdi
callq 0x34a8
jmp 0x51662
testb $0x1, -0x12b(%rbp)
jne 0x5166d
jmp 0x5167d
leaq -0x128(%rbp), %rdi
callq 0x34a8
jmp 0x5167b
jmp 0x5167d
testb $0x1, -0x12a(%rbp)
jne 0x51688
jmp 0x51694
leaq -0x129(%rbp), %rdi
callq 0x3290
testb $0x1, -0x103(%rbp)
jne 0x5169f
jmp 0x516ab
leaq -0x102(%rbp), %rdi
callq 0x3290
leaq -0x100(%rbp), %rdi
callq 0x34a8
jmp 0x516b9
leaq -0x101(%rbp), %rdi
callq 0x3290
leaq -0x98(%rbp), %rdi
callq 0x34a8
jmp 0x516d3
leaq -0xb8(%rbp), %rdi
callq 0x34a8
jmp 0x516e1
leaq -0xb9(%rbp), %rdi
callq 0x3290
leaq -0x148(%rbp), %rdi
callq 0x1a4a0
jmp 0x516fb
movl $0x5, -0x154(%rbp)
leaq -0x3d8(%rbp), %rdi
callq 0x11ad0
jmp 0x51713
leaq 0x886(%rip), %rax       # 0x51fa0
movq %rax, -0x3c0(%rbp)
leaq -0x154(%rbp), %rax
movq %rax, -0x3b8(%rbp)
movl $0x0, -0x3d8(%rbp)
movl $0x0, -0x3b0(%rbp)
movl $0x0, 0xa6b63(%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 0x5177a
movl -0x604(%rbp), %eax
movl %eax, -0x3dc(%rbp)
movl $0x1, %eax
cmpl 0xa6b1f(%rip), %eax     # 0xf82b0
je 0x51c15
leaq -0x481(%rbp), %rdi
movq %rdi, -0x610(%rbp)
callq 0x3440
movq -0x610(%rbp), %rdx
leaq 0x6195d(%rip), %rsi     # 0xb3115
leaq -0x480(%rbp), %rdi
callq 0x3340
jmp 0x517c6
leaq 0x62e08(%rip), %rdx     # 0xb45d5
leaq -0x460(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0xaa1b0
jmp 0x517e2
leaq 0x64efa(%rip), %rdx     # 0xb66e3
leaq -0x440(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0xaa1b0
jmp 0x517fe
leaq 0x62d1c(%rip), %rdx     # 0xb4521
leaq -0x420(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0xaa1b0
jmp 0x5181a
leaq 0x6193c(%rip), %rdx     # 0xb315d
leaq -0x400(%rbp), %rdi
leaq -0x420(%rbp), %rsi
callq 0xaa1b0
jmp 0x51836
movq 0xa679b(%rip), %rdi     # 0xf7fd8
leaq -0x400(%rbp), %rsi
callq 0x3200
jmp 0x5184b
leaq -0x400(%rbp), %rdi
callq 0x34a8
jmp 0x51859
leaq -0x420(%rbp), %rdi
callq 0x34a8
jmp 0x51867
leaq -0x440(%rbp), %rdi
callq 0x34a8
jmp 0x51875
leaq -0x460(%rbp), %rdi
callq 0x34a8
jmp 0x51883
leaq -0x480(%rbp), %rdi
callq 0x34a8
jmp 0x51891
leaq -0x481(%rbp), %rdi
callq 0x3290
movq 0xa6734(%rip), %rdi     # 0xf7fd8
leaq 0x8a5a0(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x618(%rbp)
jmp 0x518b9
movl $0x1, -0x4ac(%rbp)
leaq -0x4a8(%rbp), %rdi
leaq -0x4ac(%rbp), %rsi
callq 0xaaa20
jmp 0x518d8
movq -0x618(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x3200
movq %rax, -0x620(%rbp)
jmp 0x518f4
movq -0x620(%rbp), %rdi
leaq 0x61873(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x628(%rbp)
jmp 0x51910
leaq 0xa6999(%rip), %rsi     # 0xf82b0
leaq -0x4d0(%rbp), %rdi
callq 0xaaa20
jmp 0x51925
movq -0x628(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x3200
movq %rax, -0x630(%rbp)
jmp 0x51941
movq -0x630(%rbp), %rdi
leaq 0x6170d(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x638(%rbp)
jmp 0x5195d
movq -0x638(%rbp), %rdi
movq 0xa6655(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x51972
leaq -0x4d0(%rbp), %rdi
callq 0x34a8
jmp 0x51980
leaq -0x4a8(%rbp), %rdi
callq 0x34a8
jmp 0x5198e
callq 0x28bd0
jmp 0x51995
jmp 0x51c15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51f7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51f6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51aef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51adf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51ac3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51ab3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51a9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51a81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51a64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51a54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x34a8
jmp 0x51a52
jmp 0x51a54
leaq -0xe0(%rbp), %rdi
callq 0x34a8
jmp 0x51a62
jmp 0x51a64
testb $0x1, -0x12b(%rbp)
jne 0x51a6f
jmp 0x51a7f
leaq -0x128(%rbp), %rdi
callq 0x34a8
jmp 0x51a7d
jmp 0x51a7f
jmp 0x51a81
testb $0x1, -0x12a(%rbp)
jne 0x51a8c
jmp 0x51a98
leaq -0x129(%rbp), %rdi
callq 0x3290
jmp 0x51a9a
testb $0x1, -0x103(%rbp)
jne 0x51aa5
jmp 0x51ab1
leaq -0x102(%rbp), %rdi
callq 0x3290
jmp 0x51ab3
leaq -0x100(%rbp), %rdi
callq 0x34a8
jmp 0x51ac1
jmp 0x51ac3
leaq -0x101(%rbp), %rdi
callq 0x3290
leaq -0x98(%rbp), %rdi
callq 0x34a8
jmp 0x51add
jmp 0x51adf
leaq -0xb8(%rbp), %rdi
callq 0x34a8
jmp 0x51aed
jmp 0x51aef
leaq -0xb9(%rbp), %rdi
callq 0x3290
jmp 0x51f6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51f5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51f4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51bc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51bb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51ba7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51b97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51b87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x34a8
jmp 0x51b85
jmp 0x51b87
leaq -0x420(%rbp), %rdi
callq 0x34a8
jmp 0x51b95
jmp 0x51b97
leaq -0x440(%rbp), %rdi
callq 0x34a8
jmp 0x51ba5
jmp 0x51ba7
leaq -0x460(%rbp), %rdi
callq 0x34a8
jmp 0x51bb5
jmp 0x51bb7
leaq -0x480(%rbp), %rdi
callq 0x34a8
jmp 0x51bc5
jmp 0x51bc7
leaq -0x481(%rbp), %rdi
callq 0x3290
jmp 0x51f4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51c02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x4d0(%rbp), %rdi
callq 0x34a8
jmp 0x51c00
jmp 0x51c02
leaq -0x4a8(%rbp), %rdi
callq 0x34a8
jmp 0x51c10
jmp 0x51f4f
movl $0x6e, %eax
cmpl -0x3dc(%rbp), %eax
je 0x51f16
leaq -0x571(%rbp), %rdi
movq %rdi, -0x640(%rbp)
callq 0x3440
movq -0x640(%rbp), %rdx
leaq 0x614ce(%rip), %rsi     # 0xb3115
leaq -0x570(%rbp), %rdi
callq 0x3340
jmp 0x51c55
leaq 0x6297e(%rip), %rdx     # 0xb45da
leaq -0x550(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0xaa1b0
jmp 0x51c71
leaq 0x64a6b(%rip), %rdx     # 0xb66e3
leaq -0x530(%rbp), %rdi
leaq -0x550(%rbp), %rsi
callq 0xaa1b0
jmp 0x51c8d
leaq 0x613e1(%rip), %rdx     # 0xb3075
leaq -0x510(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0xaa1b0
jmp 0x51ca9
leaq 0x614ad(%rip), %rdx     # 0xb315d
leaq -0x4f0(%rbp), %rdi
leaq -0x510(%rbp), %rsi
callq 0xaa1b0
jmp 0x51cc5
movq 0xa630c(%rip), %rdi     # 0xf7fd8
leaq -0x4f0(%rbp), %rsi
callq 0x3200
jmp 0x51cda
leaq -0x4f0(%rbp), %rdi
callq 0x34a8
jmp 0x51ce8
leaq -0x510(%rbp), %rdi
callq 0x34a8
jmp 0x51cf6
leaq -0x530(%rbp), %rdi
callq 0x34a8
jmp 0x51d04
leaq -0x550(%rbp), %rdi
callq 0x34a8
jmp 0x51d12
leaq -0x570(%rbp), %rdi
callq 0x34a8
jmp 0x51d20
leaq -0x571(%rbp), %rdi
callq 0x3290
movq 0xa62a5(%rip), %rdi     # 0xf7fd8
leaq 0x8a111(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x648(%rbp)
jmp 0x51d48
movl $0x6e, -0x59c(%rbp)
leaq -0x598(%rbp), %rdi
leaq -0x59c(%rbp), %rsi
callq 0xaaa20
jmp 0x51d67
movq -0x648(%rbp), %rdi
leaq -0x598(%rbp), %rsi
callq 0x3200
movq %rax, -0x650(%rbp)
jmp 0x51d83
movq -0x650(%rbp), %rdi
leaq 0x613e4(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x658(%rbp)
jmp 0x51d9f
leaq -0x5c0(%rbp), %rdi
leaq -0x3dc(%rbp), %rsi
callq 0xaa7f0
jmp 0x51db4
movq -0x658(%rbp), %rdi
leaq -0x5c0(%rbp), %rsi
callq 0x3200
movq %rax, -0x660(%rbp)
jmp 0x51dd0
movq -0x660(%rbp), %rdi
leaq 0x6127e(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x668(%rbp)
jmp 0x51dec
movq -0x668(%rbp), %rdi
movq 0xa61c6(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x51e01
leaq -0x5c0(%rbp), %rdi
callq 0x34a8
jmp 0x51e0f
leaq -0x598(%rbp), %rdi
callq 0x34a8
jmp 0x51e1d
callq 0x28bd0
jmp 0x51e24
jmp 0x51f16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51ece
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51ebe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51eae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51e9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51e8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x4f0(%rbp), %rdi
callq 0x34a8
jmp 0x51e8c
jmp 0x51e8e
leaq -0x510(%rbp), %rdi
callq 0x34a8
jmp 0x51e9c
jmp 0x51e9e
leaq -0x530(%rbp), %rdi
callq 0x34a8
jmp 0x51eac
jmp 0x51eae
leaq -0x550(%rbp), %rdi
callq 0x34a8
jmp 0x51ebc
jmp 0x51ebe
leaq -0x570(%rbp), %rdi
callq 0x34a8
jmp 0x51ecc
jmp 0x51ece
leaq -0x571(%rbp), %rdi
callq 0x3290
jmp 0x51f4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x51f06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x5c0(%rbp), %rdi
callq 0x34a8
jmp 0x51f04
jmp 0x51f06
leaq -0x598(%rbp), %rdi
callq 0x34a8
jmp 0x51f14
jmp 0x51f4f
leaq -0x3d8(%rbp), %rdi
callq 0x11b20
jmp 0x51f24
leaq -0x148(%rbp), %rdi
callq 0x1a4c0
jmp 0x51f32
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x51f3d
leaq -0x28(%rbp), %rdi
callq 0xaab00
addq $0x670, %rsp            # imm = 0x670
popq %rbp
retq
leaq -0x3d8(%rbp), %rdi
callq 0x11b20
jmp 0x51f5d
jmp 0x51f5f
leaq -0x148(%rbp), %rdi
callq 0x1a4c0
jmp 0x51f6d
jmp 0x51f6f
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x51f7a
jmp 0x51f7c
leaq -0x28(%rbp), %rdi
callq 0xaab00
jmp 0x51f87
jmp 0x51f89
movq -0x30(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nopw (%rax,%rax)