// File: 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
movq %rsp, %rbp
subq $0x90, %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 0x2a333
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 0x2a350
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 0x2a48a
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 $0x2, %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 0x2a485
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x2a472
movq -0x28(%rbp), %rax
movl -0x18(%rbp), %ecx
imulq %rcx, %rax
shlq $0x2, %rax
movq -0x30(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movb %al, -0x5c(%rbp)
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 $0x1, %rsi
callq 0x1a5f0
movb $-0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x2, %rsi
callq 0x1a5f0
movb $0x0, (%rax)
xorl %eax, %eax
testb $0x1, -0x11(%rbp)
movb %al, -0x5b(%rbp)
je 0x2a438
cmpq $0x0, -0x30(%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 $0x3, %rsi
callq 0x1a5f0
movb -0x5d(%rbp), %cl
movb %cl, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x2a3af
jmp 0x2a474
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2a397
jmp 0x2a707
testb $0x1, -0x1d(%rbp)
je 0x2a5a8
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 $0x2, %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1a540
movl -0x3c(%rbp), %eax
movb %al, -0x60(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1a5f0
movb -0x60(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x5f(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x1a5f0
movb -0x5f(%rbp), %cl
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, -0x5e(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x1a5f0
movb -0x5e(%rbp), %cl
movb %cl, (%rax)
testb $0x1, -0x1e(%rbp)
je 0x2a527
movl -0x3c(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x2a531
movl $0xff, %eax
movl %eax, -0x64(%rbp)
jmp 0x2a531
movl -0x64(%rbp), %eax
movb %al, -0x66(%rbp)
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x1a5f0
movb -0x66(%rbp), %cl
movb %cl, (%rax)
movq -0x8(%rbp), %rdi
movl $0x4, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0x5, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0x6, %esi
callq 0x1a5f0
movb $0x0, (%rax)
movb -0x11(%rbp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x65(%rbp)
movq -0x8(%rbp), %rdi
movl $0x7, %esi
callq 0x1a5f0
movb -0x65(%rbp), %cl
movb %cl, (%rax)
jmp 0x2a705
movl $0x101, -0x18(%rbp)     # imm = 0x101
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
shll $0x2, %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 0x2a703
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
jae 0x2a6f0
movq -0x48(%rbp), %rax
movl -0x18(%rbp), %ecx
imulq %rcx, %rax
shlq $0x2, %rax
movq -0x50(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq %rax
movb %al, -0x69(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x0, %rsi
callq 0x1a5f0
movb -0x69(%rbp), %cl
movb %cl, (%rax)
movq -0x58(%rbp), %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movb %al, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x1, %rsi
callq 0x1a5f0
movb -0x68(%rbp), %cl
movb %cl, (%rax)
movq -0x58(%rbp), %rax
movl $0x5, %ecx
xorl %edx, %edx
divq %rcx
movb %al, -0x67(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x2, %rsi
callq 0x1a5f0
movb -0x67(%rbp), %cl
movb %cl, (%rax)
testb $0x1, -0x11(%rbp)
je 0x2a699
cmpq $0x0, -0x50(%rbp)
jne 0x2a699
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x2a6bc
testb $0x1, -0x1e(%rbp)
je 0x2a6a9
movq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x2a6b4
movl $0xff, %eax
movq %rax, -0x80(%rbp)
jmp 0x2a6b4
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movb %al, -0x81(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x3, %rsi
callq 0x1a5f0
movb -0x81(%rbp), %cl
movb %cl, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2a5e8
jmp 0x2a6f2
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2a5d0
jmp 0x2a705
jmp 0x2a707
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 $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)