// File: lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: testFuzzing()
void testFuzzing() {
  std::cout << "testFuzzing" << std::endl;
  std::vector<unsigned char> png;
  createComplexPNG(png);
  std::vector<unsigned char> broken = png;
  std::vector<unsigned char> result;
  std::map<unsigned, unsigned> errors;
  unsigned w, h;
  lodepng::State state;
  state.decoder.ignore_crc = 1;
  state.decoder.zlibsettings.ignore_adler32 = 1;
  for(size_t i = 0; i < png.size(); i++) {
    result.clear();
    broken[i] = ~png[i];
    errors[lodepng::decode(result, w, h, state, broken)]++;
    broken[i] = 0;
    errors[lodepng::decode(result, w, h, state, broken)]++;
    for(int j = 0; j < 8; j++) {
      broken[i] = flipBit(png[i], j);
      errors[lodepng::decode(result, w, h, state, broken)]++;
    }
    broken[i] = 255;
    errors[lodepng::decode(result, w, h, state, broken)]++;
    broken[i] = png[i]; //fix it again for the next test
  }
  std::cout << "testFuzzing shrinking" << std::endl;
  broken = png;
  while(broken.size() > 0) {
    broken.resize(broken.size() - 1);
    errors[lodepng::decode(result, w, h, state, broken)]++;
  }

  //For fun, print the number of each error
  std::cout << "Fuzzing error code counts: ";
  for(std::map<unsigned, unsigned>::iterator it = errors.begin(); it != errors.end(); ++it) {
    std::cout << it->first << ":" << it->second << ", ";
  }
  std::cout << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq 0xaa5e6(%rip), %rdi     # 0xf7fd8
leaq 0x66ac9(%rip), %rsi     # 0xb44c2
callq 0x3230
movq %rax, %rdi
movq 0xaa5b8(%rip), %rsi     # 0xf7fc0
callq 0x3280
leaq -0x18(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x1a4a0
movq -0x348(%rbp), %rdi
callq 0x3a400
jmp 0x4da2b
leaq -0x40(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x25250
jmp 0x4da3a
leaq -0x58(%rbp), %rdi
callq 0x1a4a0
jmp 0x4da45
leaq -0x88(%rbp), %rdi
callq 0xab370
jmp 0x4da53
leaq -0x310(%rbp), %rdi
callq 0x11ad0
jmp 0x4da61
movl $0x1, -0x2e8(%rbp)
movl $0x1, -0x310(%rbp)
movq $0x0, -0x318(%rbp)
movq -0x318(%rbp), %rax
movq %rax, -0x358(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x1a400
movq %rax, -0x350(%rbp)
jmp 0x4daa0
movq -0x358(%rbp), %rax
movq -0x350(%rbp), %rcx
cmpq %rcx, %rax
jae 0x4de27
leaq -0x58(%rbp), %rdi
callq 0xab390
jmp 0x4dac2
movq -0x318(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x360(%rbp)
jmp 0x4dadb
movq -0x360(%rbp), %rax
movb (%rax), %al
notb %al
movb %al, -0x369(%rbp)
movq -0x318(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x368(%rbp)
jmp 0x4db05
movq -0x368(%rbp), %rax
movb -0x369(%rbp), %cl
movb %cl, (%rax)
leaq -0x58(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x310(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x11e30
movl %eax, -0x370(%rbp)
jmp 0x4db3e
movl -0x370(%rbp), %eax
movl %eax, -0x31c(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x31c(%rbp), %rsi
callq 0xab3b0
movq %rax, -0x378(%rbp)
jmp 0x4db66
movq -0x378(%rbp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq -0x318(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x380(%rbp)
jmp 0x4db8c
movq -0x380(%rbp), %rax
movb $0x0, (%rax)
leaq -0x58(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x310(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x11e30
movl %eax, -0x384(%rbp)
jmp 0x4dbc0
movl -0x384(%rbp), %eax
movl %eax, -0x320(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0xab3b0
movq %rax, -0x390(%rbp)
jmp 0x4dbe8
movq -0x390(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x324(%rbp)
cmpl $0x8, -0x324(%rbp)
jge 0x4dd3e
movq -0x318(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x398(%rbp)
jmp 0x4dc26
movq -0x398(%rbp), %rax
movzbl (%rax), %edi
movl -0x324(%rbp), %esi
callq 0x4d9b0
movb %al, -0x3a1(%rbp)
movq -0x318(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x3a0(%rbp)
jmp 0x4dc5a
movq -0x3a0(%rbp), %rax
movb -0x3a1(%rbp), %cl
movb %cl, (%rax)
leaq -0x58(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x310(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x11e30
movl %eax, -0x3a8(%rbp)
jmp 0x4dc93
movl -0x3a8(%rbp), %eax
movl %eax, -0x328(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0xab3b0
movq %rax, -0x3b0(%rbp)
jmp 0x4dcbb
movq -0x3b0(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x324(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x324(%rbp)
jmp 0x4dc00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4e0d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4e0c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4e0b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4e0a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x11b20
jmp 0x4e0a5
movq -0x318(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x3b8(%rbp)
jmp 0x4dd57
movq -0x3b8(%rbp), %rax
movb $-0x1, (%rax)
leaq -0x58(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x310(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x11e30
movl %eax, -0x3bc(%rbp)
jmp 0x4dd8b
movl -0x3bc(%rbp), %eax
movl %eax, -0x32c(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x32c(%rbp), %rsi
callq 0xab3b0
movq %rax, -0x3c8(%rbp)
jmp 0x4ddb3
movq -0x3c8(%rbp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq -0x318(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x3d0(%rbp)
jmp 0x4ddd9
movq -0x3d0(%rbp), %rax
movb (%rax), %al
movb %al, -0x3d9(%rbp)
movq -0x318(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1a5f0
movq %rax, -0x3d8(%rbp)
jmp 0x4de01
movq -0x3d8(%rbp), %rax
movb -0x3d9(%rbp), %cl
movb %cl, (%rax)
movq -0x318(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x318(%rbp)
jmp 0x4da80
movq 0xaa1aa(%rip), %rdi     # 0xf7fd8
leaq 0x66699(%rip), %rsi     # 0xb44ce
callq 0x3230
movq %rax, -0x3e8(%rbp)
jmp 0x4de43
movq -0x3e8(%rbp), %rdi
movq 0xaa16f(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x4de58
leaq -0x40(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x23520
jmp 0x4de67
jmp 0x4de69
leaq -0x40(%rbp), %rdi
callq 0x1a400
movq %rax, -0x3f0(%rbp)
jmp 0x4de7b
movq -0x3f0(%rbp), %rax
cmpq $0x0, %rax
jbe 0x4df1a
leaq -0x40(%rbp), %rdi
callq 0x1a400
movq %rax, -0x3f8(%rbp)
jmp 0x4de9e
movq -0x3f8(%rbp), %rsi
decq %rsi
leaq -0x40(%rbp), %rdi
xorl %edx, %edx
callq 0x1a540
jmp 0x4deb5
leaq -0x58(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x310(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x11e30
movl %eax, -0x3fc(%rbp)
jmp 0x4dedf
movl -0x3fc(%rbp), %eax
movl %eax, -0x330(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0xab3b0
movq %rax, -0x408(%rbp)
jmp 0x4df07
movq -0x408(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4de69
movq 0xaa0b7(%rip), %rdi     # 0xf7fd8
leaq 0x665bc(%rip), %rsi     # 0xb44e4
callq 0x3230
jmp 0x4df2f
leaq -0x88(%rbp), %rdi
callq 0xab490
movq %rax, -0x410(%rbp)
jmp 0x4df44
movq -0x410(%rbp), %rax
movq %rax, -0x338(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xab4f0
movq %rax, -0x418(%rbp)
jmp 0x4df67
movq -0x418(%rbp), %rax
movq %rax, -0x340(%rbp)
leaq -0x338(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0xab4c0
movb %al, -0x419(%rbp)
jmp 0x4df90
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0x4df9f
jmp 0x4e04c
leaq -0x338(%rbp), %rdi
callq 0xab520
movq %rax, -0x428(%rbp)
jmp 0x4dfb4
movq -0x428(%rbp), %rax
movl (%rax), %esi
movq 0xaa014(%rip), %rdi     # 0xf7fd8
callq 0x3310
movq %rax, -0x430(%rbp)
jmp 0x4dfd2
movq -0x430(%rbp), %rdi
leaq 0x66520(%rip), %rsi     # 0xb4500
callq 0x3230
movq %rax, -0x438(%rbp)
jmp 0x4dfee
leaq -0x338(%rbp), %rdi
callq 0xab520
movq %rax, -0x440(%rbp)
jmp 0x4e003
movq -0x438(%rbp), %rdi
movq -0x440(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x3310
movq %rax, -0x448(%rbp)
jmp 0x4e022
movq -0x448(%rbp), %rdi
leaq 0x664d2(%rip), %rsi     # 0xb4502
callq 0x3230
jmp 0x4e037
jmp 0x4e039
leaq -0x338(%rbp), %rdi
callq 0xab540
jmp 0x4e047
jmp 0x4df52
movq 0xa9f85(%rip), %rdi     # 0xf7fd8
movq 0xa9f66(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x4e061
leaq -0x310(%rbp), %rdi
callq 0x11b20
jmp 0x4e06f
leaq -0x88(%rbp), %rdi
callq 0xab570
jmp 0x4e07d
leaq -0x58(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e088
leaq -0x40(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e093
leaq -0x18(%rbp), %rdi
callq 0x1a4c0
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
jmp 0x4e0a7
leaq -0x88(%rbp), %rdi
callq 0xab570
jmp 0x4e0b5
jmp 0x4e0b7
leaq -0x58(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e0c2
jmp 0x4e0c4
leaq -0x40(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e0cf
jmp 0x4e0d1
leaq -0x18(%rbp), %rdi
callq 0x1a4c0
jmp 0x4e0dc
jmp 0x4e0de
movq -0x20(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nop