// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/rg_etc1.cpp
// Function: rg_etc1::etc1_optimizer::init(rg_etc1::etc1_optimizer::params const&, rg_etc1::etc1_optimizer::results&)
void etc1_optimizer::init(const params& p, results& r)
   {
      // This version is hardcoded for 8 pixel subblocks.
      RG_ETC1_ASSERT(p.m_num_src_pixels == 8);
      
      m_pParams = &p;
      m_pResult = &r;
                  
      const uint n = 8;
      
      m_limit = m_pParams->m_use_color4 ? 15 : 31;

      vec3F avg_color(0.0f);

      for (uint i = 0; i < n; i++)
      {
         const color_quad_u8& c = m_pParams->m_pSrc_pixels[i];
         const vec3F fc(c.r, c.g, c.b);

         avg_color += fc;

         m_luma[i] = static_cast<uint16>(c.r + c.g + c.b);
         m_sorted_luma[0][i] = i;
      }
      avg_color *= (1.0f / static_cast<float>(n));
      m_avg_color = avg_color;

      m_br = rg_etc1::clamp<int>(static_cast<uint>(m_avg_color[0] * m_limit / 255.0f + .5f), 0, m_limit);
      m_bg = rg_etc1::clamp<int>(static_cast<uint>(m_avg_color[1] * m_limit / 255.0f + .5f), 0, m_limit);
      m_bb = rg_etc1::clamp<int>(static_cast<uint>(m_avg_color[2] * m_limit / 255.0f + .5f), 0, m_limit);

      if (m_pParams->m_quality <= cMediumQuality)
      {
         m_pSorted_luma_indices = indirect_radix_sort(n, m_sorted_luma[0], m_sorted_luma[1], m_luma, 0, sizeof(m_luma[0]), false);
         m_pSorted_luma = m_sorted_luma[0];
         if (m_pSorted_luma_indices == m_sorted_luma[0])
            m_pSorted_luma = m_sorted_luma[1];
      
         for (uint i = 0; i < n; i++)
            m_pSorted_luma[i] = m_luma[m_pSorted_luma_indices[i]];
      }
      
      m_best_solution.m_coords.clear();
      m_best_solution.m_valid = false;
      m_best_solution.m_error = cUINT64_MAX;
   }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x8, 0x8(%rsi)
jne 0x60086
movq %rdi, %rbx
movq %rsi, (%rdi)
movq %rdx, 0x8(%rdi)
movzbl 0x18(%rsi), %eax
xorl $0x1, %eax
shll $0x4, %eax
orl $0xf, %eax
movl %eax, 0x10(%rdi)
leaq 0x28(%rsp), %r12
andq $0x0, (%r12)
andl $0x0, 0x8(%r12)
leaq 0x2c(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x3c(%rdi), %r15
pushq $-0x8
popq %rbp
leaq 0x18(%rsp), %r13
testq %rbp, %rbp
je 0x5ff3c
movq (%rbx), %rax
movq 0x10(%rax), %r14
movzbl 0x22(%r14,%rbp,4), %eax
cvtsi2ss %eax, %xmm0
movd 0x20(%r14,%rbp,4), %xmm1
pxor %xmm2, %xmm2
punpcklbw %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3],xmm1[4],xmm2[4],xmm1[5],xmm2[5],xmm1[6],xmm2[6],xmm1[7],xmm2[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
cvtdq2ps %xmm1, %xmm1
movlps %xmm1, 0x18(%rsp)
movss %xmm0, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x611ce
movzbl 0x20(%r14,%rbp,4), %eax
movzbl 0x21(%r14,%rbp,4), %ecx
addl %eax, %ecx
movzbl 0x22(%r14,%rbp,4), %eax
addl %ecx, %eax
movw %ax, 0x3c(%rbx,%rbp,2)
leal 0x8(%rbp), %eax
movl %eax, 0x5c(%rbx,%rbp,4)
incq %rbp
jmp 0x5fed3
leaq 0x28(%rsp), %r12
movss 0x114a7(%rip), %xmm0    # 0x713f0
movq %r12, %rdi
callq 0x611ee
movq (%r12), %rax
movq %rax, 0x14(%rbx)
movl 0x8(%r12), %eax
movl %eax, 0x1c(%rbx)
movl 0x10(%rbx), %eax
cvtsi2ss %eax, %xmm0
movsd 0x14(%rbx), %xmm1
movaps %xmm0, %xmm2
shufps $0x0, %xmm0, %xmm2      # xmm2 = xmm2[0,0],xmm0[0,0]
mulps %xmm1, %xmm2
divps 0xf562(%rip), %xmm2     # 0x6f4e0
addps 0x1142b(%rip), %xmm2    # 0x713b0
cvttps2dq %xmm2, %xmm1
movdqa %xmm1, %xmm3
psrad $0x1f, %xmm3
subps 0x11427(%rip), %xmm2    # 0x713c0
cvttps2dq %xmm2, %xmm2
pand %xmm3, %xmm2
por %xmm1, %xmm2
pxor %xmm1, %xmm1
movd %eax, %xmm3
pshufd $0x50, %xmm3, %xmm3     # xmm3 = xmm3[0,0,1,1]
movdqa %xmm3, %xmm4
pcmpgtd %xmm2, %xmm4
pcmpgtd %xmm2, %xmm1
pand %xmm4, %xmm2
pandn %xmm3, %xmm4
por %xmm2, %xmm4
pandn %xmm4, %xmm1
movq %xmm1, 0x20(%rbx)
mulss 0x1c(%rbx), %xmm0
divss 0xf340(%rip), %xmm0     # 0x6f320
addss 0xf320(%rip), %xmm0     # 0x6f308
cvttss2si %xmm0, %rcx
cmpl %eax, %ecx
cmovll %ecx, %eax
xorl %edx, %edx
testl %ecx, %ecx
cmovnsl %eax, %edx
movl %edx, 0x28(%rbx)
movq (%rbx), %rax
cmpl $0x2, (%rax)
movq 0x10(%rsp), %r14
jge 0x60059
leaq 0x5c(%rbx), %r12
andl $0x0, (%rsp)
pushq $0x8
popq %rdi
xorl %r13d, %r13d
pushq $0x2
popq %r9
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x6120d
movq %rax, 0x80(%rbx)
cmpq %r15, %rax
cmoveq %r12, %r15
movq %r15, 0x88(%rbx)
cmpq $0x8, %r13
je 0x60059
movl (%rax,%r13,4), %ecx
movzwl (%r14,%rcx,2), %ecx
movl %ecx, (%r15,%r13,4)
incq %r13
jmp 0x60041
xorl %eax, %eax
movb %al, 0xa8(%rbx)
andq $0x0, 0xa0(%rbx)
movb %al, 0xc0(%rbx)
orq $-0x1, 0xb8(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11595(%rip), %rdi     # 0x71622
leaq 0x1139b(%rip), %rsi     # 0x7142f
leaq 0x1159f(%rip), %rcx     # 0x7163a
movl $0x660, %edx            # imm = 0x660
callq 0x61b0