// File: /workspace/github_cpp_makefile_star2_O1/lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: generateTestImageRequiringColorType8(Image&, LodePNGColorType, unsigned int, bool)
void generateTestImageRequiringColorType8(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 * 4);
    for(size_t y = 0; y < h; y++) {
      for(size_t x = 0; x < w; x++) {
        size_t i = y * w * 4 + x * 4;
        image.data[i + 0] = x;
        image.data[i + 1] = 255;
        image.data[i + 2] = 0;
        image.data[i + 3] = (key && x == 0) ? 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 * 4);
    image.data[0] = v;
    image.data[1] = v;
    image.data[2] = v;
    image.data[3] = alpha ? v : 255;

    image.data[4] = 0;
    image.data[5] = 0;
    image.data[6] = 0;
    image.data[7] = 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 * 4);
    for(size_t y = 0; y < h; y++) {
      for(size_t x = 0; x < w; x++) {
        size_t i = y * w * 4 + x * 4;
        image.data[i + 0] = i / 2;
        image.data[i + 1] = i / 3;
        image.data[i + 2] = i / 5;
        image.data[i + 3] = (key && x == 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)
movl %esi, %r15d
andl $-0x3, %r15d
testl %esi, %esi
je 0x16fe7
cmpl $0x4, %esi
je 0x16fe7
cmpl $0x3, %esi
jne 0x17064
movl $0x1, %r15d
movl %r14d, %ecx
shll %cl, %r15d
movl $0x400, %esi            # imm = 0x400
shll %cl, %esi
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
movl %r14d, %ecx
notb %bpl
movq %r12, %rax
shlq %cl, %rax
shlq $0x2, %rax
xorl %edx, %edx
movq (%rbx), %rsi
addq %rax, %rsi
movb %dl, (%rsi,%rdx,4)
movq (%rbx), %rsi
addq %rax, %rsi
movb $-0x1, 0x1(%rsi,%rdx,4)
movq (%rbx), %rsi
addq %rax, %rsi
movb $0x0, 0x2(%rsi,%rdx,4)
testq %rdx, %rdx
setne %sil
orb %bpl, %sil
andb $0x1, %sil
negb %sil
movq (%rbx), %rdi
addq %rax, %rdi
movb %sil, 0x3(%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %r15
jne 0x16f8e
incq %r12
cmpq $0x100, %r12            # imm = 0x100
jne 0x16f82
movl $0x100, %eax            # imm = 0x100
jmp 0x170f7
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 $0x8, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
cmpl $0x4, %r15d
movq (%rbx), %rax
movb %r14b, (%rax)
movq (%rbx), %rax
movb %r14b, 0x1(%rax)
movq (%rbx), %rax
movb %r14b, 0x2(%rax)
cmovel %r14d, %r13d
movq (%rbx), %rax
movb %r13b, 0x3(%rax)
movq (%rbx), %rax
movb %r12b, 0x4(%rax)
movq (%rbx), %rax
movb %r12b, 0x5(%rax)
movq (%rbx), %rax
movb %r12b, 0x6(%rax)
decb %bpl
movq (%rbx), %rax
movb %bpl, 0x7(%rax)
movl $0x2, %r15d
jmp 0x170f2
xorl %r14d, %r14d
movl $0x404, %esi            # imm = 0x404
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10b40
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
xorl %r9d, %r9d
xorl %ecx, %ecx
movq %rcx, %rax
mulq %rdi
movq %rdx, %rsi
shrl %esi
movq %rcx, %rax
mulq %r8
shrl $0x2, %edx
cmpl $0x4, %r15d
movq (%rbx), %rax
movb %r9b, (%rax,%rcx)
movq (%rbx), %rax
movb %sil, 0x1(%rax,%rcx)
movq (%rbx), %rax
movb %dl, 0x2(%rax,%rcx)
movl $0xff, %eax
cmovel %ecx, %eax
testb %bpl, %bpl
movl %eax, %edx
cmovnel %r14d, %edx
testq %rcx, %rcx
cmovnel %eax, %edx
movq (%rbx), %rax
movb %dl, 0x3(%rax,%rcx)
addq $0x4, %rcx
addb $0x2, %r9b
cmpq $0x404, %rcx            # imm = 0x404
jne 0x1708f
movl $0x101, %r15d           # imm = 0x101
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