// File: /workspace/github_c_makefile_star2_O2/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 0xc802(%rip), %xmm1     # 0x73c30
movsd 0xc80a(%rip), %xmm2     # 0x73c40
cmpq $0x2, %rax
je 0x674fc
xorl %r8d, %r8d
leaq (%rax,%rax,2), %r9
xorl %ecx, %ecx
cmpq $0x3, %r8
je 0x67478
movzbl 0x14(%rdi,%r8), %r10d
imulq $0x6, %r10, %r10
addq (%rsi,%r8,8), %r10
leaq (%r10,%r9), %r11
movq %r11, -0x20(%rsp,%r8,8)
movzbl 0x2(%r10,%r9), %r10d
imull %r10d, %r10d
addl %r10d, %ecx
incq %r8
jmp 0x67449
cmpl %edx, %ecx
jge 0x674f4
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
incq %rax
jmp 0x67436
popq %rbx
retq