// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl %edx, %r14d
movq %rdi, %rbx
movl %esi, 0x20(%rdi)
movl %edx, 0x24(%rdi)
testl %esi, %esi
sete %r12b
cmpl $0x4, %esi
sete %al
cmpl $0x6, %esi
sete %r15b
cmpl $0x3, %esi
jne 0x16ccb
movl $0x1, %r15d
movl %r14d, %ecx
shll %cl, %r15d
movl $0x800, %esi            # imm = 0x800
shll %cl, %esi
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
movl %r14d, %ecx
notb %bpl
movb $-0x1, %al
xorl %edx, %edx
movq %rdx, %rsi
shlq %cl, %rsi
testq %rdx, %rdx
setne %dil
orb %bpl, %dil
andb $0x1, %dil
negb %dil
shlq $0x3, %rsi
xorl %r8d, %r8d
movq (%rbx), %r9
addq %rsi, %r9
movb %dl, 0x1(%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %dl, (%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %al, 0x3(%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %al, 0x2(%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %r12b, 0x5(%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %r12b, 0x4(%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %dil, 0x7(%r9,%r8,8)
movq (%rbx), %r9
addq %rsi, %r9
movb %dil, 0x6(%r9,%r8,8)
incq %r8
cmpq %r8, %r15
jne 0x16c52
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0x16c34
movl $0x100, %eax            # imm = 0x100
jmp 0x16e68
orb %al, %r15b
cmpl $0x10, %r14d
jne 0x16d99
orb %al, %r12b
movl $0x10, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
movq (%rbx), %rax
movb $0xa, %cl
movb %cl, (%rax)
movq (%rbx), %rax
movb $0x14, %dl
movb %dl, 0x1(%rax)
movq (%rbx), %rax
movb %cl, 0x2(%rax)
decb %r15b
movl %r15d, %eax
orb $-0x80, %al
orb %dl, %r15b
testb %r12b, %r12b
movl $0xa, %ecx
movl $0x6e, %esi
cmovnel %ecx, %esi
movq (%rbx), %rcx
movb %dl, 0x3(%rcx)
movq (%rbx), %rcx
movb %sil, 0x4(%rcx)
movl $0x14, %ecx
movl $0x78, %edx
cmovnel %ecx, %edx
movq (%rbx), %rcx
movb %dl, 0x5(%rcx)
movq (%rbx), %rcx
movb %al, 0x6(%rcx)
movq (%rbx), %rax
movb %r15b, 0x7(%rax)
movq (%rbx), %rax
movb $0x28, %cl
movb %cl, 0x8(%rax)
movq (%rbx), %rax
movb $0x32, %dl
movb %dl, 0x9(%rax)
movq (%rbx), %rax
movb %cl, 0xa(%rax)
movq (%rbx), %rax
movb %dl, 0xb(%rax)
movl $0x28, %eax
movl $0x8c, %ecx
cmovnel %eax, %ecx
movq (%rbx), %rax
movl $0x32, %edx
movl $0x96, %r12d
cmovnel %edx, %r12d
movb %cl, 0xc(%rax)
movl $0xf, %eax
movl $0xe, %ecx
movl $0xd, %edx
jmp 0x16e45
testl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
jne 0x16e7e
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %r14d, %ecx
shll %cl, %esi
notl %esi
movl $0xff, %r13d
xorl %r12d, %r12d
movl $0xff, %eax
xorl %edx, %edx
divl %esi
movl %eax, %r14d
movl $0x10, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
movq (%rbx), %rax
movb %r14b, (%rax)
movq (%rbx), %rax
movb %r14b, 0x1(%rax)
movq (%rbx), %rax
movb %r14b, 0x2(%rax)
movq (%rbx), %rax
movb %r14b, 0x3(%rax)
movq (%rbx), %rax
movb %r14b, 0x4(%rax)
movq (%rbx), %rax
movb %r14b, 0x5(%rax)
testb %r15b, %r15b
cmovnel %r14d, %r13d
movq (%rbx), %rax
movb %r13b, 0x6(%rax)
movq (%rbx), %rax
movb %r13b, 0x7(%rax)
movq (%rbx), %rax
movb %r12b, 0x9(%rax)
movq (%rbx), %rax
movb %r12b, 0x8(%rax)
movq (%rbx), %rax
movb %r12b, 0xb(%rax)
movq (%rbx), %rax
movb %r12b, 0xa(%rax)
movq (%rbx), %rax
movb %r12b, 0xd(%rax)
movl $0xe, %eax
movl $0xf, %ecx
movl $0xc, %edx
movq (%rbx), %rsi
movb %r12b, (%rsi,%rdx)
decb %bpl
movq (%rbx), %rdx
movb %bpl, (%rdx,%rcx)
movq (%rbx), %rcx
movb %bpl, (%rcx,%rax)
movl $0x2, %r15d
movl $0x1, %eax
movl %r15d, 0x18(%rbx)
movl %eax, 0x1c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movl $0x808, %esi            # imm = 0x808
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
xorl %r8d, %r8d
xorl %ecx, %ecx
movq (%rbx), %rax
movb %r8b, 0x1(%rax,%rcx)
movq (%rbx), %rax
movb %r8b, (%rax,%rcx)
movq %rcx, %rax
mulq %rsi
shrl %edx
movq (%rbx), %rax
movb %dl, 0x3(%rax,%rcx)
movq (%rbx), %rax
movb %dl, 0x2(%rax,%rcx)
movq %rcx, %rax
mulq %rdi
shrl $0x2, %edx
movq (%rbx), %rax
movb %dl, 0x5(%rax,%rcx)
testb %r15b, %r15b
movl $0xff, %eax
cmovnel %ecx, %eax
movq (%rbx), %r9
testb %bpl, %bpl
cmovnel %r14d, %eax
movb %dl, 0x4(%r9,%rcx)
movq (%rbx), %rdx
movb %al, 0x7(%rdx,%rcx)
movq (%rbx), %rdx
movb %al, 0x6(%rdx,%rcx)
addq $0x8, %rcx
addb $0x4, %r8b
cmpq $0x808, %rcx            # imm = 0x808
jne 0x16ea9
movl $0x101, %r15d           # imm = 0x101
jmp 0x16e63