// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, %r14
movzbl 0x3(%rdi), %r15d
movl %r15d, %ebp
shrl $0x2, %ebp
movl %r15d, %r12d
shrl $0x5, %r12d
andl $0x7, %ebp
testb $0x2, %r15b
jne 0x5eeb3
xorl %esi, %esi
callq 0x610c6
movzwl %ax, %esi
leaq 0x20(%rsp), %rdi
movl %r12d, %edx
callq 0x5eca0
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x610c6
movzwl %ax, %esi
leaq 0x10(%rsp), %rdi
movl %ebp, %edx
callq 0x5eca0
movb $0x1, 0xe(%rsp)
jmp 0x5eefe
callq 0x61072
movl %r13d, 0x34(%rsp)
movl %eax, %r13d
movq %r14, %rdi
callq 0x610a8
movw %ax, 0xe(%rsp)
movzwl %r13w, %r13d
leaq 0x20(%rsp), %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x5e946
movzwl 0xe(%rsp), %edx
leaq 0x10(%rsp), %rdi
movl %r13d, %esi
movl 0x34(%rsp), %r13d
movl %ebp, %ecx
callq 0x5eaf0
movb %al, 0xe(%rsp)
testb %r13b, %r13b
je 0x5efc6
testb $0x1, %r15b
jne 0x5f045
xorl %r15d, %r15d
pushq $0x1
popq %r12
pushq $0x2
popq %r13
pushq $0x3
popq %rbp
cmpl $0x4, %r15d
je 0x5f290
movq %r14, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x20(%rsp,%rax,4), %cl
movb %cl, (%rbx)
movb 0x21(%rsp,%rax,4), %cl
movb %cl, 0x1(%rbx)
movb 0x22(%rsp,%rax,4), %al
movb %al, 0x2(%rbx)
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x20(%rsp,%rax,4), %cl
movb %cl, 0x4(%rbx)
movb 0x21(%rsp,%rax,4), %cl
movb %cl, 0x5(%rbx)
movb 0x22(%rsp,%rax,4), %al
movb %al, 0x6(%rbx)
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x10(%rsp,%rax,4), %cl
movb %cl, 0x8(%rbx)
movb 0x11(%rsp,%rax,4), %cl
movb %cl, 0x9(%rbx)
movb 0x12(%rsp,%rax,4), %al
movb %al, 0xa(%rbx)
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x10(%rsp,%rax,4), %cl
movb %cl, 0xc(%rbx)
movb 0x11(%rsp,%rax,4), %cl
movb %cl, 0xd(%rbx)
movb 0x12(%rsp,%rax,4), %al
movb %al, 0xe(%rbx)
addq $0x10, %rbx
incl %r15d
jmp 0x5ef1f
xorl %ebp, %ebp
testb $0x1, %r15b
jne 0x5f0fa
pushq $0x1
popq %r15
pushq $0x2
popq %r12
pushq $0x3
popq %r13
cmpl $0x4, %ebp
je 0x5f290
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %eax
movl %eax, (%rbx)
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %eax
movl %eax, 0x4(%rbx)
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0xc(%rbx)
addq $0x10, %rbx
incl %ebp
jmp 0x5efde
xorl %r12d, %r12d
pushq $0x1
popq %r13
pushq $0x2
popq %r15
pushq $0x3
popq %rbp
cmpl $0x2, %r12d
je 0x5f16d
movq %r14, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x20(%rsp,%rax,4), %cl
movb %cl, (%rbx)
movb 0x21(%rsp,%rax,4), %cl
movb %cl, 0x1(%rbx)
movb 0x22(%rsp,%rax,4), %al
movb %al, 0x2(%rbx)
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x20(%rsp,%rax,4), %cl
movb %cl, 0x4(%rbx)
movb 0x21(%rsp,%rax,4), %cl
movb %cl, 0x5(%rbx)
movb 0x22(%rsp,%rax,4), %al
movb %al, 0x6(%rbx)
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x20(%rsp,%rax,4), %cl
movb %cl, 0x8(%rbx)
movb 0x21(%rsp,%rax,4), %cl
movb %cl, 0x9(%rbx)
movb 0x22(%rsp,%rax,4), %al
movb %al, 0xa(%rbx)
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x20(%rsp,%rax,4), %cl
movb %cl, 0xc(%rbx)
movb 0x21(%rsp,%rax,4), %cl
movb %cl, 0xd(%rbx)
movb 0x22(%rsp,%rax,4), %al
movb %al, 0xe(%rbx)
addq $0x10, %rbx
incl %r12d
jmp 0x5f053
pushq $0x1
popq %r12
pushq $0x2
popq %r15
pushq $0x3
popq %r13
cmpl $0x2, %ebp
je 0x5f21e
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %eax
movl %eax, (%rbx)
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %eax
movl %eax, 0x4(%rbx)
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %eax
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x610f6
movl %eax, %eax
movl 0x20(%rsp,%rax,4), %eax
movl %eax, 0xc(%rbx)
addq $0x10, %rbx
incl %ebp
jmp 0x5f106
pushq $0x1
popq %r12
pushq $0x3
popq %rbp
movl %r15d, %r13d
cmpl $0x4, %r13d
je 0x5f290
movq %r14, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x10(%rsp,%rax,4), %cl
movb %cl, (%rbx)
movb 0x11(%rsp,%rax,4), %cl
movb %cl, 0x1(%rbx)
movb 0x12(%rsp,%rax,4), %al
movb %al, 0x2(%rbx)
movq %r14, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x10(%rsp,%rax,4), %cl
movb %cl, 0x4(%rbx)
movb 0x11(%rsp,%rax,4), %cl
movb %cl, 0x5(%rbx)
movb 0x12(%rsp,%rax,4), %al
movb %al, 0x6(%rbx)
movq %r14, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x10(%rsp,%rax,4), %cl
movb %cl, 0x8(%rbx)
movb 0x11(%rsp,%rax,4), %cl
movb %cl, 0x9(%rbx)
movb 0x12(%rsp,%rax,4), %al
movb %al, 0xa(%rbx)
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movb 0x10(%rsp,%rax,4), %cl
movb %cl, 0xc(%rbx)
movb 0x11(%rsp,%rax,4), %cl
movb %cl, 0xd(%rbx)
movb 0x12(%rsp,%rax,4), %al
movb %al, 0xe(%rbx)
addq $0x10, %rbx
incl %r13d
jmp 0x5f177
pushq $0x1
popq %rbp
pushq $0x3
popq %r12
movl %r15d, %r13d
cmpl $0x4, %r13d
je 0x5f290
movq %r14, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movl 0x10(%rsp,%rax,4), %eax
movl %eax, (%rbx)
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0x4(%rbx)
movq %r14, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x610f6
movl %eax, %eax
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0xc(%rbx)
addq $0x10, %rbx
incl %r13d
jmp 0x5f228
movb 0xe(%rsp), %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop