// File: /workspace/github_cpp_makefile_star2_O2/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 0x13d23
cmpl $0x4, %esi
je 0x13d23
cmpl $0x3, %esi
jne 0x13d9d
pushq $0x1
popq %r15
movl %r14d, %ecx
shll %cl, %r15d
movl $0x400, %esi            # imm = 0x400
shll %cl, %esi
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6d8
movl %r14d, %ecx
notb %bpl
cmpq $0x100, %r12            # imm = 0x100
je 0x13e21
movq %r12, %rax
shlq %cl, %rax
shlq $0x2, %rax
xorl %edx, %edx
cmpq %rdx, %r15
je 0x13d1e
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
jmp 0x13cd9
incq %r12
jmp 0x13cc0
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 $0x8
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6d8
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)
pushq $0x2
popq %r15
pushq $0x1
popq %rdi
jmp 0x13e2e
xorl %r14d, %r14d
movl $0x404, %esi            # imm = 0x404
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6d8
pushq $0x1
popq %rdi
movw $0x3, %r8w
movw $0x5, %r9w
xorl %r10d, %r10d
xorl %ecx, %ecx
cmpq $0x404, %rcx            # imm = 0x404
je 0x13e28
movl %ecx, %eax
xorl %edx, %edx
divw %r8w
movl %eax, %esi
movl %ecx, %eax
xorl %edx, %edx
divw %r9w
cmpl $0x4, %r15d
movq (%rbx), %rdx
movb %r10b, (%rdx,%rcx)
movq (%rbx), %rdx
movb %sil, 0x1(%rdx,%rcx)
movq (%rbx), %rdx
movl $0xff, %esi
cmovel %ecx, %esi
testb %bpl, %bpl
movl %esi, %r11d
cmovnel %r14d, %r11d
movb %al, 0x2(%rdx,%rcx)
testq %rcx, %rcx
cmovnel %esi, %r11d
movq (%rbx), %rax
movb %r11b, 0x3(%rax,%rcx)
addq $0x4, %rcx
addb $0x2, %r10b
jmp 0x13dc1
movl $0x100, %edi            # imm = 0x100
jmp 0x13e2e
movl $0x101, %r15d           # imm = 0x101
movl %r15d, 0x18(%rbx)
movl %edi, 0x1c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq