// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/rg_etc1.cpp
// Function: rg_etc1::unpack_etc1_block(void const*, unsigned int*, bool)
bool unpack_etc1_block(const void* pETC1_block, unsigned int* pDst_pixels_rgba, bool preserve_alpha)
   {
      color_quad_u8* pDst = reinterpret_cast<color_quad_u8*>(pDst_pixels_rgba);
      const etc1_block& block = *static_cast<const etc1_block*>(pETC1_block);

      const bool diff_flag = block.get_diff_bit();
      const bool flip_flag = block.get_flip_bit();
      const uint table_index0 = block.get_inten_table(0);
      const uint table_index1 = block.get_inten_table(1);

      color_quad_u8 subblock_colors0[4];
      color_quad_u8 subblock_colors1[4];
      bool success = true;

      if (diff_flag)
      {
         const uint16 base_color5 = block.get_base5_color();
         const uint16 delta_color3 = block.get_delta3_color();
         etc1_block::get_diff_subblock_colors(subblock_colors0, base_color5, table_index0);
            
         if (!etc1_block::get_diff_subblock_colors(subblock_colors1, base_color5, delta_color3, table_index1))
            success = false;
      }
      else
      {
         const uint16 base_color4_0 = block.get_base4_color(0);
         etc1_block::get_abs_subblock_colors(subblock_colors0, base_color4_0, table_index0);

         const uint16 base_color4_1 = block.get_base4_color(1);
         etc1_block::get_abs_subblock_colors(subblock_colors1, base_color4_1, table_index1);
      }

      if (preserve_alpha)
      {
         if (flip_flag)
         {
            for (uint y = 0; y < 2; y++)
            {
               pDst[0].set_rgb(subblock_colors0[block.get_selector(0, y)]);
               pDst[1].set_rgb(subblock_colors0[block.get_selector(1, y)]);
               pDst[2].set_rgb(subblock_colors0[block.get_selector(2, y)]);
               pDst[3].set_rgb(subblock_colors0[block.get_selector(3, y)]);
               pDst += 4;
            }

            for (uint y = 2; y < 4; y++)
            {
               pDst[0].set_rgb(subblock_colors1[block.get_selector(0, y)]);
               pDst[1].set_rgb(subblock_colors1[block.get_selector(1, y)]);
               pDst[2].set_rgb(subblock_colors1[block.get_selector(2, y)]);
               pDst[3].set_rgb(subblock_colors1[block.get_selector(3, y)]);
               pDst += 4;
            }
         }
         else
         {
            for (uint y = 0; y < 4; y++)
            {
               pDst[0].set_rgb(subblock_colors0[block.get_selector(0, y)]);
               pDst[1].set_rgb(subblock_colors0[block.get_selector(1, y)]);
               pDst[2].set_rgb(subblock_colors1[block.get_selector(2, y)]);
               pDst[3].set_rgb(subblock_colors1[block.get_selector(3, y)]);
               pDst += 4;
            }
         }
      }
      else 
      {
         if (flip_flag)
         {
            // 0000
            // 0000
            // 1111
            // 1111
            for (uint y = 0; y < 2; y++)
            {
               pDst[0] = subblock_colors0[block.get_selector(0, y)];
               pDst[1] = subblock_colors0[block.get_selector(1, y)];
               pDst[2] = subblock_colors0[block.get_selector(2, y)];
               pDst[3] = subblock_colors0[block.get_selector(3, y)];
               pDst += 4;
            }

            for (uint y = 2; y < 4; y++)
            {
               pDst[0] = subblock_colors1[block.get_selector(0, y)];
               pDst[1] = subblock_colors1[block.get_selector(1, y)];
               pDst[2] = subblock_colors1[block.get_selector(2, y)];
               pDst[3] = subblock_colors1[block.get_selector(3, y)];
               pDst += 4;
            }
         }
         else
         {
            // 0011
            // 0011
            // 0011
            // 0011
            for (uint y = 0; y < 4; y++)
            {
               pDst[0] = subblock_colors0[block.get_selector(0, y)];
               pDst[1] = subblock_colors0[block.get_selector(1, y)];
               pDst[2] = subblock_colors1[block.get_selector(2, y)];
               pDst[3] = subblock_colors1[block.get_selector(3, y)];
               pDst += 4;
            }
         }
      }
      
      return success;
   }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
