// File: /workspace/github_c_makefile_star2_O3/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 0x69cea
movzbl 0x2(%r14), %ecx
movzwl %ax, %esi
movzbl 0x1(%r14), %eax
andl $-0x10, %eax
shrl $0x4, %ecx
orl %eax, %ecx
shll $0x4, %esi
andl $0xf00, %esi            # imm = 0xF00
orl %ecx, %esi
leaq 0x10(%rsp), %rdi
callq 0x69ad6
movzbl (%r14), %esi
movb 0x1(%r14), %al
movzbl 0x2(%r14), %ecx
andl $0xf, %esi
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 0x69ad6
movb $0x1, %al
jmp 0x69d52
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 0x6979c
movq %rsp, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl 0x24(%rsp), %r12d
movl %r15d, %ecx
callq 0x69934
testb %r12b, %r12b
je 0x69e7d
testb $0x1, %bpl
jne 0x69f57
xorl %edx, %edx
leaq 0x12d7c(%rip), %rdi     # 0x7caea
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 0x69d6e
jmp 0x6a324
testb $0x1, %bpl
jne 0x6a184
xorl %edx, %edx
leaq 0x12c5a(%rip), %rdi     # 0x7caea
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 0x69e90
jmp 0x6a324
xorl %edx, %edx
movb $0x1, %r8b
leaq 0x12b87(%rip), %rdi     # 0x7caea
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r9d
movl %edx, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%rsi,%r9,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
movl %edx, %esi
orb $0x4, %sil
movzbl %sil, %esi
xorl %r9d, %r9d
btl %esi, %ecx
setb %r9b
movzbl 0x5(%r14), %r10d
movl %esi, %ecx
shrl %cl, %r10d
andl $0x1, %r10d
leal (%r9,%r10,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %r9b
movb %r9b, 0x4(%rbx)
movb 0x11(%rsp,%rcx,4), %r9b
movb %r9b, 0x5(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0x6(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r9d, %r9d
btl %edx, %ecx
setb %r9b
movzbl 0x4(%r14), %r10d
movl %edx, %ecx
shrl %cl, %r10d
andl $0x1, %r10d
leal (%r9,%r10,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %dl
movb %dl, 0x8(%rbx)
movb 0x11(%rsp,%rcx,4), %dl
movb %dl, 0x9(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0xa(%rbx)
movzbl 0x6(%r14), %ecx
xorl %edx, %edx
btl %esi, %ecx
setb %dl
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%rdx,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movb 0x10(%rsp,%rcx,4), %dl
movb %dl, 0xc(%rbx)
movb 0x11(%rsp,%rcx,4), %dl
movb %dl, 0xd(%rbx)
movb 0x12(%rsp,%rcx,4), %cl
movb %cl, 0xe(%rbx)
addq $0x10, %rbx
movl $0x1, %edx
testb $0x1, %r8b
movl $0x0, %r8d
jne 0x69f63
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 0x6a077
jmp 0x6a324
xorl %edx, %edx
movb $0x1, %r8b
leaq 0x1295a(%rip), %rdi     # 0x7caea
movzbl 0x7(%r14), %ecx
xorl %esi, %esi
btl %edx, %ecx
setb %sil
movzbl 0x5(%r14), %r9d
movl %edx, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%rsi,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, (%rbx)
movzbl 0x7(%r14), %ecx
movl %edx, %esi
orb $0x4, %sil
movzbl %sil, %esi
xorl %r9d, %r9d
btl %esi, %ecx
setb %r9b
movzbl 0x5(%r14), %r10d
movl %esi, %ecx
shrl %cl, %r10d
andl $0x1, %r10d
leal (%r9,%r10,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0x4(%rbx)
movzbl 0x6(%r14), %ecx
xorl %r9d, %r9d
btl %edx, %ecx
setb %r9b
movzbl 0x4(%r14), %r10d
movl %edx, %ecx
shrl %cl, %r10d
andl $0x1, %r10d
leal (%r9,%r10,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0x8(%rbx)
movzbl 0x6(%r14), %ecx
xorl %edx, %edx
btl %esi, %ecx
setb %dl
movzbl 0x4(%r14), %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl $0x1, %r9d
leal (%rdx,%r9,2), %ecx
movzbl (%rcx,%rdi), %ecx
movl 0x10(%rsp,%rcx,4), %ecx
movl %ecx, 0xc(%rbx)
addq $0x10, %rbx
movl $0x1, %edx
testb $0x1, %r8b
movl $0x0, %r8d
jne 0x6a190
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 0x6a264
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop