// File: /workspace/github_cpp_makefile_star2_O2/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 0x13a2d
pushq $0x1
popq %r15
movl %r14d, %ecx
shll %cl, %r15d
movl $0x800, %esi            # imm = 0x800
shll %cl, %esi
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6d8
movl %r14d, %ecx
leaq (,%r15,8), %rax
notb %bpl
movb $-0x1, %dl
xorl %esi, %esi
cmpq $0x100, %rsi            # imm = 0x100
je 0x13ae6
movq %rsi, %rdi
shlq %cl, %rdi
testq %rsi, %rsi
setne %r8b
orb %bpl, %r8b
andb $0x1, %r8b
negb %r8b
shlq $0x3, %rdi
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x13a25
movq (%rbx), %r10
addq %rdi, %r10
movb %sil, 0x1(%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %sil, (%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %dl, 0x3(%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %dl, 0x2(%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %r12b, 0x5(%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %r12b, 0x4(%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %r8b, 0x7(%r9,%r10)
movq (%rbx), %r10
addq %rdi, %r10
movb %r8b, 0x6(%r9,%r10)
addq $0x8, %r9
jmp 0x139c3
incq %rsi
jmp 0x13998
orb %al, %r15b
cmpl $0x10, %r14d
jne 0x13af0
orb %al, %r12b
pushq $0x10
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6d8
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
pushq $0xa
popq %rcx
pushq $0x6e
popq %rsi
cmovnel %ecx, %esi
movq (%rbx), %rcx
movb %dl, 0x3(%rcx)
movq (%rbx), %rcx
movb %sil, 0x4(%rcx)
pushq $0x14
popq %rcx
pushq $0x78
popq %rdx
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)
pushq $0x28
popq %rax
movl $0x8c, %ecx
cmovnel %eax, %ecx
movq (%rbx), %rax
pushq $0x32
popq %rdx
movl $0x96, %r12d
cmovnel %edx, %r12d
movb %cl, 0xc(%rax)
pushq $0xf
popq %rax
pushq $0xe
popq %rcx
pushq $0xd
jmp 0x13b91
movl $0x100, %esi            # imm = 0x100
jmp 0x13bb1
testl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
jne 0x13bc7
pushq $-0x1
popq %rsi
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
pushq $0x10
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6d8
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)
pushq $0xe
popq %rax
pushq $0xf
popq %rcx
pushq $0xc
popq %rdx
movq (%rbx), %rsi
movb %r12b, (%rsi,%rdx)
decb %bpl
movq (%rbx), %rdx
movb %bpl, (%rdx,%rcx)
movq (%rbx), %rcx
movb %bpl, (%rcx,%rax)
pushq $0x2
popq %r15
pushq $0x1
popq %rsi
movl %r15d, 0x18(%rbx)
movl %esi, 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 0xe6d8
pushq $0x1
popq %rsi
movw $0x3, %di
movw $0x5, %r8w
xorl %r9d, %r9d
xorl %ecx, %ecx
cmpq $0x808, %rcx            # imm = 0x808
je 0x13c57
movq (%rbx), %rax
movb %r9b, 0x1(%rax,%rcx)
movq (%rbx), %rax
movb %r9b, (%rax,%rcx)
movl %ecx, %eax
xorl %edx, %edx
divw %di
movq (%rbx), %rdx
movb %al, 0x3(%rdx,%rcx)
movq (%rbx), %rdx
movb %al, 0x2(%rdx,%rcx)
movl %ecx, %eax
xorl %edx, %edx
divw %r8w
movq (%rbx), %rdx
movb %al, 0x5(%rdx,%rcx)
movq (%rbx), %rdx
movb %al, 0x4(%rdx,%rcx)
testb %r15b, %r15b
movl $0xff, %eax
cmovnel %ecx, %eax
testb %bpl, %bpl
cmovnel %r14d, %eax
movq (%rbx), %rdx
movb %al, 0x7(%rdx,%rcx)
movq (%rbx), %rdx
movb %al, 0x6(%rdx,%rcx)
addq $0x8, %rcx
addb $0x4, %r9b
jmp 0x13bea
movl $0x101, %r15d           # imm = 0x101
jmp 0x13bb1