movzbl 0x3(%rdi), %ebp
movl %ebp, %r15d
shrl $0x2, %r15d
movl %ebp, %edx
shrl $0x5, %edx
andl $0x7, %r15d
movzbl (%rdi), %eax
testb $0x2, %bpl
jne 0x68004
movzwl %ax, %esi
movzbl 0x1(%r14), %eax
andl $-0x10, %eax
movzbl 0x2(%r14), %ecx
shrl $0x4, %ecx
orl %eax, %ecx
shll $0x4, %esi
andl $0xf00, %esi            # imm = 0xF00
orl %ecx, %esi
leaq 0x10(%rsp), %rdi
callq 0x67dea
movzbl (%r14), %esi
andl $0xf, %esi
movb 0x1(%r14), %al
movzbl 0x2(%r14), %ecx
andl $0xf, %ecx
shlb $0x4, %al
movzbl %al, %eax
orl %ecx, %eax
shll $0x8, %esi
orl %eax, %esi
movq %rsp, %rdi
movl %r15d, %edx
callq 0x67dea
movb $0x1, %al
jmp 0x6806c
movl %r12d, 0x24(%rsp)
movzwl %ax, %r12d
movzbl 0x1(%r14), %eax
movzbl 0x2(%r14), %ecx
movl %ecx, %esi
shrl $0x3, %esi
movl %eax, %edi
andl $-0x8, %edi
leal (%rsi,%rdi,4), %esi
movl %r12d, %r13d
shll $0x7, %r13d
andl $0x7c00, %r13d          # imm = 0x7C00
orl %esi, %r13d
andl $0x7, %r12d
andl $0x7, %ecx
andl $0x7, %eax
leal (%rcx,%rax,8), %eax
shll $0x6, %r12d
orl %eax, %r12d
leaq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x67ab8
movq %rsp, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl 0x24(%rsp), %r12d
movl %r15d, %ecx
callq 0x67c48
xorl %edx, %edx
leaq 0x135cd(%rip), %rdi     # 0x7b642
testb %r12b, %r12b
je 0x683b6
testb $0x1, %bpl
jne 0x68197
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r8d
movl %edx, %ecx
shrl %cl, %r8d
andl $0x1, %r8d
leal (%rsi,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %sil
movb %sil, (%rbx)
movb 0x11(%rsp,%rcx,4), %sil
movb %sil, 0x1(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0x2(%rbx)
movzbl 0x7(%r14), %ecx
leal 0x4(%rdx), %esi
movzbl %sil, %esi
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x5(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %r8b
movb %r8b, 0x4(%rbx)
movb 0x11(%rsp,%rcx,4), %r8b
movb %r8b, 0x5(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0x6(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %edx, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %edx, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb (%rsp,%rcx,4), %r8b
movb %r8b, 0x8(%rbx)
movb 0x1(%rsp,%rcx,4), %r8b
movb %r8b, 0x9(%rbx)
movb 0x2(%rsp,%rcx,4), %cl
movb %cl, 0xa(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb (%rsp,%rcx,4), %sil
movb %sil, 0xc(%rbx)
movb 0x1(%rsp,%rcx,4), %sil
movb %sil, 0xd(%rbx)
movb 0x2(%rsp,%rcx,4), %cl
movb %cl, 0xe(%rbx)
addq $0x10, %rbx
incl %edx
cmpl $0x4, %edx
jne 0x68088
jmp 0x68611
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r8d
movl %edx, %ecx
shrl %cl, %r8d
andl $0x1, %r8d
leal (%rsi,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %sil
movb %sil, (%rbx)
movb 0x11(%rsp,%rcx,4), %sil
movb %sil, 0x1(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0x2(%rbx)
movzbl 0x7(%r14), %ecx
leal 0x4(%rdx), %esi
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x5(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %r8b
movb %r8b, 0x4(%rbx)
movb 0x11(%rsp,%rcx,4), %r8b
movb %r8b, 0x5(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0x6(%rbx)
movzbl 0x6(%r14), %r8d
leal -0x4(%rsi), %ecx
movzbl %cl, %ecx
xorl %r9d, %r9d
btl %ecx, %r8d
setb %r9b
movzbl 0x4(%r14), %r8d
shrl %cl, %r8d
andl $0x1, %r8d
leal (%r9,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %r8b
movb %r8b, 0x8(%rbx)
movb 0x11(%rsp,%rcx,4), %r8b
movb %r8b, 0x9(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0xa(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %r8b
movb %r8b, 0xc(%rbx)
movb 0x11(%rsp,%rcx,4), %r8b
movb %r8b, 0xd(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0xe(%rbx)
addq $0x10, %rbx
incl %edx
cmpl $0x4, %esi
je 0x68197
movl $0x2, %edx
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r8d
movl %edx, %ecx
shrl %cl, %r8d
andl $0x1, %r8d
leal (%rsi,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb (%rsp,%rcx,4), %sil
movb %sil, (%rbx)
movb 0x1(%rsp,%rcx,4), %sil
movb %sil, 0x1(%rbx)
movb 0x2(%rsp,%rcx,4), %cl
movb %cl, 0x2(%rbx)
movzbl 0x7(%r14), %ecx
leal 0x4(%rdx), %esi
movzbl %sil, %esi
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x5(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb (%rsp,%rcx,4), %r8b
movb %r8b, 0x4(%rbx)
movb 0x1(%rsp,%rcx,4), %r8b
movb %r8b, 0x5(%rbx)
movb 0x2(%rsp,%rcx,4), %cl
movb %cl, 0x6(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %edx, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %edx, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb (%rsp,%rcx,4), %r8b
movb %r8b, 0x8(%rbx)
movb 0x1(%rsp,%rcx,4), %r8b
movb %r8b, 0x9(%rbx)
movb 0x2(%rsp,%rcx,4), %cl
movb %cl, 0xa(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb (%rsp,%rcx,4), %sil
movb %sil, 0xc(%rbx)
movb 0x1(%rsp,%rcx,4), %sil
movb %sil, 0xd(%rbx)
movb 0x2(%rsp,%rcx,4), %cl
movb %cl, 0xe(%rbx)
addq $0x10, %rbx
incl %edx
cmpl $0x4, %edx
jne 0x682a9
jmp 0x68611
testb $0x1, %bpl
jne 0x68487
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r8d
movl %edx, %ecx
shrl %cl, %r8d
andl $0x1, %r8d
leal (%rsi,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, (%rbx)
movzbl 0x7(%r14), %ecx
leal 0x4(%rdx), %esi
movzbl %sil, %esi
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x5(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0x4(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %edx, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %edx, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl (%rsp,%rcx,4), %ecx
movl %ecx, 0x8(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl (%rsp,%rcx,4), %ecx
movl %ecx, 0xc(%rbx)
addq $0x10, %rbx
incl %edx
cmpl $0x4, %edx
jne 0x683c0
jmp 0x68611
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r8d
movl %edx, %ecx
shrl %cl, %r8d
andl $0x1, %r8d
leal (%rsi,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, (%rbx)
movzbl 0x7(%r14), %ecx
leal 0x4(%rdx), %esi
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x5(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0x4(%rbx)
movzbl 0x6(%r14), %r8d
leal -0x4(%rsi), %ecx
movzbl %cl, %ecx
xorl %r9d, %r9d
btl %ecx, %r8d
setb %r9b
movzbl 0x4(%r14), %r8d
shrl %cl, %r8d
andl $0x1, %r8d
leal (%r9,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0x8(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0xc(%rbx)
addq $0x10, %rbx
incl %edx
cmpl $0x4, %esi
je 0x68487
movl $0x2, %edx
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r8d
movl %edx, %ecx
shrl %cl, %r8d
andl $0x1, %r8d
leal (%rsi,%r8,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl (%rsp,%rcx,4), %ecx
movl %ecx, (%rbx)
movzbl 0x7(%r14), %ecx
leal 0x4(%rdx), %esi
movzbl %sil, %esi
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x5(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl (%rsp,%rcx,4), %ecx
movl %ecx, 0x4(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %edx, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %edx, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl (%rsp,%rcx,4), %ecx
movl %ecx, 0x8(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r8d, %r8d
btl %esi, %ecx
setb %r8b
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%r8,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl (%rsp,%rcx,4), %ecx
movl %ecx, 0xc(%rbx)
addq $0x10, %rbx
incl %edx
cmpl $0x4, %edx
jne 0x68551
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq