// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/rg_etc1.cpp
// Function: rg_etc1::pack_etc1_block_init()
void pack_etc1_block_init()
   {
      for (uint diff = 0; diff < 2; diff++)
      {
         const uint limit = diff ? 32 : 16;

         for (uint inten = 0; inten < 8; inten++)
         {
            for (uint selector = 0; selector < 4; selector++)
            {
               const uint inverse_table_index = diff + (inten << 1) + (selector << 4);
               for (uint color = 0; color < 256; color++)
               {
                  uint best_error = cUINT32_MAX, best_packed_c = 0;
                  for (uint packed_c = 0; packed_c < limit; packed_c++)
                  {
                     int v = etc1_decode_value(diff, inten, selector, packed_c);
                     uint err = abs(v - static_cast<int>(color));  //JonoF
                     if (err < best_error)
                     {
                        best_error = err;
                        best_packed_c = packed_c;
                        if (!best_error) 
                           break;
                     }
                  }
                  RG_ETC1_ASSERT(best_error <= 255);
                  g_etc1_inverse_lookup[inverse_table_index][color] = static_cast<uint16>(best_packed_c | (best_error << 8));
               }
            }
         }
      }
      
      uint expand5[32];
      for(int i = 0; i < 32; i++)
         expand5[i] = (i << 3) | (i >> 2);

      for(int i = 0; i < 256 + 16; i++)
      {
         int v = clamp<int>(i - 8, 0, 255);
         g_quant5_tab[i] = static_cast<uint8>(expand5[mul_8bit(v,31)]);
      }
   }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movb $0x1, %al
xorl %ecx, %ecx
movl $0xff, %esi
movq $0x0, (%rsp)
movl %eax, %edx
notb %dl
movzbl %dl, %r9d
andl $0x1, %r9d
shll $0x4, %r9d
addl $0x10, %r9d
xorl %edx, %edx
leaq (%rdx,%rdx), %rdi
movq %rdi, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdx, %rdi
shlq $0x4, %rdi
leaq 0x11988(%rip), %rdx     # 0x7cd60
addq %rdx, %rdi
movq %rdi, 0x10(%rsp)
xorl %edi, %edi
movq %rdi, %r8
shlq $0x4, %r8
addq 0x18(%rsp), %r8
orq (%rsp), %r8
movq 0x10(%rsp), %rdx
movq %rdi, 0x20(%rsp)
movl (%rdx,%rdi,4), %ebp
shlq $0x9, %r8
leaq 0x659da6(%rip), %rdx    # 0x6c51b0
addq %rdx, %r8
movq %r8, 0x28(%rsp)
xorl %r12d, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x1, %r8d
xorl %r10d, %r10d
xorl %edi, %edi
xorl %edx, %edx
leal -0x1(%r8), %r11d
testb $0x1, %al
je 0x6b438
movl %r10d, %ebx
orl %r11d, %ebx
jmp 0x6b440
movl %r11d, %ebx
shrl $0x2, %ebx
orl %edi, %ebx
addl %ebp, %ebx
cmpl %esi, %ebx
cmovgel %esi, %ebx
testl %ebx, %ebx
cmovlel %ecx, %ebx
movl %ebx, %r15d
subl %r12d, %r15d
movl %r15d, %r14d
negl %r14d
cmovsl %r15d, %r14d
cmpq %rbx, %r12
sete %bl
cmpl %r13d, %r14d
cmovbl %r14d, %r13d
setb %r14b
cmovbl %r11d, %edx
testb %r14b, %bl
jne 0x6b489
leal 0x1(%r8), %r11d
addl $0x8, %edi
addl $0x10, %r10d
cmpl %r9d, %r8d
movl %r11d, %r8d
jb 0x6b428
cmpl $0x100, %r13d           # imm = 0x100
jae 0x6b598
shll $0x8, %r13d
orl %r13d, %edx
movq 0x28(%rsp), %rdi
movw %dx, (%rdi,%r12,2)
incq %r12
cmpq $0x100, %r12            # imm = 0x100
jne 0x6b415
movq 0x20(%rsp), %rdi
incq %rdi
cmpq $0x4, %rdi
jne 0x6b3e2
movq 0x8(%rsp), %rdx
incq %rdx
cmpq $0x8, %rdx
jne 0x6b3bc
movl $0x1, %edx
movq %rdx, (%rsp)
testb $0x1, %al
movl $0x0, %eax
jne 0x6b3a6
movdqa 0xc2d7(%rip), %xmm0     # 0x777d0
xorl %eax, %eax
movdqa 0xbb6d(%rip), %xmm1     # 0x77070
movdqa %xmm0, %xmm2
movdqa %xmm0, %xmm3
psrld $0x2, %xmm3
movdqa %xmm2, %xmm4
pslld $0x3, %xmm4
paddd %xmm3, %xmm4
movdqa %xmm4, 0x30(%rsp,%rax,4)
addq $0x4, %rax
paddd %xmm1, %xmm0
paddd %xmm1, %xmm2
cmpq $0x20, %rax
jne 0x6b507
xorl %eax, %eax
movl $0x107, %ecx            # imm = 0x107
movl $0x8, %edx
leaq 0x661c68(%rip), %rsi    # 0x6cd1b0
cmpl %ecx, %eax
movl $0x107, %edi            # imm = 0x107
cmovll %eax, %edi
cmpl $0x9, %edi
cmovll %edx, %edi
movl %edi, %r8d
shll $0x5, %r8d
subl %edi, %r8d
leal -0x78(%r8), %edi
shrl $0x8, %edi
addl %r8d, %edi
addl $-0x78, %edi
shrl $0x8, %edi
movb 0x30(%rsp,%rdi,4), %dil
movb %dil, (%rax,%rsi)
incq %rax
cmpq $0x110, %rax            # imm = 0x110
jne 0x6b548
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11389(%rip), %rdi     # 0x7c928
leaq 0x11139(%rip), %rsi     # 0x7c6df
leaq 0x1138d(%rip), %rcx     # 0x7c93a
movl $0x78b, %edx            # imm = 0x78B
callq 0x61b0