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

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

  struct TestFun {
    static unsigned custom_deflate(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_deflate = TestFun::custom_deflate;
  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 deflate 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 0xa8536(%rip), %rdi     # 0xf7fd8
leaq 0x64ab6(%rip), %rsi     # 0xb455f
callq 0x3230
movq %rax, %rdi
movq 0xa8508(%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 0x4faed
leaq -0x50(%rbp), %rdi
callq 0x1a4a0
jmp 0x4faf8
movl $0x5, -0x54(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x11ad0
jmp 0x4fb0d
leaq 0x6ec(%rip), %rax       # 0x50200
movq %rax, -0x268(%rbp)
leaq -0x54(%rbp), %rax
movq %rax, -0x260(%rbp)
movl $0x0, 0xa8780(%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 0x4fb52
movl -0x4cc(%rbp), %eax
movl %eax, -0x2dc(%rbp)
movl $0x1, %eax
cmpl 0xa8747(%rip), %eax     # 0xf82b0
je 0x4fe98
leaq -0x381(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x3440
movq -0x4d8(%rbp), %rdx
leaq 0x63585(%rip), %rsi     # 0xb3115
leaq -0x380(%rbp), %rdi
callq 0x3340
jmp 0x4fb9e
leaq 0x649cc(%rip), %rdx     # 0xb4571
leaq -0x360(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0xaa1b0
jmp 0x4fbba
leaq 0x66b22(%rip), %rdx     # 0xb66e3
leaq -0x340(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0xaa1b0
jmp 0x4fbd6
leaq 0x64944(%rip), %rdx     # 0xb4521
leaq -0x320(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0xaa1b0
jmp 0x4fbf2
leaq 0x63564(%rip), %rdx     # 0xb315d
leaq -0x300(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0xaa1b0
jmp 0x4fc0e
movq 0xa83c3(%rip), %rdi     # 0xf7fd8
leaq -0x300(%rbp), %rsi
callq 0x3200
jmp 0x4fc23
leaq -0x300(%rbp), %rdi
callq 0x34a8
jmp 0x4fc31
leaq -0x320(%rbp), %rdi
callq 0x34a8
jmp 0x4fc3f
leaq -0x340(%rbp), %rdi
callq 0x34a8
jmp 0x4fc4d
leaq -0x360(%rbp), %rdi
callq 0x34a8
jmp 0x4fc5b
leaq -0x380(%rbp), %rdi
callq 0x34a8
jmp 0x4fc69
leaq -0x381(%rbp), %rdi
callq 0x3290
movq 0xa835c(%rip), %rdi     # 0xf7fd8
leaq 0x8c1c8(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x4e0(%rbp)
jmp 0x4fc91
movl $0x1, -0x3ac(%rbp)
leaq -0x3a8(%rbp), %rdi
leaq -0x3ac(%rbp), %rsi
callq 0xaaa20
jmp 0x4fcb0
movq -0x4e0(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
callq 0x3200
movq %rax, -0x4e8(%rbp)
jmp 0x4fccc
movq -0x4e8(%rbp), %rdi
leaq 0x6349b(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x4f0(%rbp)
jmp 0x4fce8
leaq 0xa85c1(%rip), %rsi     # 0xf82b0
leaq -0x3d0(%rbp), %rdi
callq 0xaaa20
jmp 0x4fcfd
movq -0x4f0(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x3200
movq %rax, -0x4f8(%rbp)
jmp 0x4fd19
movq -0x4f8(%rbp), %rdi
leaq 0x63335(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x500(%rbp)
jmp 0x4fd35
movq -0x500(%rbp), %rdi
movq 0xa827d(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x4fd4a
leaq -0x3d0(%rbp), %rdi
callq 0x34a8
jmp 0x4fd58
leaq -0x3a8(%rbp), %rdi
callq 0x34a8
jmp 0x4fd66
callq 0x28bd0
jmp 0x4fd6d
jmp 0x4fe98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x501e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x501d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x501c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4fe4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4fe3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4fe2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4fe1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4fe0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x34a8
jmp 0x4fe08
jmp 0x4fe0a
leaq -0x320(%rbp), %rdi
callq 0x34a8
jmp 0x4fe18
jmp 0x4fe1a
leaq -0x340(%rbp), %rdi
callq 0x34a8
jmp 0x4fe28
jmp 0x4fe2a
leaq -0x360(%rbp), %rdi
callq 0x34a8
jmp 0x4fe38
jmp 0x4fe3a
leaq -0x380(%rbp), %rdi
callq 0x34a8
jmp 0x4fe48
jmp 0x4fe4a
leaq -0x381(%rbp), %rdi
callq 0x3290
jmp 0x501c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4fe85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x3d0(%rbp), %rdi
callq 0x34a8
jmp 0x4fe83
jmp 0x4fe85
leaq -0x3a8(%rbp), %rdi
callq 0x34a8
jmp 0x4fe93
jmp 0x501c4
movl $0x6f, %eax
cmpl -0x2dc(%rbp), %eax
je 0x50199
leaq -0x471(%rbp), %rdi
movq %rdi, -0x508(%rbp)
callq 0x3440
movq -0x508(%rbp), %rdx
leaq 0x6324b(%rip), %rsi     # 0xb3115
leaq -0x470(%rbp), %rdi
callq 0x3340
jmp 0x4fed8
leaq 0x64697(%rip), %rdx     # 0xb4576
leaq -0x450(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0xaa1b0
jmp 0x4fef4
leaq 0x667e8(%rip), %rdx     # 0xb66e3
leaq -0x430(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0xaa1b0
jmp 0x4ff10
leaq 0x6315e(%rip), %rdx     # 0xb3075
leaq -0x410(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xaa1b0
jmp 0x4ff2c
leaq 0x6322a(%rip), %rdx     # 0xb315d
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0xaa1b0
jmp 0x4ff48
movq 0xa8089(%rip), %rdi     # 0xf7fd8
leaq -0x3f0(%rbp), %rsi
callq 0x3200
jmp 0x4ff5d
leaq -0x3f0(%rbp), %rdi
callq 0x34a8
jmp 0x4ff6b
leaq -0x410(%rbp), %rdi
callq 0x34a8
jmp 0x4ff79
leaq -0x430(%rbp), %rdi
callq 0x34a8
jmp 0x4ff87
leaq -0x450(%rbp), %rdi
callq 0x34a8
jmp 0x4ff95
leaq -0x470(%rbp), %rdi
callq 0x34a8
jmp 0x4ffa3
leaq -0x471(%rbp), %rdi
callq 0x3290
movq 0xa8022(%rip), %rdi     # 0xf7fd8
leaq 0x8be8e(%rip), %rsi     # 0xdbe4b
callq 0x3230
movq %rax, -0x510(%rbp)
jmp 0x4ffcb
movl $0x6f, -0x49c(%rbp)
leaq -0x498(%rbp), %rdi
leaq -0x49c(%rbp), %rsi
callq 0xaaa20
jmp 0x4ffea
movq -0x510(%rbp), %rdi
leaq -0x498(%rbp), %rsi
callq 0x3200
movq %rax, -0x518(%rbp)
jmp 0x50006
movq -0x518(%rbp), %rdi
leaq 0x63161(%rip), %rsi     # 0xb3175
callq 0x3230
movq %rax, -0x520(%rbp)
jmp 0x50022
leaq -0x4c0(%rbp), %rdi
leaq -0x2dc(%rbp), %rsi
callq 0xaa7f0
jmp 0x50037
movq -0x520(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
callq 0x3200
movq %rax, -0x528(%rbp)
jmp 0x50053
movq -0x528(%rbp), %rdi
leaq 0x62ffb(%rip), %rsi     # 0xb305c
callq 0x3230
movq %rax, -0x530(%rbp)
jmp 0x5006f
movq -0x530(%rbp), %rdi
movq 0xa7f43(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x50084
leaq -0x4c0(%rbp), %rdi
callq 0x34a8
jmp 0x50092
leaq -0x498(%rbp), %rdi
callq 0x34a8
jmp 0x500a0
callq 0x28bd0
jmp 0x500a7
jmp 0x50199
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50151
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50141
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50131
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50121
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50111
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x34a8
jmp 0x5010f
jmp 0x50111
leaq -0x410(%rbp), %rdi
callq 0x34a8
jmp 0x5011f
jmp 0x50121
leaq -0x430(%rbp), %rdi
callq 0x34a8
jmp 0x5012f
jmp 0x50131
leaq -0x450(%rbp), %rdi
callq 0x34a8
jmp 0x5013f
jmp 0x50141
leaq -0x470(%rbp), %rdi
callq 0x34a8
jmp 0x5014f
jmp 0x50151
leaq -0x471(%rbp), %rdi
callq 0x3290
jmp 0x501c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x50189
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x4c0(%rbp), %rdi
callq 0x34a8
jmp 0x50187
jmp 0x50189
leaq -0x498(%rbp), %rdi
callq 0x34a8
jmp 0x50197
jmp 0x501c4
leaq -0x2d8(%rbp), %rdi
callq 0x11b20
jmp 0x501a7
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x501b2
leaq -0x28(%rbp), %rdi
callq 0xaab00
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
leaq -0x2d8(%rbp), %rdi
callq 0x11b20
jmp 0x501d2
jmp 0x501d4
leaq -0x50(%rbp), %rdi
callq 0x1a4c0
jmp 0x501df
jmp 0x501e1
leaq -0x28(%rbp), %rdi
callq 0xaab00
jmp 0x501ec
jmp 0x501ee
movq -0x30(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nop