// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/libsquish/singlecolourfit.cpp
// Function: squish::SingleColourFit::ComputeEndPoints(squish::SingleColourLookup const* const*)
void SingleColourFit::ComputeEndPoints( SingleColourLookup const* const* lookups )
{
    // check each index combination (endpoint or intermediate)
    m_error = INT_MAX;
    for( int index = 0; index < 2; ++index )
    {
        // check the error for this codebook index
        SourceBlock const* sources[3];
        int error = 0;
        for( int channel = 0; channel < 3; ++channel )
        {
            // grab the lookup table and index for this channel
            SingleColourLookup const* lookup = lookups[channel];
            int target = m_colour[channel];

            // store a pointer to the source for this channel
            sources[channel] = lookup[target].sources + index;

            // accumulate the error
            int diff = sources[channel]->error;
            error += diff*diff;
        }

        // keep it if the error is lower
        if( error < m_error )
        {
            m_start = Vec3(
                ( float )sources[0]->start/31.0f,
                ( float )sources[1]->start/63.0f,
                ( float )sources[2]->start/31.0f
            );
            m_end = Vec3(
                ( float )sources[0]->end/31.0f,
                ( float )sources[1]->end/63.0f,
                ( float )sources[2]->end/31.0f
            );
            m_index = ( u8 )( 2*index );
            m_error = error;
        }
    }
}

// Assembly:
pushq %rbp
pushq %rbx
movl $0x7fffffff, 0x34(%rdi) # imm = 0x7FFFFFFF
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movb $0x1, %al
xorl %ecx, %ecx
pxor %xmm0, %xmm0
movaps 0xc22e(%rip), %xmm1     # 0x7ee30
movsd 0xc236(%rip), %xmm2     # 0x7ee40
leaq (%rcx,%rcx,2), %r9
xorl %r10d, %r10d
xorl %edx, %edx
movzbl 0x14(%rdi,%r10), %r11d
leaq (%r11,%r11,2), %r11
addq %r11, %r11
addq (%rsi,%r10,8), %r11
leaq (%r11,%r9), %rbx
movq %rbx, -0x18(%rsp,%r10,8)
movzbl 0x2(%r11,%r9), %r11d
imull %r11d, %r11d
addl %r11d, %edx
incq %r10
cmpq $0x3, %r10
jne 0x72c13
cmpl %r8d, %edx
jge 0x72cc5
movq -0x18(%rsp), %r8
movq -0x10(%rsp), %r9
movzbl (%r8), %r10d
movzbl (%r9), %r11d
movq -0x8(%rsp), %rbx
movzbl (%rbx), %ebp
movzbl 0x1(%r9), %r9d
shll $0x8, %r11d
orl %r10d, %r11d
shll $0x10, %ebp
orl %r11d, %ebp
movzbl 0x1(%r8), %r8d
shll $0x18, %r8d
orl %ebp, %r8d
movd %r8d, %xmm3
punpcklbw %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3],xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
punpcklwd %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3]
cvtdq2ps %xmm3, %xmm3
divps %xmm1, %xmm3
movzbl 0x1(%rbx), %r8d
movups %xmm3, 0x18(%rdi)
shll $0x8, %r8d
orl %r9d, %r8d
movd %r8d, %xmm3
punpcklbw %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3],xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
punpcklwd %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3]
cvtdq2ps %xmm3, %xmm3
divps %xmm2, %xmm3
movlps %xmm3, 0x28(%rdi)
addb %cl, %cl
movb %cl, 0x30(%rdi)
movl %edx, 0x34(%rdi)
movl %edx, %r8d
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x72c0a
popq %rbx
popq %rbp
retq