// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/libsquish/rangefit.cpp
// Function: squish::RangeFit::Compress3(void*)
void RangeFit::Compress3( void* block )
{
    // cache some values
    int const count = m_colours->GetCount();
    Vec3 const* values = m_colours->GetPoints();

    // create a codebook
    Vec3 codes[3];
    codes[0] = m_start;
    codes[1] = m_end;
    codes[2] = 0.5f*m_start + 0.5f*m_end;

    // match each point to the closest code
    u8 closest[16];
    float error = 0.0f;
    for( int i = 0; i < count; ++i )
    {
        // find the closest code
        float dist = FLT_MAX;
        int idx = 0;
        for( int j = 0; j < 3; ++j )
        {
            float d = LengthSquared( m_metric*( values[i] - codes[j] ) );
            if( d < dist )
            {
                dist = d;
                idx = j;
            }
        }

        // save the index
        closest[i] = ( u8 )idx;

        // accumulate the error
        error += dist;
    }

    // save this scheme if it wins
    if( error < m_besterror )
    {
        // remap the indices
        u8 indices[16];
        m_colours->RemapIndices( closest, indices );

        // save the block
        WriteColourBlock3( m_start, m_end, indices, block );

        // save the error
        m_besterror = error;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movslq (%rdi), %rax
movl 0x28(%rbx), %ecx
movl %ecx, 0x18(%rsp)
movq 0x20(%rbx), %rcx
movq %rcx, 0x10(%rsp)
movq 0x2c(%rbx), %rcx
movq %rcx, 0x1c(%rsp)
movl 0x34(%rbx), %ecx
movl %ecx, 0x24(%rsp)
movss 0x87bc(%rip), %xmm0     # 0x792a8
movss 0x28(%rbx), %xmm1
mulss %xmm0, %xmm1
movsd 0x20(%rbx), %xmm2
movsd 0x2c(%rbx), %xmm3
mulss 0x34(%rbx), %xmm0
addss %xmm1, %xmm0
movaps 0xcd91(%rip), %xmm1     # 0x7d8a0
mulps %xmm1, %xmm2
mulps %xmm1, %xmm3
addps %xmm2, %xmm3
movlps %xmm3, 0x28(%rsp)
movss %xmm0, 0x30(%rsp)
testq %rax, %rax
jle 0x70bf0
leaq 0x4(%rdi), %rcx
movsd 0x14(%rbx), %xmm0
movss 0x1c(%rbx), %xmm1
movaps %xmm0, %xmm2
shufps $0x55, %xmm0, %xmm2     # xmm2 = xmm2[1,1],xmm0[1,1]
xorps %xmm11, %xmm11
leaq 0x18(%rsp), %rdx
xorl %esi, %esi
movss 0xce40(%rip), %xmm3     # 0x7d994
leaq (%rsi,%rsi,2), %r8
movsd (%rcx,%r8,4), %xmm4
movss 0x8(%rcx,%r8,4), %xmm5
movaps %xmm4, %xmm6
shufps $0x55, %xmm4, %xmm6     # xmm6 = xmm6[1,1],xmm4[1,1]
movq %rdx, %r8
xorl %r10d, %r10d
movaps %xmm3, %xmm7
xorl %r9d, %r9d
movaps %xmm7, %xmm8
movaps %xmm4, %xmm9
subss -0x8(%r8), %xmm9
movaps %xmm6, %xmm10
subss -0x4(%r8), %xmm10
movaps %xmm5, %xmm7
subss (%r8), %xmm7
mulss %xmm1, %xmm7
mulss %xmm0, %xmm9
mulss %xmm2, %xmm10
mulss %xmm10, %xmm10
mulss %xmm9, %xmm9
addss %xmm10, %xmm9
mulss %xmm7, %xmm7
addss %xmm9, %xmm7
ucomiss %xmm7, %xmm8
cmoval %r10d, %r9d
minss %xmm8, %xmm7
incq %r10
addq $0xc, %r8
cmpq $0x3, %r10
jne 0x70b78
movb %r9b, 0x40(%rsp,%rsi)
addss %xmm7, %xmm11
incq %rsi
cmpq %rax, %rsi
jne 0x70b54
jmp 0x70bf4
xorps %xmm11, %xmm11
movss 0x38(%rbx), %xmm0
ucomiss %xmm11, %xmm0
jbe 0x70c3c
leaq 0x20(%rbx), %r15
leaq 0x2c(%rbx), %r12
leaq 0x40(%rsp), %rsi
leaq 0x50(%rsp), %r13
movq %r13, %rdx
movss %xmm11, 0xc(%rsp)
callq 0x704a6
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x6ff28
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x38(%rbx)
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq