// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x7fffffff, 0x34(%rax) # imm = 0x7FFFFFFF
movl $0x0, 0x64(%rsp)
cmpl $0x2, 0x64(%rsp)
jge 0xaee60
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x38(%rsp)
cmpl $0x3, 0x38(%rsp)
jge 0xaed5d
movq 0x8(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq 0x38(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x30(%rsp)
movslq 0x38(%rsp), %rcx
movzbl 0x14(%rax,%rcx), %eax
movl %eax, 0x2c(%rsp)
movq 0x30(%rsp), %rcx
movslq 0x2c(%rsp), %rax
imulq $0x6, %rax, %rax
addq %rax, %rcx
movslq 0x64(%rsp), %rax
imulq $0x3, %rax, %rax
addq %rax, %rcx
movslq 0x38(%rsp), %rax
movq %rcx, 0x40(%rsp,%rax,8)
movslq 0x38(%rsp), %rax
movq 0x40(%rsp,%rax,8), %rax
movzbl 0x2(%rax), %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
imull 0x28(%rsp), %eax
addl 0x3c(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0xaecd2
movq 0x8(%rsp), %rcx
movl 0x3c(%rsp), %eax
cmpl 0x34(%rcx), %eax
jge 0xaee4e
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
movzbl (%rcx), %ecx
cvtsi2ss %ecx, %xmm0
movss 0xbcf8(%rip), %xmm3     # 0xbaa80
movss %xmm3, (%rsp)
divss %xmm3, %xmm0
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm1
movss 0x7840(%rip), %xmm2     # 0xb65e0
movss %xmm2, 0x4(%rsp)
divss %xmm2, %xmm1
movq 0x50(%rsp), %rax
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm2
divss %xmm3, %xmm2
leaq 0x1c(%rsp), %rdi
callq 0xabe10
movss (%rsp), %xmm1
movss 0x4(%rsp), %xmm2
movq 0x8(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, 0x20(%rax)
movq 0x1c(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
movzbl 0x1(%rcx), %ecx
cvtsi2ss %ecx, %xmm0
divss %xmm1, %xmm0
movzbl 0x1(%rax), %eax
cvtsi2ss %eax, %xmm1
divss %xmm2, %xmm1
movq 0x50(%rsp), %rax
movzbl 0x1(%rax), %eax
cvtsi2ss %eax, %xmm2
movss 0xbc65(%rip), %xmm3     # 0xbaa80
divss %xmm3, %xmm2
leaq 0x10(%rsp), %rdi
callq 0xabe10
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x24(%rax)
movl 0x18(%rsp), %ecx
movl %ecx, 0x2c(%rax)
movl 0x64(%rsp), %ecx
shll %ecx
movb %cl, 0x30(%rax)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x34(%rax)
jmp 0xaee50
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0xaecb7
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)