// File: lvandeve[P]lodepng/lodepng_unittest.cpp
// Function: testColorConvert2()
void testColorConvert2() {
  std::cout << "testColorConvert2" << std::endl;
  struct Combo {
    LodePNGColorType colortype;
    unsigned bitdepth;
  };

  Combo combos[15] = { { LCT_GREY, 1}, { LCT_GREY, 2}, { LCT_GREY, 4}, { LCT_GREY, 8}, { LCT_GREY, 16}, { LCT_RGB, 8}, { LCT_RGB, 16}, { LCT_PALETTE, 1}, { LCT_PALETTE, 2}, { LCT_PALETTE, 4}, { LCT_PALETTE, 8}, { LCT_GREY_ALPHA, 8}, { LCT_GREY_ALPHA, 16}, { LCT_RGBA, 8}, { LCT_RGBA, 16},
  };

  lodepng::State state;
  LodePNGColorMode& mode_in = state.info_png.color;
  LodePNGColorMode& mode_out = state.info_raw;
  LodePNGColorMode mode_8;
  lodepng_color_mode_init(&mode_8);

  for(size_t i = 0; i < 256; i++) {
    size_t j = i == 1 ? 255 : i;
    lodepng_palette_add(&mode_in, j, j, j, 255);
    lodepng_palette_add(&mode_out, j, j, j, 255);
  }

  for(size_t i = 0; i < 15; i++) {
    mode_in.colortype = combos[i].colortype;
    mode_in.bitdepth = combos[i].bitdepth;

    for(size_t j = 0; j < 15; j++) {
      mode_out.colortype = combos[j].colortype;
      mode_out.bitdepth = combos[j].bitdepth;

      unsigned char eight[36] = {
          0,0,0,255, 255,255,255,255,
          0,0,0,255, 255,255,255,255,
          255,255,255,255, 0,0,0,255,
          255,255,255,255, 255,255,255,255,
          0,0,0,255 }; //input in RGBA8
      unsigned char in[72]; //custom input color type
      unsigned char out[72]; //custom output color type
      unsigned char eight2[36]; //back in RGBA8 after all conversions to check correctness
      unsigned error = 0;

      error |= lodepng_convert(in, eight, &mode_in, &mode_8, 3, 3);
      if(!error) error |= lodepng_convert(out, in, &mode_out, &mode_in, 3, 3); //Test input to output type
      if(!error) error |= lodepng_convert(eight2, out, &mode_8, &mode_out, 3, 3);

      if(!error) {
        for(size_t k = 0; k < 36; k++) {
          if(eight[k] != eight2[k]) {
            error = 99999;
            break;
          }
        }
      }

      if(error) {
        std::cout << "Error " << error << " i: " << i << " j: " << j
          << " colortype i: " << combos[i].colortype
          << " bitdepth i: " << combos[i].bitdepth
          << " colortype j: " << combos[j].colortype
          << " bitdepth j: " << combos[j].bitdepth
          << std::endl;
        if(error != 99999) ASSERT_NO_PNG_ERROR(error);
        else fail();
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x600, %rsp            # imm = 0x600
movq 0xc2486(%rip), %rdi     # 0xf7fd8
leaq 0x7dca7(%rip), %rsi     # 0xb3800
callq 0x3230
movq %rax, %rdi
movq 0xc2458(%rip), %rsi     # 0xf7fc0
callq 0x3280
movabsq $0x1000000006, %rax     # imm = 0x1000000006
movq %rax, -0x10(%rbp)
movaps 0x7d41e(%rip), %xmm0    # 0xb2fa0
movaps %xmm0, -0x20(%rbp)
movaps 0x7d403(%rip), %xmm0    # 0xb2f90
movaps %xmm0, -0x30(%rbp)
movaps 0x7d3e8(%rip), %xmm0    # 0xb2f80
movaps %xmm0, -0x40(%rbp)
movaps 0x7d3cd(%rip), %xmm0    # 0xb2f70
movaps %xmm0, -0x50(%rbp)
movaps 0x7d3b2(%rip), %xmm0    # 0xb2f60
movaps %xmm0, -0x60(%rbp)
movaps 0x7d397(%rip), %xmm0    # 0xb2f50
movaps %xmm0, -0x70(%rbp)
movaps 0x7d37c(%rip), %xmm0    # 0xb2f40
movaps %xmm0, -0x80(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x11ad0
leaq -0x220(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq -0x258(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x56a0
jmp 0x35bfe
movq $0x0, -0x350(%rbp)
cmpq $0x100, -0x350(%rbp) # imm = 0x100
jae 0x35cbc
cmpq $0x1, -0x350(%rbp)
jne 0x35c32
movl $0xff, %eax
movq %rax, -0x550(%rbp)
jmp 0x35c40
movq -0x350(%rbp), %rax
movq %rax, -0x550(%rbp)
movq -0x550(%rbp), %rax
movq %rax, -0x358(%rbp)
movq -0x308(%rbp), %rdi
movzbl -0x358(%rbp), %ecx
movl $0xff, %r8d
movl %ecx, %esi
movl %ecx, %edx
callq 0x58b0
jmp 0x35c6d
movq -0x310(%rbp), %rdi
movzbl -0x358(%rbp), %ecx
movl $0xff, %r8d
movl %ecx, %esi
movl %ecx, %edx
callq 0x58b0
jmp 0x35c8c
jmp 0x35c8e
movq -0x350(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x350(%rbp)
jmp 0x35c09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x36471
movq $0x0, -0x360(%rbp)
cmpq $0xf, -0x360(%rbp)
jae 0x3645c
movq -0x360(%rbp), %rax
movl -0x80(%rbp,%rax,8), %ecx
movq -0x308(%rbp), %rax
movl %ecx, (%rax)
movq -0x360(%rbp), %rax
movl -0x7c(%rbp,%rax,8), %ecx
movq -0x308(%rbp), %rax
movl %ecx, 0x4(%rax)
movq $0x0, -0x368(%rbp)
cmpq $0xf, -0x368(%rbp)
jae 0x36443
movq -0x368(%rbp), %rax
movl -0x80(%rbp,%rax,8), %ecx
movq -0x310(%rbp), %rax
movl %ecx, (%rax)
movq -0x368(%rbp), %rax
movl -0x7c(%rbp,%rax,8), %ecx
movq -0x310(%rbp), %rax
movl %ecx, 0x4(%rax)
movaps 0x7d289(%rip), %xmm0    # 0xb2fd0
movaps %xmm0, -0x380(%rbp)
movaps 0x7d26b(%rip), %xmm0    # 0xb2fc0
movaps %xmm0, -0x390(%rbp)
movl $0xff000000, -0x370(%rbp) # imm = 0xFF000000
movl $0x0, -0x464(%rbp)
movq -0x308(%rbp), %rdx
leaq -0x3e0(%rbp), %rdi
leaq -0x390(%rbp), %rsi
leaq -0x338(%rbp), %rcx
movl $0x3, %r9d
movl %r9d, %r8d
callq 0x6d60
movl %eax, -0x554(%rbp)
jmp 0x35da2
movl -0x554(%rbp), %eax
orl -0x464(%rbp), %eax
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
jne 0x35e01
movq -0x310(%rbp), %rdx
movq -0x308(%rbp), %rcx
leaq -0x430(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
movl $0x3, %r9d
movl %r9d, %r8d
callq 0x6d60
movl %eax, -0x558(%rbp)
jmp 0x35def
movl -0x558(%rbp), %eax
orl -0x464(%rbp), %eax
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
jne 0x35e4e
movq -0x310(%rbp), %rcx
leaq -0x460(%rbp), %rdi
leaq -0x430(%rbp), %rsi
leaq -0x338(%rbp), %rdx
movl $0x3, %r9d
movl %r9d, %r8d
callq 0x6d60
movl %eax, -0x55c(%rbp)
jmp 0x35e3c
movl -0x55c(%rbp), %eax
orl -0x464(%rbp), %eax
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
jne 0x35eb2
movq $0x0, -0x470(%rbp)
cmpq $0x24, -0x470(%rbp)
jae 0x35eb0
movq -0x470(%rbp), %rax
movzbl -0x390(%rbp,%rax), %eax
movq -0x470(%rbp), %rcx
movzbl -0x460(%rbp,%rcx), %ecx
cmpl %ecx, %eax
je 0x35e9a
movl $0x1869f, -0x464(%rbp)  # imm = 0x1869F
jmp 0x35eb0
jmp 0x35e9c
movq -0x470(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x470(%rbp)
jmp 0x35e62
jmp 0x35eb2
cmpl $0x0, -0x464(%rbp)
je 0x3642a
movq 0xc2112(%rip), %rdi     # 0xf7fd8
leaq 0x7d945(%rip), %rsi     # 0xb3812
callq 0x3230
movq %rax, -0x568(%rbp)
jmp 0x35edb
movq -0x568(%rbp), %rdi
movl -0x464(%rbp), %esi
callq 0x3310
movq %rax, -0x570(%rbp)
jmp 0x35ef6
movq -0x570(%rbp), %rdi
leaq 0x7d91f(%rip), %rsi     # 0xb3823
callq 0x3230
movq %rax, -0x578(%rbp)
jmp 0x35f12
movq -0x578(%rbp), %rdi
movq -0x360(%rbp), %rsi
callq 0x3090
movq %rax, -0x580(%rbp)
jmp 0x35f2e
movq -0x580(%rbp), %rdi
leaq 0x7d904(%rip), %rsi     # 0xb3840
callq 0x3230
movq %rax, -0x588(%rbp)
jmp 0x35f4a
movq -0x588(%rbp), %rdi
movq -0x368(%rbp), %rsi
callq 0x3090
movq %rax, -0x590(%rbp)
jmp 0x35f66
movq -0x590(%rbp), %rdi
leaq 0x7d8a5(%rip), %rsi     # 0xb3819
callq 0x3230
movq %rax, -0x598(%rbp)
jmp 0x35f82
movq -0x598(%rbp), %rdi
movq -0x360(%rbp), %rax
movl -0x80(%rbp,%rax,8), %esi
callq 0x3420
movq %rax, -0x5a0(%rbp)
jmp 0x35fa2
movq -0x5a0(%rbp), %rdi
leaq 0x7d878(%rip), %rsi     # 0xb3828
callq 0x3230
movq %rax, -0x5a8(%rbp)
jmp 0x35fbe
movq -0x5a8(%rbp), %rdi
movq -0x360(%rbp), %rax
movl -0x7c(%rbp,%rax,8), %esi
callq 0x3310
movq %rax, -0x5b0(%rbp)
jmp 0x35fde
movq -0x5b0(%rbp), %rdi
leaq 0x7d84a(%rip), %rsi     # 0xb3836
callq 0x3230
movq %rax, -0x5b8(%rbp)
jmp 0x35ffa
movq -0x5b8(%rbp), %rdi
movq -0x368(%rbp), %rax
movl -0x80(%rbp,%rax,8), %esi
callq 0x3420
movq %rax, -0x5c0(%rbp)
jmp 0x3601a
movq -0x5c0(%rbp), %rdi
leaq 0x7d81d(%rip), %rsi     # 0xb3845
callq 0x3230
movq %rax, -0x5c8(%rbp)
jmp 0x36036
movq -0x5c8(%rbp), %rdi
movq -0x368(%rbp), %rax
movl -0x7c(%rbp,%rax,8), %esi
callq 0x3310
movq %rax, -0x5d0(%rbp)
jmp 0x36056
movq -0x5d0(%rbp), %rdi
movq 0xc1f5c(%rip), %rsi     # 0xf7fc0
callq 0x3280
jmp 0x3606b
cmpl $0x1869f, -0x464(%rbp)  # imm = 0x1869F
je 0x3641f
movl -0x464(%rbp), %eax
movl %eax, -0x5dc(%rbp)
leaq -0x4d1(%rbp), %rdi
movq %rdi, -0x5d8(%rbp)
callq 0x3440
movq -0x5d8(%rbp), %rdx
leaq 0x7d06d(%rip), %rsi     # 0xb3115
leaq -0x4d0(%rbp), %rdi
callq 0x3340
jmp 0x360b6
leaq 0x7d796(%rip), %rdx     # 0xb3853
leaq -0x4b0(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0xaa1b0
jmp 0x360d2
leaq -0x519(%rbp), %rdi
movq %rdi, -0x5e8(%rbp)
callq 0x3440
movq -0x5e8(%rbp), %rdx
movb $0x0, -0x51b(%rbp)
movb $0x0, -0x542(%rbp)
movb $0x0, -0x543(%rbp)
leaq 0x7e3fc(%rip), %rsi     # 0xb4504
leaq -0x518(%rbp), %rdi
callq 0x3340
jmp 0x36116
leaq -0x518(%rbp), %rdi
callq 0x33f0
movb %al, -0x5e9(%rbp)
jmp 0x3612a
movb -0x5e9(%rbp), %al
testb $0x1, %al
jne 0x36136
jmp 0x3616e
leaq -0x51a(%rbp), %rdi
movq %rdi, -0x5f8(%rbp)
callq 0x3440
movq -0x5f8(%rbp), %rdx
movb $0x1, -0x51b(%rbp)
leaq 0x7e3a6(%rip), %rsi     # 0xb4504
leaq -0x4f8(%rbp), %rdi
callq 0x3340
jmp 0x3616c
jmp 0x361c9
leaq -0x541(%rbp), %rdi
movq %rdi, -0x600(%rbp)
callq 0x3440
movq -0x600(%rbp), %rdx
movb $0x1, -0x542(%rbp)
leaq 0x7e36e(%rip), %rsi     # 0xb4504
leaq -0x540(%rbp), %rdi
callq 0x3340
jmp 0x361a4
movb $0x1, -0x543(%rbp)
leaq 0x80531(%rip), %rsi     # 0xb66e3
leaq -0x4f8(%rbp), %rdi
leaq -0x540(%rbp), %rdx
callq 0xaa6d0
jmp 0x361c7
jmp 0x361c9
leaq -0x490(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
leaq -0x4f8(%rbp), %rdx
callq 0xaa240
jmp 0x361e5
movl -0x5dc(%rbp), %edi
leaq -0x490(%rbp), %rsi
callq 0x28d30
jmp 0x361f9
leaq -0x490(%rbp), %rdi
callq 0x34a8
jmp 0x36207
leaq -0x4f8(%rbp), %rdi
callq 0x34a8
jmp 0x36215
testb $0x1, -0x543(%rbp)
jne 0x36220
jmp 0x36230
leaq -0x540(%rbp), %rdi
callq 0x34a8
jmp 0x3622e
jmp 0x36230
testb $0x1, -0x542(%rbp)
jne 0x3623b
jmp 0x36247
leaq -0x541(%rbp), %rdi
callq 0x3290
testb $0x1, -0x51b(%rbp)
jne 0x36252
jmp 0x3625e
leaq -0x51a(%rbp), %rdi
callq 0x3290
leaq -0x518(%rbp), %rdi
callq 0x34a8
jmp 0x3626c
leaq -0x519(%rbp), %rdi
callq 0x3290
leaq -0x4b0(%rbp), %rdi
callq 0x34a8
jmp 0x36286
leaq -0x4d0(%rbp), %rdi
callq 0x34a8
jmp 0x36294
leaq -0x4d1(%rbp), %rdi
callq 0x3290
jmp 0x36428
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x36411
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x36401
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x363e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x363d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x363bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x363a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x36386
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x36376
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x34a8
jmp 0x36374
jmp 0x36376
leaq -0x4f8(%rbp), %rdi
callq 0x34a8
jmp 0x36384
jmp 0x36386
testb $0x1, -0x543(%rbp)
jne 0x36391
jmp 0x363a1
leaq -0x540(%rbp), %rdi
callq 0x34a8
jmp 0x3639f
jmp 0x363a1
jmp 0x363a3
testb $0x1, -0x542(%rbp)
jne 0x363ae
jmp 0x363ba
leaq -0x541(%rbp), %rdi
callq 0x3290
jmp 0x363bc
testb $0x1, -0x51b(%rbp)
jne 0x363c7
jmp 0x363d3
leaq -0x51a(%rbp), %rdi
callq 0x3290
jmp 0x363d5
leaq -0x518(%rbp), %rdi
callq 0x34a8
jmp 0x363e3
jmp 0x363e5
leaq -0x519(%rbp), %rdi
callq 0x3290
leaq -0x4b0(%rbp), %rdi
callq 0x34a8
jmp 0x363ff
jmp 0x36401
leaq -0x4d0(%rbp), %rdi
callq 0x34a8
jmp 0x3640f
jmp 0x36411
leaq -0x4d1(%rbp), %rdi
callq 0x3290
jmp 0x36471
callq 0x28bd0
jmp 0x36426
jmp 0x36428
jmp 0x3642a
jmp 0x3642c
movq -0x368(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x368(%rbp)
jmp 0x35d09
jmp 0x36445
movq -0x360(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x360(%rbp)
jmp 0x35cc7
leaq -0x300(%rbp), %rdi
callq 0x11b20
addq $0x600, %rsp            # imm = 0x600
popq %rbp
retq
leaq -0x300(%rbp), %rdi
callq 0x11b20
jmp 0x3647f
jmp 0x36481
movq -0x340(%rbp), %rdi
callq 0x3430
movq %rax, %rdi
callq 0x1a490
nopw %cs:(%rax,%rax)