// File: /workspace/github_c_makefile_star2_O1/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 %rbx
movl $0x7fffffff, 0x34(%rdi) # imm = 0x7FFFFFFF
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %eax, %eax
pxor %xmm0, %xmm0
movaps 0xca5a(%rip), %xmm1     # 0x7d9a0
movsd 0xca62(%rip), %xmm2     # 0x7d9b0
leaq (%rax,%rax,2), %r8
xorl %r9d, %r9d
xorl %ecx, %ecx
movzbl 0x14(%rdi,%r9), %r10d
leaq (%r10,%r10,2), %r10
addq %r10, %r10
addq (%rsi,%r9,8), %r10
leaq (%r10,%r8), %r11
movq %r11, -0x20(%rsp,%r9,8)
movzbl 0x2(%r10,%r8), %r10d
imull %r10d, %r10d
addl %r10d, %ecx
incq %r9
cmpq $0x3, %r9
jne 0x70f57
cmpl %edx, %ecx
jge 0x71003
movq -0x20(%rsp), %rdx
movq -0x18(%rsp), %r8
movzbl (%rdx), %r9d
movzbl (%r8), %r10d
movq -0x10(%rsp), %r11
movzbl (%r11), %ebx
movzbl 0x1(%r8), %r8d
shll $0x8, %r10d
orl %r9d, %r10d
shll $0x10, %ebx
orl %r10d, %ebx
movzbl 0x1(%rdx), %edx
shll $0x18, %edx
orl %ebx, %edx
movd %edx, %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(%r11), %edx
movups %xmm3, 0x18(%rdi)
shll $0x8, %edx
orl %r8d, %edx
movd %edx, %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)
leal (%rax,%rax), %edx
movb %dl, 0x30(%rdi)
movl %ecx, 0x34(%rdi)
movl %ecx, %edx
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0x70f4e
popq %rbx
retq
nop