// File: /workspace/github_cpp_makefile_star2_O2/lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: testBkgdChunk()
void testBkgdChunk() {
  std::cout << "testBkgdChunk" << std::endl;
  // color param order is: generated, raw, png ( == bKGD)
  // here generated means: what color values the pixels will get, so what auto_convert will make it choose
  testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGBA, 8, LCT_RGBA, 8, LCT_RGBA, 8, true);
  testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGBA, 8, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGB, 8, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(255, 255, 255, 1, 1, 1, LCT_GREY, 1, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(255, 255, 255, 3, 3, 3, LCT_GREY, 2, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(255, 255, 255, 15, 15, 15, LCT_GREY, 4, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(255, 255, 255, 255, 255, 255, LCT_GREY, 8, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(255, 255, 255, 65535, 65535, 65535, LCT_GREY, 16, LCT_RGB, 16, LCT_RGB, 8, true);
  testBkgdChunk(123, 0, 0, 123, 0, 0, LCT_GREY, 1, LCT_RGB, 8, LCT_RGB, 8, true);
  testBkgdChunk(170, 170, 170, 2, 2, 2, LCT_GREY, 1, LCT_RGB, 8, LCT_RGB, 8, true); // 170 = value 2 in 2-bit

  // without auto_convert. Note that it will still convert if different colortype is given for raw and png, it's just
  // not automatic in that case.
  testBkgdChunk(255, 0, 0, 255, 0, 0, LCT_RGBA, 8, LCT_RGBA, 8, LCT_RGBA, 8, false);
  testBkgdChunk(60000, 0, 0, 60000, 0, 0, LCT_RGBA, 8, LCT_RGBA, 8, LCT_RGBA, 16, false);
  testBkgdChunk(128, 128, 128, 128, 128, 128, LCT_GREY, 8, LCT_RGBA, 8, LCT_GREY, 8, false);
 {
    LodePNGColorMode pal;
    lodepng_color_mode_init(&pal);
    for(int i = 0; i < 200; i++) lodepng_palette_add(&pal, i, i / 2, 0, 255);
    pal.colortype = LCT_PALETTE;
    pal.bitdepth = 8;
    unsigned w = 200;
    unsigned h = 200;
    std::vector<unsigned char> img(w * h);
    for(unsigned y = 0; y < h; y++)
    for(unsigned x = 0; x < w; x++) {
      img[y * w + x] = x;
    }

    testBkgdChunk(100, 0, 0, 100, 100, 100, img, w, h, pal, pal, true, false);
    testBkgdChunk(100, 0, 0, 100, 100, 100, img, w, h, pal, pal, false, false);
    testBkgdChunk(250, 0, 0, 250, 250, 250, img, w, h, pal, pal, true, true);

    std::vector<unsigned char> fourcolor(w * h);
    for(unsigned y = 0; y < h; y++)
    for(unsigned x = 0; x < w; x++) {
      fourcolor[y * w + x] = x & 3;
    }
    // palette index 4 expected for output bKGD: auto_convert should turn the 200-sized
    // palette in one of size 5, 4 values for the fourcolor image above, and then a 5th for
    // the bkgd index. The other two 4's actually shouldn't matter, it's not defined what
    // they should be though currently lodepng sets them also to the palette index...
    testBkgdChunk(100, 0, 0, 4, 4, 4, fourcolor, w, h, pal, pal, true, false);


    std::vector<unsigned char> mini(4);
    mini[0] = 1; mini[1] = 2; mini[2] = 3; mini[3] = 4;
    // here we expect RGB color from the output image, since the image is tiny so it chooses to not add PLTE
    testBkgdChunk(100, 0, 0, 100, 50, 0, mini, 2, 2, pal, pal, true, false);

    lodepng_color_mode_cleanup(&pal);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq 0x62338(%rip), %rdi     # 0xa2fd8
leaq 0x226e6(%rip), %rsi     # 0x6338d
callq 0x21f0
movq %rax, %rdi
callq 0x2100
subq $0x40, %rsp
pushq $0x1
popq %r14
movl %r14d, 0x30(%rsp)
pushq $0x8
popq %r15
movl %r15d, 0x28(%rsp)
pushq $0x6
popq %r13
movl %r13d, 0x20(%rsp)
movl %r15d, 0x18(%rsp)
movl %r13d, 0x10(%rsp)
movl %r15d, 0x8(%rsp)
movl %r13d, (%rsp)
andl $0x0, 0x38(%rsp)
movl $0xff, %ebp
xorl %r12d, %r12d
movl $0xff, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xff, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4090f
addq $0x40, %rsp
pushq $0x2
popq %rbx
movl $0xff, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xff, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %r15
pushq %r13
callq 0x4090f
addq $0x40, %rsp
movl $0xff, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xff, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
callq 0x4090f
addq $0x40, %rsp
movl $0xff, %edi
movl $0xff, %esi
movl $0xff, %edx
movl %r14d, %ecx
movl %r14d, %r8d
movl %r14d, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %r14
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
pushq $0x3
popq %rcx
movl $0xff, %edi
movl $0xff, %esi
movl $0xff, %edx
movl %ecx, %r8d
movl %ecx, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %rbx
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
pushq $0xf
popq %rcx
movl $0xff, %edi
movl $0xff, %esi
movl $0xff, %edx
movl %ecx, %r8d
movl %ecx, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq $0x4
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
movl $0xff, %edi
movl $0xff, %esi
movl $0xff, %edx
movl $0xff, %ecx
movl $0xff, %r8d
movl $0xff, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %r15
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
pushq $0x10
popq %rax
movl $0xff, %edi
movl $0xff, %esi
movl $0xff, %edx
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0xffff, %r8d           # imm = 0xFFFF
movl $0xffff, %r9d           # imm = 0xFFFF
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %rax
pushq %rbx
pushq %rax
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
pushq $0x7b
popq %rcx
movl %ecx, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %r14
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
movl $0xaa, %edi
movl $0xaa, %esi
movl $0xaa, %edx
movl %ebx, %ecx
movl %ebx, %r8d
movl %ebx, %r9d
pushq $0x0
pushq %r14
pushq %r15
pushq %rbx
pushq %r15
pushq %rbx
pushq %r14
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
movl $0xff, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xff, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
pushq %r15
pushq %r13
pushq %r15
pushq %r13
pushq %r15
pushq %r13
callq 0x4090f
addq $0x40, %rsp
movl $0xea60, %edi           # imm = 0xEA60
xorl %esi, %esi
xorl %edx, %edx
movl $0xea60, %ecx           # imm = 0xEA60
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
pushq $0x10
popq %rax
pushq %rax
pushq %r13
pushq %r15
pushq %r13
pushq %r15
pushq %r13
callq 0x4090f
addq $0x40, %rsp
movl $0x80, %edi
movl $0x80, %esi
movl $0x80, %edx
movl $0x80, %ecx
movl $0x80, %r8d
movl $0x80, %r9d
pushq $0x0
pushq $0x0
pushq %r15
pushq $0x0
pushq %r15
pushq %r13
pushq %r15
pushq $0x0
callq 0x4090f
addq $0x40, %rsp
leaq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x4970
cmpl $0xc8, %r12d
je 0x40f83
movl %r12d, %edx
shrl %edx
movl %r12d, %esi
andl %ebp, %esi
andl %ebp, %edx
movq %r15, %rdi
xorl %ecx, %ecx
movl $0xff, %r8d
callq 0x4a2f
incl %r12d
jmp 0x40f59
movabsq $0x800000003, %rax      # imm = 0x800000003
movq %rax, 0x50(%rsp)
leaq 0x20(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x38(%rsp), %r12
leaq 0x8(%rsp), %rcx
movl $0x9c40, %esi           # imm = 0x9C40
movq %r12, %rdi
callq 0x5ab3a
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0xc8, %rcx
je 0x40fe4
xorl %edx, %edx
cmpq $0xc8, %rdx
je 0x40fd9
movq 0x38(%rsp), %rsi
addq %rax, %rsi
movb %dl, (%rdx,%rsi)
incq %rdx
jmp 0x40fc0
incq %rcx
addq $0xc8, %rax
jmp 0x40fb5
subq $0x40, %rsp
movq %r15, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movl $0xc8, %ebp
movl %ebp, 0x10(%rsp)
movl %ebp, 0x8(%rsp)
movq %r12, (%rsp)
andl $0x0, 0x30(%rsp)
movl $0x1, 0x28(%rsp)
pushq $0x64
popq %rcx
movl %ecx, %edi
xorl %esi, %esi
xorl %edx, %edx
movl %ecx, %r8d
movl %ecx, %r9d
callq 0x3efb9
addq $0x40, %rsp
subq $0x40, %rsp
movq %r15, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movl %ebp, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
movl %ebp, 0x8(%rsp)
andl $0x0, 0x28(%rsp)
movq %r12, (%rsp)
pushq $0x64
popq %rcx
movl %ecx, %edi
xorl %esi, %esi
xorl %edx, %edx
movl %ecx, %r8d
movl %ecx, %r9d
callq 0x3efb9
addq $0x40, %rsp
subq $0x8, %rsp
movl $0xc8, %eax
movl $0xfa, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xfa, %ecx
movl $0xfa, %r8d
movl $0xfa, %r9d
pushq %r14
pushq %r14
pushq %r15
pushq %r15
pushq %rax
pushq %rax
pushq %r12
callq 0x3efb9
addq $0x40, %rsp
leaq 0x8(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x20(%rsp), %r14
leaq 0x6(%rsp), %rcx
movl $0x9c40, %esi           # imm = 0x9C40
movq %r14, %rdi
callq 0x5ab3a
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0xc8, %rcx
je 0x410f5
xorl %edx, %edx
cmpq $0xc8, %rdx
je 0x410ea
movl %edx, %esi
andb $0x3, %sil
movq 0x20(%rsp), %rdi
addq %rax, %rdi
movb %sil, (%rdx,%rdi)
incq %rdx
jmp 0x410ca
incq %rcx
addq $0xc8, %rax
jmp 0x410bf
subq $0x40, %rsp
movq %r15, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movl $0xc8, %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x8(%rsp)
movq %r14, (%rsp)
andl $0x0, 0x30(%rsp)
movl $0x1, 0x28(%rsp)
pushq $0x64
popq %rdi
pushq $0x4
popq %rcx
xorl %esi, %esi
xorl %edx, %edx
movl %ecx, %r8d
movl %ecx, %r9d
callq 0x3efb9
addq $0x40, %rsp
leaq 0x6(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x8(%rsp), %r14
pushq $0x4
popq %rsi
leaq 0x7(%rsp), %rcx
movq %r14, %rdi
callq 0x5ab3a
movq 0x8(%rsp), %rax
movb $0x1, (%rax)
movq 0x8(%rsp), %rax
movb $0x2, 0x1(%rax)
movq 0x8(%rsp), %rax
movb $0x3, 0x2(%rax)
movq 0x8(%rsp), %rax
movb $0x4, 0x3(%rax)
subq $0x40, %rsp
movq %r15, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movl %ebx, 0x10(%rsp)
movl %ebx, 0x8(%rsp)
movq %r14, (%rsp)
andl $0x0, 0x30(%rsp)
movl $0x1, 0x28(%rsp)
pushq $0x64
popq %rcx
pushq $0x32
popq %r8
movl %ecx, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0x3efb9
addq $0x40, %rsp
leaq 0x50(%rsp), %rdi
callq 0x4989
leaq 0x8(%rsp), %rdi
callq 0xea7c
leaq 0x20(%rsp), %rdi
callq 0xea7c
leaq 0x38(%rsp), %rdi
callq 0xea7c
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x41217
jmp 0x411f7
jmp 0x411f7
movq %rax, %rbx
jmp 0x4120b
jmp 0x41217
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xea7c
leaq 0x20(%rsp), %rdi
callq 0xea7c
jmp 0x4121a
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xea7c
movq %rbx, %rdi
callq 0x2380
movq %rax, %rdi
callq 0xe6cc