// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xa1cb0
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x28(%rbp), %rdi
callq 0xa1cd0
andb $0x1, %al
movb %al, -0x2a(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0xa1cf0
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xa1cf0
movl %eax, -0x34(%rbp)
leaq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x10, %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0xa1c30
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
addq $0x4, %rax
cmpq %rcx, %rax
movq %rax, -0x90(%rbp)
jne 0x9e16e
leaq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x10, %rcx
movq %rcx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0xa1c30
movq -0xb8(%rbp), %rax
movq -0xb0(%rbp), %rcx
addq $0x4, %rax
cmpq %rcx, %rax
movq %rax, -0xa8(%rbp)
jne 0x9e1b8
movb $0x1, -0x61(%rbp)
testb $0x1, -0x29(%rbp)
je 0x9e244
movq -0x28(%rbp), %rdi
callq 0xa1d60
movw %ax, -0x64(%rbp)
movq -0x28(%rbp), %rdi
callq 0xa1dd0
movw %ax, -0x66(%rbp)
leaq -0x50(%rbp), %rdi
movw -0x64(%rbp), %ax
movl -0x30(%rbp), %edx
movzwl %ax, %esi
callq 0x9dd10
leaq -0x60(%rbp), %rdi
movw -0x64(%rbp), %dx
movw -0x66(%rbp), %ax
movl -0x34(%rbp), %ecx
movzwl %dx, %esi
movzwl %ax, %edx
callq 0x9de50
testb $0x1, %al
jne 0x9e242
movb $0x0, -0x61(%rbp)
jmp 0x9e28b
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0xa1e40
movw %ax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
movw -0x68(%rbp), %ax
movl -0x30(%rbp), %edx
movzwl %ax, %esi
callq 0x9dfb0
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xa1e40
movw %ax, -0x6a(%rbp)
leaq -0x60(%rbp), %rdi
movw -0x6a(%rbp), %ax
movl -0x34(%rbp), %edx
movzwl %ax, %esi
callq 0x9dfb0
testb $0x1, -0x11(%rbp)
je 0x9e5c3
testb $0x1, -0x2a(%rbp)
je 0x9e4b4
movl $0x0, -0x70(%rbp)
cmpl $0x2, -0x70(%rbp)
jae 0x9e3a7
movq -0x20(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x28(%rbp), %rdi
movl -0x70(%rbp), %edx
xorl %esi, %esi
callq 0xa1f30
movq -0xd8(%rbp), %rdi
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rdi
movl -0x70(%rbp), %edx
movl $0x1, %esi
callq 0xa1f30
movq -0xd0(%rbp), %rdi
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
movl -0x70(%rbp), %edx
movl $0x2, %esi
callq 0xa1f30
movq -0xc8(%rbp), %rdi
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0xc, %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rdi
movl -0x70(%rbp), %edx
movl $0x3, %esi
callq 0xa1f30
movq -0xc0(%rbp), %rdi
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x9e2a6
movl $0x2, -0x74(%rbp)
cmpl $0x4, -0x74(%rbp)
jae 0x9e4af
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x28(%rbp), %rdi
movl -0x74(%rbp), %edx
xorl %esi, %esi
callq 0xa1f30
movq -0xf8(%rbp), %rdi
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xf0(%rbp)
movq -0x28(%rbp), %rdi
movl -0x74(%rbp), %edx
movl $0x1, %esi
callq 0xa1f30
movq -0xf0(%rbp), %rdi
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rdi
movl -0x74(%rbp), %edx
movl $0x2, %esi
callq 0xa1f30
movq -0xe8(%rbp), %rdi
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0xc, %rax
movq %rax, -0xe0(%rbp)
movq -0x28(%rbp), %rdi
movl -0x74(%rbp), %edx
movl $0x3, %esi
callq 0xa1f30
movq -0xe0(%rbp), %rdi
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x9e3ae
jmp 0x9e5be
movl $0x0, -0x78(%rbp)
cmpl $0x4, -0x78(%rbp)
jae 0x9e5bc
movq -0x20(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x28(%rbp), %rdi
movl -0x78(%rbp), %edx
xorl %esi, %esi
callq 0xa1f30
movq -0x118(%rbp), %rdi
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x110(%rbp)
movq -0x28(%rbp), %rdi
movl -0x78(%rbp), %edx
movl $0x1, %esi
callq 0xa1f30
movq -0x110(%rbp), %rdi
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x108(%rbp)
movq -0x28(%rbp), %rdi
movl -0x78(%rbp), %edx
movl $0x2, %esi
callq 0xa1f30
movq -0x108(%rbp), %rdi
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x100(%rbp)
movq -0x28(%rbp), %rdi
movl -0x78(%rbp), %edx
movl $0x3, %esi
callq 0xa1f30
movq -0x100(%rbp), %rdi
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
callq 0xa1f00
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x9e4bb
jmp 0x9e5be
jmp 0x9e85e
testb $0x1, -0x2a(%rbp)
je 0x9e772
movl $0x0, -0x7c(%rbp)
cmpl $0x2, -0x7c(%rbp)
jae 0x9e69d
movq -0x28(%rbp), %rdi
movl -0x7c(%rbp), %edx
xorl %esi, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl $0x1, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl $0x2, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl $0x3, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0xc, %rdi
callq 0xa1ff0
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x9e5d4
movl $0x2, -0x80(%rbp)
cmpl $0x4, -0x80(%rbp)
jae 0x9e76d
movq -0x28(%rbp), %rdi
movl -0x80(%rbp), %edx
xorl %esi, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x80(%rbp), %edx
movl $0x1, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x80(%rbp), %edx
movl $0x2, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x80(%rbp), %edx
movl $0x3, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0xc, %rdi
callq 0xa1ff0
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x9e6a4
jmp 0x9e85c
movl $0x0, -0x84(%rbp)
cmpl $0x4, -0x84(%rbp)
jae 0x9e85a
movq -0x28(%rbp), %rdi
movl -0x84(%rbp), %edx
xorl %esi, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x84(%rbp), %edx
movl $0x1, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x50(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x84(%rbp), %edx
movl $0x2, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
callq 0xa1ff0
movq -0x28(%rbp), %rdi
movl -0x84(%rbp), %edx
movl $0x3, %esi
callq 0xa1f30
movl %eax, %eax
leaq -0x60(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0xc, %rdi
callq 0xa1ff0
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x9e77c
jmp 0x9e85c
jmp 0x9e85e
movb -0x61(%rbp), %al
andb $0x1, %al
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)