// File: lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: generateTestImageRequiringColorType16(Image&, LodePNGColorType, unsigned int, bool)
void generateTestImageRequiringColorType16(Image& image, LodePNGColorType colorType, unsigned bitDepth, bool key) {
  image.colorType = colorType;
  image.bitDepth = bitDepth;
  unsigned w = 1;
  unsigned h = 1;

  bool gray = colorType == LCT_GREY || colorType == LCT_GREY_ALPHA;
  bool alpha = colorType == LCT_RGBA || colorType == LCT_GREY_ALPHA;

  if(colorType == LCT_PALETTE) {
    w = 1u << bitDepth;
    h = 256; // ensure it'll really choose palette, not omit it due to small image size
    image.data.resize(w * h * 8);
    for(size_t y = 0; y < h; y++) {
      for(size_t x = 0; x < w; x++) {
        size_t i = y * w * 8 + x * 8;
        image.data[i + 0] = image.data[i + 1] = y;
        image.data[i + 2] = image.data[i + 3] = 255;
        image.data[i + 4] = image.data[i + 5] = 0;
        image.data[i + 6] = image.data[i + 7] = (key && y == 0) ? 0 : 255;
      }
    }
  } else if(bitDepth == 16) {
    // one color suffices for this model. But add one more to support key.
    w = 2;
    image.data.resize(w * h * 8);
    image.data[0] = 10; image.data[1] = 20;
    image.data[2] = 10; image.data[3] = 20;
    image.data[4] = gray ? 10 : 110; image.data[5] = gray ? 20 : 120;
    image.data[6] = alpha ? 128 : 255; image.data[7] = alpha ? 20 : 255;

    image.data[8] = 40; image.data[9] = 50;
    image.data[10] = 40; image.data[11] = 50;
    image.data[12] = gray ? 40 : 140; image.data[13] = gray ? 50 : 150;
    image.data[14] = key ? 0 : 255; image.data[15] = key ? 0 : 255;
  } else if(gray) {
    w = 2;
    unsigned v = 255u / ((1u << bitDepth) - 1u); // value that forces at least this bitdepth
    image.data.resize(w * h * 8);
    image.data[0] = v; image.data[1] = v;
    image.data[2] = v; image.data[3] = v;
    image.data[4] = v; image.data[5] = v;
    image.data[6] = alpha ? v : 255; image.data[7] = alpha ? v : 255;

    image.data[8] = image.data[9] = 0;
    image.data[10] = image.data[11] = 0;
    image.data[12] = image.data[13] = 0;
    image.data[14] = image.data[15] = key ? 0 : 255;
  } else {
    // now it's RGB or RGBA with bitdepth 8
    w = 257; // must have at least more than 256 colors so it won't use palette
    image.data.resize(w * h * 8);
    for(size_t y = 0; y < h; y++) {
      for(size_t x = 0; x < w; x++) {
        size_t i = y * w * 8 + x * 8;
        image.data[i + 0] = image.data[i + 1] = i / 2;
        image.data[i + 2] = image.data[i + 3] = i / 3;
        image.data[i + 4] = image.data[i + 5] = i / 5;
        image.data[i + 6] = image.data[i + 7] = (key && y == 0) ? 0 : (alpha ? i : 255);
      }
    }
  }

  image.width = w;
  image.height = h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl $0x1, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movb $0x1, %al
cmpl $0x0, -0xc(%rbp)
movb %al, -0x59(%rbp)
je 0x29b63
cmpl $0x4, -0xc(%rbp)
sete %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
movb $0x1, %al
cmpl $0x6, -0xc(%rbp)
movb %al, -0x5a(%rbp)
je 0x29b80
cmpl $0x4, -0xc(%rbp)
sete %al
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %al
andb $0x1, %al
movb %al, -0x1e(%rbp)
cmpl $0x3, -0xc(%rbp)
jne 0x29d0e
movl -0x10(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x18(%rbp)
movl $0x100, -0x1c(%rbp)     # imm = 0x100
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1a540
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x29d09
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x29cf6
movq -0x28(%rbp), %rax
movl -0x18(%rbp), %ecx
imulq %rcx, %rax
shlq $0x3, %rax
movq -0x30(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movb %al, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x1, %rsi
callq 0x1a5f0
movb -0x5c(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x0, %rsi
callq 0x1a5f0
movb -0x5c(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x3, %rsi
callq 0x1a5f0
movb $-0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x2, %rsi
callq 0x1a5f0
movb $-0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x5, %rsi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x4, %rsi
callq 0x1a5f0
movb $0x0, (%rax)
xorl %eax, %eax
testb $0x1, -0x11(%rbp)
movb %al, -0x5b(%rbp)
je 0x29ca6
cmpq $0x0, -0x28(%rbp)
sete %al
movb %al, -0x5b(%rbp)
movb -0x5b(%rbp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x5d(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x7, %rsi
callq 0x1a5f0
movb -0x5d(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x6, %rsi
callq 0x1a5f0
movb -0x5d(%rbp), %cl
movb %cl, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x29bdf
jmp 0x29cf8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x29bc7
jmp 0x2a2b4
cmpl $0x10, -0x10(%rbp)
jne 0x29f06
movl $0x2, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1a540
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1a5f0
movb $0xa, (%rax)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x1a5f0
movb $0x14, (%rax)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x1a5f0
movb $0xa, (%rax)
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x1a5f0
movb $0x14, (%rax)
movb -0x1d(%rbp), %dl
movl $0x6e, %eax
movl $0xa, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x65(%rbp)
movq -0x8(%rbp), %rdi
movl $0x4, %esi
callq 0x1a5f0
movb -0x65(%rbp), %cl
movb %cl, (%rax)
movb -0x1d(%rbp), %dl
movl $0x78, %eax
movl $0x14, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movl $0x5, %esi
callq 0x1a5f0
movb -0x64(%rbp), %cl
movb %cl, (%rax)
movb -0x1e(%rbp), %dl
movl $0xff, %eax
movl $0x80, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x63(%rbp)
movq -0x8(%rbp), %rdi
movl $0x6, %esi
callq 0x1a5f0
movb -0x63(%rbp), %cl
movb %cl, (%rax)
movb -0x1e(%rbp), %dl
movl $0xff, %eax
movl $0x14, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x62(%rbp)
movq -0x8(%rbp), %rdi
movl $0x7, %esi
callq 0x1a5f0
movb -0x62(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movl $0x8, %esi
callq 0x1a5f0
movb $0x28, (%rax)
movq -0x8(%rbp), %rdi
movl $0x9, %esi
callq 0x1a5f0
movb $0x32, (%rax)
movq -0x8(%rbp), %rdi
movl $0xa, %esi
callq 0x1a5f0
movb $0x28, (%rax)
movq -0x8(%rbp), %rdi
movl $0xb, %esi
callq 0x1a5f0
movb $0x32, (%rax)
movb -0x1d(%rbp), %dl
movl $0x8c, %eax
movl $0x28, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x61(%rbp)
movq -0x8(%rbp), %rdi
movl $0xc, %esi
callq 0x1a5f0
movb -0x61(%rbp), %cl
movb %cl, (%rax)
movb -0x1d(%rbp), %dl
movl $0x96, %eax
movl $0x32, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movl $0xd, %esi
callq 0x1a5f0
movb -0x60(%rbp), %cl
movb %cl, (%rax)
movb -0x11(%rbp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x5f(%rbp)
movq -0x8(%rbp), %rdi
movl $0xe, %esi
callq 0x1a5f0
movb -0x5f(%rbp), %cl
movb %cl, (%rax)
movb -0x11(%rbp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x5e(%rbp)
movq -0x8(%rbp), %rdi
movl $0xf, %esi
callq 0x1a5f0
movb -0x5e(%rbp), %cl
movb %cl, (%rax)
jmp 0x2a2b2
testb $0x1, -0x1d(%rbp)
je 0x2a0e6
movl $0x2, -0x18(%rbp)
movl -0x10(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
subl $0x1, %ecx
movl $0xff, %eax
xorl %edx, %edx
divl %ecx
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1a540
movl -0x3c(%rbp), %eax
movb %al, -0x6b(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1a5f0
movb -0x6b(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x6a(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x1a5f0
movb -0x6a(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x69(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x1a5f0
movb -0x69(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x1a5f0
movb -0x68(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x67(%rbp)
movq -0x8(%rbp), %rdi
movl $0x4, %esi
callq 0x1a5f0
movb -0x67(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x66(%rbp)
movq -0x8(%rbp), %rdi
movl $0x5, %esi
callq 0x1a5f0
movb -0x66(%rbp), %cl
movb %cl, (%rax)
testb $0x1, -0x1e(%rbp)
je 0x29fee
movl -0x3c(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x29ff8
movl $0xff, %eax
movl %eax, -0x70(%rbp)
jmp 0x29ff8
movl -0x70(%rbp), %eax
movb %al, -0x71(%rbp)
movq -0x8(%rbp), %rdi
movl $0x6, %esi
callq 0x1a5f0
movb -0x71(%rbp), %cl
movb %cl, (%rax)
testb $0x1, -0x1e(%rbp)
je 0x2a01f
movl -0x3c(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x2a029
movl $0xff, %eax
movl %eax, -0x78(%rbp)
jmp 0x2a029
movl -0x78(%rbp), %eax
movb %al, -0x7a(%rbp)
movq -0x8(%rbp), %rdi
movl $0x7, %esi
callq 0x1a5f0
movb -0x7a(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movl $0x9, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0x8, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0xb, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0xa, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0xd, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0xc, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movb -0x11(%rbp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x79(%rbp)
movq -0x8(%rbp), %rdi
movl $0xf, %esi
callq 0x1a5f0
movb -0x79(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movl $0xe, %esi
callq 0x1a5f0
movb -0x79(%rbp), %cl
movb %cl, (%rax)
jmp 0x2a2b0
movl $0x101, -0x18(%rbp)     # imm = 0x101
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1a540
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x2a2ae
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x2a29b
movq -0x48(%rbp), %rax
movl -0x18(%rbp), %ecx
imulq %rcx, %rax
shlq $0x3, %rax
movq -0x50(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq %rax
movb %al, -0x7d(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x1, %rsi
callq 0x1a5f0
movb -0x7d(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x0, %rsi
callq 0x1a5f0
movb -0x7d(%rbp), %cl
movb %cl, (%rax)
movq -0x58(%rbp), %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movb %al, -0x7c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x3, %rsi
callq 0x1a5f0
movb -0x7c(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x2, %rsi
callq 0x1a5f0
movb -0x7c(%rbp), %cl
movb %cl, (%rax)
movq -0x58(%rbp), %rax
movl $0x5, %ecx
xorl %edx, %edx
divq %rcx
movb %al, -0x7b(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x5, %rsi
callq 0x1a5f0
movb -0x7b(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x4, %rsi
callq 0x1a5f0
movb -0x7b(%rbp), %cl
movb %cl, (%rax)
testb $0x1, -0x11(%rbp)
je 0x2a21c
cmpq $0x0, -0x48(%rbp)
jne 0x2a21c
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x2a24b
testb $0x1, -0x1e(%rbp)
je 0x2a22f
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x2a23d
movl $0xff, %eax
movq %rax, -0x90(%rbp)
jmp 0x2a23d
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movb %al, -0x91(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x7, %rsi
callq 0x1a5f0
movb -0x91(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x6, %rsi
callq 0x1a5f0
movb -0x91(%rbp), %cl
movb %cl, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2a126
jmp 0x2a29d
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2a10e
jmp 0x2a2b0
jmp 0x2a2b2
jmp 0x2a2b4
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)